Hi,
I'm fairly new to Java and I've been having some difficulties with Swing. I'm trying to create a very simple GUI program which should be create a set of buttons but my code doesn't work.
Here's my code;
myPanel = new JPanel();
JButton myButton = new JButton("create buttons");
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int val = Integer.parseInt(textfield.getText());
for(int i = 0; i < val; i++) {
JButton button = new JButton("");
button.setText(String.valueOf(i));
myPanel.add(button);
}
}
});
But nothing happens when I click to "create buttons" button. Can anyone tell me what I'm missing?