JAVA Question

Started by
4 comments, last by Gallivan 15 years, 4 months ago
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);
    }
}

Advertisement
Java isn't an acronym. Don't use uppercase for it. Does the exact code from the tutorial not work for you?
Yes, the exact code does work for me, but I rarely learn anything by copy-typing.
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?

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

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.

Thanks! I removed void and it works perfectly.

This topic is closed to new replies.

Advertisement