// This code example is created for educational purpose // by Thorsten Thormaehlen (contact: www.thormae.de). // It is distributed without any warranty. import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; class MyGui extends JFrame implements ActionListener{ private int counter = 0; JLabel label = new JLabel("Hello World"); public void createGUI() { setTitle("HelloGUI"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(320, 240); setLayout(null); label.setBounds(120, 0, 150, 30); getContentPane().add(label); JButton button = new JButton("Increment"); button.addActionListener(this); button.setBounds(120, 30, 150, 30); getContentPane().add(button); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem item = new JMenuItem("Open"); menu.add(item); setJMenuBar(menuBar); setVisible(true); } public void actionPerformed(ActionEvent event) { counter++; label.setText("Click #" + Integer.toString(counter)); } } public class ActionButton { public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { MyGui myGUI = new MyGui(); myGUI.createGUI(); } }); } }