Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Error in Lectures notes(please help)

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Error in Lectures notes(please help)

    Hi this is the code i downloaded off my lectures example folder im getting an error that says "Exception in thread "main" java.lang.NoSuchMethodError: main" but there is no main class can anyone help


    import javax.swing.*;
     
    import java.awt.Dimension;
    import java.awt.BorderLayout;
     
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
     
    public class WindowEventDemo extends JApplet implements WindowListener,ActionListener
    {
        JTextArea display;
        JFrame window;
        JButton b1, b2;
        static final String SHOW = "show";
        static final String CLEAR = "clear";
        final static String newline = "\n";
     
     
        public void init() {
            b1 = new JButton("Click to bring up a window.");
            b1.setActionCommand(SHOW);
            b1.addActionListener(this);
     
            b2 = new JButton("Click to clear the display.");
            b2.setActionCommand(CLEAR);
            b2.addActionListener(this);
     
            display = new JTextArea();
            display.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(display);
            scrollPane.setPreferredSize(new Dimension(200, 75));
     
            JPanel contentPane = new JPanel();
            contentPane.setLayout(new BorderLayout());
            contentPane.add(b1, BorderLayout.NORTH);
            contentPane.add(scrollPane, BorderLayout.CENTER);
            contentPane.add(b2, BorderLayout.SOUTH);
            setContentPane(contentPane);
     
            //Create but don't show window.
            window = new JFrame("Window Event Window");
            window.addWindowListener(this);
            JLabel l = new JLabel("The applet listens to this window"
                                + " for window events.");
            window.getContentPane().add(l, BorderLayout.CENTER);
            window.pack();
        }
     
        public void stop() {
            window.setVisible(false);
        }
     
        public void windowClosing(WindowEvent e) {
            window.setVisible(false);
            displayMessage("Window closing", e);
        }
     
        public void windowClosed(WindowEvent e) {
            displayMessage("Window closed", e);
        }
     
        public void windowOpened(WindowEvent e) {
            displayMessage("Window opened", e);
        }
     
        public void windowIconified(WindowEvent e) {
            displayMessage("Window iconified", e);
        }
     
        public void windowDeiconified(WindowEvent e) {
            displayMessage("Window deiconified", e);
        }
     
        public void windowActivated(WindowEvent e) {
            displayMessage("Window activated", e);
        }
     
        public void windowDeactivated(WindowEvent e) {
            displayMessage("Window deactivated", e);
        }
     
        public void displayMessage(String prefix, WindowEvent e) {
            display.append(prefix
                           + ": "
                           + e.getWindow()
                           + newline);
        }
     
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand() == SHOW) {
                window.pack();
                window.setVisible(true);
            } else {
                display.setText("");
            }
        }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Error in Lectures notes(please help)

    "Exception in thread "main" java.lang.NoSuchMethodError: main" but there is no main class can anyone help
    The jvm cannot find the main method, not a main class. However, given this class extends a JApplet, it should be run as an applet not an application eg you are better off trying to run it through Appletviewer or some alternative to view applets

  3. The Following User Says Thank You to copeg For This Useful Post:

    Pulse_Irl (October 12th, 2010)