Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.GridBagLayout;
  2. import javax.swing.JPanel;
  3. import javax.swing.JButton;
  4. import java.awt.GridBagConstraints;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class HelloPanel extends JPanel {
  9.  
  10.     private static final long serialVersionUID = 1L;
  11.     private JButton HelloButton = null;
  12.  
  13.     /**
  14.      * This is the default constructor
  15.      */
  16.     public HelloPanel() {
  17.         super();
  18.         initialize();
  19.     }
  20.  
  21.     /**
  22.      * This method initializes this
  23.      *
  24.      * @return void
  25.      */
  26.     private void initialize() {
  27.         GridBagConstraints gridBagConstraints = new GridBagConstraints();
  28.         gridBagConstraints.gridx = 0;
  29.         gridBagConstraints.gridheight = 2;
  30.         gridBagConstraints.gridy = 0;
  31.         this.setSize(300, 200);
  32.         this.setLayout(new GridBagLayout());
  33.         this.add(getHelloButton(), gridBagConstraints);
  34.     }
  35.  
  36.     /**
  37.      * This method initializes HelloButton 
  38.      *  
  39.      * @return javax.swing.JButton 
  40.      */
  41.     private JButton getHelloButton() {
  42.         if (HelloButton == null) {
  43.             HelloButton = new JButton("Hello");
  44.             HelloAction ha =new HelloAction();
  45.             HelloButton.addActionListener(ha);
  46.         }
  47.         return HelloButton;
  48.     }
  49.    
  50.     class HelloAction implements ActionListener{
  51.         @Override
  52.         public void actionPerformed(ActionEvent e) {
  53.             System.out.println("hello");           
  54.         }
  55.        
  56.     }
  57.    
  58. }