Solved

Initializing a component in an application.

Posted on 1997-04-06
1
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 63
jboss 7.1 start up error 1 84
passing enum to a method 4 51
DTD and JAVA versions 1 57
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

739 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