add component to existing GUI
hi,
I have created simple GUI with one panel containing button and textfield(I used GUI designer of idea):
public class GUIClass{
private JTextField textField1;
private JButton button1;
private JPanel mainPanel;
private final JFrame frame;
public GUIClass() {
frame = new JFrame("hello");
button1.addActionListener(new pushbutton());
}
public static void main(String[] args){
GUIClass GU = new GUIClass();
GU.frame.setContentPane(GU.mainPanel);
GU.frame.pack();
GU.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
GU.frame.setSize(400,400);
GU.frame.setVisible(true);
}
class pushbutton implements ActionListener {
public void actionPerformed(ActionEvent ae){
textField1.setText(textField1.getText()+"hello");
}
}
}
my question is, if I want to add a new button (or any other simple component) after pressing button1, what should I do?
thanks
Koby
Please sign in to leave a comment.