All pastes #33077 Raw Edit

Dr4g

public java v1 · immutable
#33077 ·published 2005-12-09 09:03 UTC
rendered paste body
import java.awt.*;import javax.swing.*;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JComponent;import java.awt.Toolkit;import java.awt.BorderLayout;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class HelloWorld extends JPanel implements ActionListener{        int numClicks = 0;    public HelloWorld() {        JButton button = new JButton("Click Me");        button.setPreferredSize(new Dimension(200, 80));        String lblPrefix = "Number of Clicks: ";        JLabel label = new JLabel(lblPrefix + numClicks);        add(button, BorderLayout.CENTER);        add(label, BorderLayout.CENTER);        button.addActionListener(this);    }       public void actionPerformed(ActionEvent e) {        numClicks++;   }    public static void createAndShowGUI() {        //Make sure we have nice window decorations.        JFrame.setDefaultLookAndFeelDecorated(true);        //Create and set up the window.        JFrame frame = new JFrame("Hello World");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                //Create and set up the content pane.        JComponent newContentPane = new HelloWorld();        newContentPane.setOpaque(true); //content panes must be opaque        frame.setContentPane(newContentPane);        //Display the window.        frame.pack();        frame.setVisible(true);    }        public static void main(String[] args) {        javax.swing.SwingUtilities.invokeLater(new Runnable() {            public void run() {                createAndShowGUI();            }        });    }}