import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class HelloPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JButton HelloButton = null;
/**
* This is the default constructor
*/
public HelloPanel() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridheight = 2;
gridBagConstraints.gridy = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getHelloButton(), gridBagConstraints);
}
/**
* This method initializes HelloButton
*
* @return javax.swing.JButton
*/
private JButton getHelloButton() {
if (HelloButton == null) {
HelloButton = new JButton("Hello");
HelloAction ha =new HelloAction();
HelloButton.addActionListener(ha);
}
return HelloButton;
}
class HelloAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("hello");
}
}
}