Uznałem, że nie ma sensu tworzyć nowy wątek. Mam problem z kodem który napisałem:
public class Fixus {
public JPanel panel = new JPanel();
public JFrame frame = new JFrame();
public void addComponentToPane() {
}
public class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("udalo sie");
JButton button2 = new JButton("guzik 2");
panel.add(button2);
frame.getContentPane().add(panel);
}
}
public void launchFrame() {
frame.setSize(800, 600);
frame.setTitle("Fixus v. 0.0.1");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public Fixus() {
JButton button = new JButton("guzik 1");
panel.add(button);
frame.getContentPane().add(panel);
button.addActionListener(new ButtonListener());
}
public static void main(String args[]) {
Fixus gui = new Fixus();
gui.launchFrame();
}
}
problem: nie pojawia się button2. Zdarzenie jest obsłużone bo konsola wywala napis, ale guzik się nie pojawia. Co i gdzie źle robię? Właśnie dodawania elementów nie potrafię zrozumieć.