import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UsingButtons extends JApplet implements ActionListener { private JLabel label; private JButton button1; private JButton button2; public void init() { label = new JLabel("label"); button1 = new JButton("button1"); button2 = new JButton("button2"); Container container = getContentPane(); container.setLayout(new FlowLayout()); container.add(label); container.add(button1); container.add(button2); button1.addActionListener(this); button2.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { label.setText("Winner"); } else if (e.getSource() == button2) { label.setText("Loser"); } } }