LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   code from java book not working (http://www.linuxquestions.org/questions/programming-9/code-from-java-book-not-working-932928/)

Andy Alkaline 03-05-2012 11:02 PM

code from java book not working
 
I got the book for my nephew, "Programming Video Games for the Evil Genius by Ian Cinnamon" Noticed typos in the first several programs. I'm not familiar with java, but have some experience with C.

Anyway, my 10 yr old nephew spent three hours typing this program, but we only get the title bar when it runs. After compiling successfully on Windows, tried on my Debian Linux box with openjdk, then switched to sun. Each time got the same result (the title bar, "Super Racing."), and this was in the terminal window.

Quote:

andy@debian:~$ java RP1
Mar 5, 2012 9:51:39 PM com.sun.corba.se.impl.ior.IORImpl getProfile
WARNING: "IOP00511201: (INV_OBJREF) IOR must have at least one IIOP profile"
org.omg.CORBA.INV_OBJREF: vmcid: SUN minor code: 1201 completed: No
at com.sun.corba.se.impl.logging.IORSystemException.iorMustHaveIiopProfile(IORSystemException.java:473)
at com.sun.corba.se.impl.logging.IORSystemException.iorMustHaveIiopProfile(IORSystemException.java:495)
at com.sun.corba.se.impl.ior.IORImpl.getProfile(IORImpl.java:334)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_Object(CDRInputStream_1_0.java:787)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_Object(CDRInputStream_1_0.java:761)
at com.sun.corba.se.impl.encoding.CDRInputStream.read_Object(CDRInputStream.java:231)
at com.sun.corba.se.impl.resolver.INSURLOperationImpl.getIORFromString(INSURLOperationImpl.java:120)
at com.sun.corba.se.impl.resolver.INSURLOperationImpl.operate(INSURLOperationImpl.java:130)
at com.sun.corba.se.impl.orb.ORBImpl.string_to_object(ORBImpl.java:836)
at org.GNOME.Accessibility.AccessUtil.getRegistryObject(AccessUtil.java:143)
at org.GNOME.Accessibility.JavaBridge.registerApplication(JavaBridge.java:1154)
at org.GNOME.Accessibility.JavaBridge.<init>(JavaBridge.java:405)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at java.awt.Toolkit.loadAssistiveTechnologies(Toolkit.java:786)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:875)
at java.awt.Window.getToolkit(Window.java:1170)
at java.awt.Window.init(Window.java:400)
at java.awt.Window.<init>(Window.java:438)
at java.awt.Frame.<init>(Frame.java:419)
at javax.swing.JFrame.<init>(JFrame.java:218)
at RP1.<init>(RP1.java:58)
at RP1.main(RP1.java:91)
Here's the actual code. Right now when it compiles, there are no error or warnings being issued.
Code:

/*
 * RP1.java */

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class RP1 extends JFrame
{       
        final int WIDTH = 900, Height = 650;
   
    Rectangle left = new Rectangle(0,0,WIDTH/9, HEIGHT);
    Rectangle right = new Rectangle((WIDTH/9)*9,0,WIDTH/9,HEIGHT);     
    Rectangle top = new Rectangle(0,0,WIDTH, HEIGHT/9);
    Rectangle bottom = new Rectangle(0, (HEIGHT/9)*9,WIDTH,HEIGHT/9);
    Rectangle center = new
        Rectangle((int)((WIDTH/9)*2.5),(int)
              ((HEIGHT/9)*2.5), (int) ((WIDTH/9)*5),(HEIGHT/9)*4);
              Rectangle obstacle = new
                Rectangle(WIDTH/2,(int)((HEIGHT/9)*7),WIDTH/10,HEIGHT/9);
              Rectangle obstacle2 = new
                Rectangle(WIDTH/3,(int)((HEIGHT/9)*5),WIDTH/10,HEIGHT/4);           
              Rectangle obstacle3 = new
                Rectangle(2*(WIDTH/3),(int)((HEIGHT/9)*5),WIDTH/10,HEIGHT/4);
              Rectangle obstacle4 = new Rectangle(WIDTH/3,HEIGHT/9,WIDTH/30,HEIGHT/9);
              Rectangle obstacle5 = new Rectangle (WIDTH/2,(int)((HEIGHT/9)*1.5),WIDTH/30,HEIGHT/4);
              Rectangle finish = new Rectangle(WIDTH/9,(HEIGHT/2)-HEIGHT/9, (int)((WIDTH/9)*1.5),HEIGHT/70);
             
              Rectangle lineO = new
                  Rectangle(WIDTH/9,HEIGHT/2,(int)((WIDTH/9)*1.5)/2,HEIGHT/140);
              Rectangle lineI = new Rectangle(((WIDTH/9)+((int)((WIDTH/9)*1.5)/2)),
                        (HEIGHT/2)+(HEIGHT/10),
                        (int)((WIDTH/9)*1.5)/2,HEIGHT/140);
                       
              public RP1()
              {
                                  super("Super Racing!");
                                  setSize(WIDTH,HEIGHT);
                                  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                  setVisible(true);
                          }
                          public void paint(Graphics g)
                          {
                                  super.paint(g);
                                 
                                  g.setColor(Color.DARK_GRAY);
                                  g.fillRect(0,0,WIDTH,HEIGHT);
                                 
                                  g.setColor(Color.GREEN);
                                 
                                  g.fillRect(left.x,left.y,left.width,left.height);
                                  g.fillRect(right.x,right.y,left.width,left.height);
                  g.fillRect(top.x,top.y,top.width,top.height);
                  g.fillRect(bottom.x,bottom.y,bottom.width,bottom.height);
                  g.fillRect(center.x,center.y,center.width,bottom.height);
                  g.fillRect(obstacle.x,obstacle.y,obstacle.width,obstacle.height);
                  g.fillRect(obstacle2.x,obstacle2.y,obstacle2.width,obstacle2.height);
                  g.fillRect(obstacle3.x,obstacle3.y,obstacle3.width,obstacle3.height);
                  g.fillRect(obstacle4.x,obstacle4.y,obstacle4.width,obstacle4.height);
                  g.fillRect(obstacle5.x,obstacle5.y,obstacle5.width,obstacle5.height);
                  g.setColor(Color.WHITE);
                  g.fillRect(lineO.x,lineO.y,lineO.width,lineO.height);
                  g.fillRect(lineI.x,lineI.y,lineI.width,lineI.height);
                  g.setColor(Color.YELLOW);
                  g.fillRect(finish.x,finish.y,finish.width,finish.height);
                          }
                         
                          public static void main (String[] args)
                          {
                                  new RP1();
                          }
                        }


Andy Alkaline 03-05-2012 11:23 PM

Quote:

final int WIDTH = 900, Height = 650;
I saw "Height" was not all uppercase. Fixed, and the race track now displays.

BTW, the Height was a typo by my nephew, not from the book. :)


All times are GMT -5. The time now is 03:49 AM.