import java.awt.*; import java.awt.event.*; import javax.swing.*; public class HelloWorld extends JApplet implements ActionListener { private JButton button1; private GridBagLayout gl; private GridBagConstraints gc; public void init() { gl = new GridBagLayout(); gc = new GridBagConstraints(); this.setLayout(gl); this.addButton(); } public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { JOptionPane.showMessageDialog(null, "Hello, World"); } } public void addButton() { button1 = new JButton("Click!"); button1.addActionListener(this); gc.gridx = 0; gc.gridy = 0; gc.gridwidth = 0; gc.gridheight = 1; gc.weightx = 1; gc.weighty = 1; gl.setConstraints(button1, gc); this.add(button1); } }