• Advertisement
Sign in to follow this  

JAVA Question

This topic is 3321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to do a Trail on the JAVA website: http://java.sun.com/docs/books/tutorial/uiswing/painting/step1.html I have two classes: main, and SwingPaintDemo1. I'm trying to instantiate SwingPaintDemo1 when main is called and have it draw a window to the screen. Nothing appears...
package rpg;

public class main {
    public static void main(String[] args) {
        SwingPaintDemo1 f = new SwingPaintDemo1();
    }
}

package rpg;

import javax.swing.SwingUtilities;
import javax.swing.JFrame;

public class SwingPaintDemo1 {

    public void SwingPaintDemo1() {
                createAndShowGUI();
    }

    private static void createAndShowGUI() {
        JFrame f = new JFrame("Swing Paint Demo");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(500,500);
        f.setVisible(true);
    }
}

Share this post


Link to post
Share on other sites
Advertisement
I tried out your code, and everything worked fine. Perhaps you are not compiling correctly? Maybe you are not launching right. What are you doing to compile and execute the code?

Share this post


Link to post
Share on other sites
Quote:
Original post by Gallivan
I'm trying to do a Trail on the JAVA website:
http://java.sun.com/docs/books/tutorial/uiswing/painting/step1.html

I have two classes: main, and SwingPaintDemo1. I'm trying to instantiate SwingPaintDemo1 when main is called and have it draw a window to the screen. Nothing appears...


Remove the "void" from your class constructor and it should be fine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement