// import javax.swing.*; import java.awt.event.*; import java.awt.*; public class StringApplet extends JApplet implements ActionListener { private JTextField numbertext = new JTextField(5); private JTextField texttext = new JTextField(10); private JButton fillButton = new JButton("Fyll på"); private JTextArea svarstext = new JTextArea(8, 20); public void actionPerformed(ActionEvent event) { String numberstring = numbertext.getText(); String textstring = texttext.getText(); if (textstring.equals("")) { svarstext.append("ERROR"); } else { try { double n = Integer.parseInt(numberstring); for (int i = 0; i < n; ++i) svarstext.append(textstring); } catch (NumberFormatException exc) { svarstext.append("ERROR"); } } } // actionPerformed public void init() { fillButton.addActionListener(this); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(numbertext); cp.add(texttext); cp.add(fillButton); cp.add(svarstext); } public static void main(String[] args) { StringApplet applet = new StringApplet(); JFrame frame = new JFrame("StringApplet"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(applet); frame.setSize(250, 150); applet.init(); applet.start(); frame.setVisible(true); } } // class StringApplet