Sign in to follow this  
Gallivan

JAVA Question

Recommended Posts

Gallivan    158
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
Glass_Knife    8636
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
linkki    133
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this