Solved

Initializing a component in an application.

Posted on 1997-04-06
1
187 Views
Last Modified: 2010-04-16
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?
0
Comment
Question by:FRAYSER
1 Comment
 
LVL 2

Accepted Solution

by:
majkl earned 50 total points
ID: 1219450
Well. The bast way to do graphics is to extend Canvas component :
class MyCanvas extends Canvas
{
//put code for drawing in here
 
}
declare there methods to draw .....
draw in function paint(Graphics g) or update

 public void update (Graphics g)
     {
        paint (g);
     }

to avoid flickering.

Put canvas in frame like this
MyCanvas canvas = new Mycanvas();
canvas.resize(x,y); //x,y wanted size
canvas.move(xx,yy); xx,yy wanted position
//call draw methods
canvas.draw_shape();


0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question