import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Applet extends JApplet implements ActionListener { private JTextField indata = new JTextField(10); private JButton plusButton = new JButton("+"); private JTextField resultat = new JTextField(10); private int summa = 0; public void actionPerformed(ActionEvent event) { String s = indata.getText(); try { int n = Integer.parseInt(s); summa = summa + n; resultat.setText(summa + ""); } catch (NumberFormatException exc) { resultat.setText("ERROR"); } } // actionPerformed public void init() { plusButton.addActionListener(this); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(indata); cp.add(plusButton); cp.add(resultat); resultat.setText(summa + ""); } public static void main(String[] args) { Applet applet = new Applet(); JFrame frame = new JFrame("Applet"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(applet); frame.setSize(160, 100); applet.init(); applet.start(); frame.setVisible(true); } } // class Applet