I tried to convert this GUI to a JApplet but then I get the error message.

> D:\JAVA\PROGRAMS\whiteboard\whiteBoardapplet.java:9: error: whiteBoardapplet is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
> public class whiteBoardapplet extends JApplet implements ActionListener
>        ^
> 1 error
> 
> Tool completed with exit code 1











    import javax.swing.*;
            import java.awt.*;
            import java.awt.Container;
            import java.awt.event.*;
            import java.util.*;
            import java.io.IOException;
            import java.io.*;

            public class whiteBoardapplet extends JApplet implements ActionListener
            {

                    private JLabel headingLabel , writeHereLabel;
                    private JTextField writeHereText;
                    private JTextArea outputText;
                    private final static String newline = "\n";
                    private JButton buttonAppend,buttonExit;
                    private ABHandler aHandler;
                    private EBHandler eHandler;

                public void init()
                {

                    headingLabel = new JLabel("MY SIMPLE WHITEBOARD",SwingConstants.CENTER);

                    writeHereLabel = new JLabel("Write here: ",SwingConstants.LEFT);



                    writeHereText = new JTextField(10);
                    writeHereText.setEditable(true);



                    outputText = new JTextArea(100, 100);
                    outputText.setEditable(false);
                    JScrollPane scrollPane = new JScrollPane(outputText);



                     //APPEND BUTTON
                    buttonAppend = new JButton("APPEND");
                    aHandler = new ABHandler();
                    buttonAppend.addActionListener(aHandler);

                    //EXIT BUTTON
                    buttonExit = new JButton("EXIT");
                    eHandler = new EBHandler();
                    buttonExit.addActionListener(eHandler);


                    //PANE ADD
                    Container pane = getContentPane();
                    pane.setLayout(null);


                    headingLabel.setLocation(300,1);
                    writeHereLabel.setLocation(82,30);
                    writeHereText.setLocation(50, 200);
                    outputText.setLocation(200,400);
                    buttonAppend.setLocation (200,300);
                    buttonExit.setLocation(200,500);

                    headingLabel.setSize(200,200);
                    writeHereLabel.setSize(200,200);
                    writeHereText.setSize(500,100);
                    outputText.setSize(500,100);
                    buttonAppend.setSize(82,30);
                    buttonExit.setSize(82,30);


                    pane.add(headingLabel);
                    pane.add(writeHereLabel);
                    pane.add(writeHereText);
                    pane.add(buttonAppend);
                    pane.add(outputText);
                    pane.add(buttonExit);



                }


            private class ABHandler implements ActionListener
                 {
                    public void actionPerformed(ActionEvent e)
                        {
                                 String text = writeHereText.getText();
                                 outputText.append(text + newline);
                                 writeHereText.selectAll();
                                 outputText.setCaretPosition(outputText.getDocument().getLength());
                        }
                 }

                private class EBHandler implements ActionListener
                {   public void actionPerformed(ActionEvent e)
                    {
                        System.exit(0);
                    }
                }




                /*public void ActionPerformed (ActionEvent e)
                {
                    if (e.getActionCommand().equals("Append"))
                        outputText.append(writeHereText.getText());
                    else if (e.getActionCommand().equals("Exit"))

                    System.exit(0);

                }*/



            }

That's because whiteBoardapplet doesnt implement it. It's ABHandler that implements it.

OH!! THANKS!! The Exit doesn't work though...
is it impossible to
System.exit(0);
an applet?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.