Solved

Initializing a component in an application.

Posted on 1997-04-06
1
191 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

622 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