0

So I'm trying to put a GLabel on the canvas, but the problem is it won't show up. I've been watching the Programming Methodology courses from Stanford and there they extend the acm packages, which I'm extending as well. My code looks exactly like what the lecturer is using, but my GLabel isn't working. Here's my code:

import acm.program.*;
import acm.graphics.*;

public class prog extends GraphicsProgram{
    public void main () {
        GLabel label = new GLabel ("Hello, world", 200, 200); 
        add (label)
    }
}

Additional info : I'm using a text editor called TextWrangler on Mac OS X and compiling using the bash shell on a command line called Terminal.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0

This code doesn't go in the main method. With acm, you put the following in your main.

new prog.start(args);

Then you define a new method called run.

public void run() {
GLabel label = new GLabel("Hello World", 200, 200);
add(label);
}

So your finished product looks like so:

import acm.program.*;
import acm.graphics.*;

public class prog extends GraphicsProgram {
    public void main() {
        new prog.start(args);
}
    public void run() {
        GLabel label = new GLabel("Hello, world", 200, 200); 
        add (label);
    }
}
Sam
  • 54
  • 1
  • 7