Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Ready to Program for Java Technology: Unknown source error.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zybero




PostPosted: Thu Dec 20, 2007 9:47 am   Post subject: Ready to Program for Java Technology: Unknown source error.

code:
// The "SummativeU4" class.
import java.applet.*;
import java.awt.*;

public class SummativeU4 extends Applet
{
    final int WIDTH = 250;
    final int HEIGHT = 275;
    Button block = new Button ("Draw Block");
    Button oval = new Button ("Draw Oval");
    Canvas shapeDisplayCanvas = new Canvas ();

    public void init ()
    {
        Button button = new Button ("Draw Block");
        add (button);
        Button button1 = new Button ("Draw Oval");
        add (button1);
        shapeDisplayCanvas.resize (WIDTH, HEIGHT);
    }


    public boolean action (Event e, Object o)
    {
        Graphics drawG;
        drawG = shapeDisplayCanvas.getGraphics ();
        drawG.setColor (Color.black);
        if (e.target == block)
        {
            drawG.setColor (Color.orange);
            drawG.fillRect (5, 5, WIDTH - 40, HEIGHT - 40);
            return true;
        }
        else if (e.target == oval)
        {
            drawG.setColor (Color.orange);
            drawG.fillOval (20, 20, WIDTH - 40, HEIGHT - 40);
            return true;
        }
        return false;
    }



} // SummativeU4 class




The above is what I have done thus far for my unit 4 summative task. I have handed the program in to my Java teacher and we both sat down and looked through it. We couldn't figure out why it's not working.

If anyone here can tell me what's messing up or show me the area that has the error in it that'd be much appreciated.
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Thu Dec 20, 2007 11:05 am   Post subject: Re: Ready to Program for Java Technology: Unknown source error.

It sounds like the filetype (ASCII vs Binary) is the error, which can be fixed by copying and pasting to a new file... however this seems unlikely since most errors by RTP are completly not what they state.

I have compiled in JAVA (NOT RTP) and it compiles (as well as runs) fine.

This may have to do with the compiler that RTP uses or something along the lines of that, I do not have RTP installed ... so maybe someone else can clear this up a bit better.
wtd




PostPosted: Thu Dec 20, 2007 3:21 pm   Post subject: RE:Ready to Program for Java Technology: Unknown source error.

Friends don't let friends use RTP.

Nor Java, for that matter, but hey... one step at a time.
Zybero




PostPosted: Thu Dec 20, 2007 6:47 pm   Post subject: Re: Ready to Program for Java Technology: Unknown source error.

Posted Image, might have been reduced in size. Click Image to view fullscreen.

That is what comes up when I try to click either of the buttons I have drawn.

I made a new file, transferred it, nothing.
wtd




PostPosted: Thu Dec 20, 2007 8:04 pm   Post subject: RE:Ready to Program for Java Technology: Unknown source error.

So far as I can tell, line 27 is:

code:
drawG.setColor (Color.black);


Now, if you know what NullPointerException means, you know that it's likely that the following returns null for one reason or another.

code:
shapeDisplayCanvas.getGraphics ();


A note on style. You create variables for your buttons, but then don't use them, except in your event handling. Of course, that means your buttons will not work.

And for fun: the whole thing made palatable for discriminating eyes. Wink

code:
// The "SummativeU4" class.
import java.applet.*;
import java.awt.*;

public class SummativeU4 extends Applet {
    final int WIDTH = 250;
    final int HEIGHT = 275;

    Button block = new Button("Draw Block");
    Button oval = new Button("Draw Oval");
    Canvas shapeDisplayCanvas = new Canvas();

    public void init() {
        Button button = new Button("Draw Block");
        Button button1 = new Button("Draw Oval");

        add(button);
        add(button1);

        shapeDisplayCanvas.resize(WIDTH, HEIGHT);
    }

    public boolean action(Event e, Object o) {
        Graphics drawG = shapeDisplayCanvas.getGraphics();

        drawG.setColor(Color.black);

        if (e.target == block) {
            drawG.setColor(Color.orange);
            drawG.fillRect(5, 5, WIDTH - 40, HEIGHT - 40);
            return true;
        }
        else if (e.target == oval) {
            drawG.setColor(Color.orange);
            drawG.fillOval(20, 20, WIDTH - 40, HEIGHT - 40);
            return true;
        }

        return false;
    }
}
HeavenAgain




PostPosted: Thu Dec 20, 2007 8:16 pm   Post subject: RE:Ready to Program for Java Technology: Unknown source error.

i thought it would be something wrong with Canvas, but then i dont even know what that is Crying or Very sad
is it for applets only? some kind of container?
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: