Untitled
unknown
java
a year ago
877 B
6
Indexable
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI implements ActionListener {
JFrame frame = new JFrame();
JPanel buttonPanel = new JPanel();
JButton addButton = new JButton("Add");
int cnt = 1;
public GUI () {
buttonPanel.setBounds(0, 0, 600, 600);
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(addButton);
addButton.addActionListener(this);
frame.add(buttonPanel);
frame.setSize(600, 300);
frame.setLayout(null);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
buttonPanel.add(new JButton("B" + cnt));
cnt++;
frame.setVisible(true);
}
}
Editor is loading...
Leave a Comment