Commit 9bf6975e by Patryk Czarnik

Rozmowa1

parent efd1faa0
package swing.zdarzenia;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MojListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent evt) {
System.out.println("a kuku");
}
}
package swing.zdarzenia;
import javax.swing.*;
import java.awt.*;
public class Rozmowa1 {
private static final Font FONT = new Font("Arial", Font.BOLD, 32);
private static final Dimension odstep = new Dimension(0, 10);
public static void main(String[] args) {
JFrame okno = new JFrame("Rozmowa");
okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
okno.setContentPane(panel); // panel jest wnętrzem okna
// panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
panel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
LayoutManager layout = new BoxLayout(panel, BoxLayout.Y_AXIS);
panel.setLayout(layout);
JLabel pytanie = new JLabel("Jak masz na imię?");
pytanie.setFont(FONT);
panel.add(pytanie);
panel.add(Box.createRigidArea(odstep));
JTextField pole = new JTextField();
pole.setFont(FONT);
pole.setForeground(Color.RED);
panel.add(pole);
panel.add(Box.createRigidArea(odstep));
JButton guzik = new JButton("OK");
guzik.setFont(FONT);
guzik.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
panel.add(guzik);
panel.add(Box.createRigidArea(odstep));
JLabel powitanie = new JLabel("Witaj");
powitanie.setFont(FONT);
powitanie.setForeground(Color.BLUE);
panel.add(powitanie);
panel.add(Box.createRigidArea(odstep));
// JButton guzik2 = new JButton("Niespodzianka");
// guzik2.setFont(FONT);
// guzik2.setForeground(Color.RED);
// guzik2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
// panel.add(guzik2);
//
// panel.add(Box.createRigidArea(odstep));
okno.pack();
MojListener listener = new MojListener();
guzik.addActionListener(listener);
okno.setVisible(true);
System.out.println("okno wyświetlone, koniec main");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment