FRAYSER
asked on
Initializing a component in an application.
I am trying to draw graphics in a frame. I tried using:
Component drawInto = new Canvas();
Graphics g = drawInto.getGraphics();
g.drawline(X1,Y1,X2,Y2);
There is more code obviously, but since this is an application and not an applet, I don't know how to initialize the component. The frame comes up, but I don't get a Canvas or a line. If I try paint(Graphics g), the program compiles correctly, but I get a nullpointer error when I try to execute the program. Any answers?
Component drawInto = new Canvas();
Graphics g = drawInto.getGraphics();
g.drawline(X1,Y1,X2,Y2);
There is more code obviously, but since this is an application and not an applet, I don't know how to initialize the component. The frame comes up, but I don't get a Canvas or a line. If I try paint(Graphics g), the program compiles correctly, but I get a nullpointer error when I try to execute the program. Any answers?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.