Code:
import javax.swing.*;
import java.awt.event.*;
public class Test
{
public static void main(String[] args)
{
final JFrame frame = new JFrame("Test");
final JPanel panel = new JPanel();
JButton button = new JButton("Test button");
panel.add(button);
frame.add(panel);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
panel.add(new JButton("Test button"));
}
});
frame.setSize(300,200);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.event.*;
public class Test
{
public static void main(String[] args)
{
final JFrame frame = new JFrame("Test");
final JPanel panel = new JPanel();
JButton button = new JButton("Test button");
panel.add(button);
frame.add(panel);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
panel.add(new JButton("Test button"));
}
});
frame.setSize(300,200);
frame.setVisible(true);
}
}
Interesuje me na koji način unutar actionPerformed metode narediti frame-u ili panel-u da se ponovo iscrtaju kako bi se pojavili novi dugmići? I ne samo u ovom konkretnom slučaju već i inače, koja metoda se koristi kad je potrebno ponovo iscrtati komponente unutar kontejnera nakon dodavanja ili mijenjanja komponenata?!