Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class GUI {
- public static void main(String[] args) {
- GUI gui = new GUI();
- }
- private int count = 0;
- public GUI() {
- JFrame frame = new JFrame();
- frame.setSize(200, 100);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setTitle("Test GUI");
- JLabel label = new JLabel("0");
- JButton button = new JButton("Click me");
- button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- count++;
- label.setText(count + "");
- }
- });
- frame.add(label, BorderLayout.CENTER);
- frame.add(button, BorderLayout.SOUTH);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement