JFrame application HELP Needed ! ! ! (STILL NEED HELP)
Douglas Braxton
Ranch Hand
Joined: Jan 28, 2004
Posts: 36
posted
0
Ranch Hands: There is a lot of code here. Do not let it throw you. Most of it is here to avoid having to repost it if someone has a question The problem lies within the statement followed by this comment (I think) // # # # PROBLEM # # # in class MYFrame. All code compiles clean. OBJECT: Illustrate inheritance exercise which will have 15 random shapes drawn on a JFrame. PROBLEM: When I execute the Driver the JFrame is BLANK. If you drag the frame the program executes as expected but it produces the following list of runtime errors: java.lang.NullPointerException at MyFrame.paint(MyFrame.java:55) at sun.awt.RepaintArea.paint(RepaintArea.java:177) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260) at java.awt.Component.dispatchEventImpl(Component.java:3699) at java.awt.Container.dispatchEventImpl(Container.java:1623) at java.awt.Window.dispatchEventImpl(Window.java:1590) at java.awt.Component.dispatchEvent(Component.java:3480) at java.awt.EventQueue.dispatchEvent(EventQueue.java:450) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136) at java.awt.EventDispatchThread.run(EventDispatchThread.java:99) Thanks for your expert help. 75gator
[ April 13, 2004: Message edited by: Douglas Braxton ]
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Moving this to the Swing / JFC / AWT forum, where they love to get all messy with this GUI stuff...
Hi Douglas. Just make setVisible(true) the last opeation in MyFrame constructor or remove it from constructor at all and put to the main function like this: public static void main (String[ ] arg) { MyFrame mFrame = new MyFrame(); mFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); mFrame.setVisible(true); //System.exit(0); }// terminate main }// end of MyShapesDriver Like it id now, your program tries to draw shapes before you create them and you're getting the NullPointerException. Good luck. Polina