Solved

Initializing a component in an application.

Posted on 1997-04-06
1
182 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now