🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #1255

Re: Canvas

#1255
From: Nathan
Date: Thu, 28 Jan 1999 00:00
41 lines
2307 bytes
Marcel Hazrat <marcel.hazrat@cityweb.de> wanted information about Canvas
Objects.

Hi Marcel,
     given what you're going to be doing.. lots of lines and stuff I'm
pretty sure you'll be wanting to know about the Graphics object.(bear with
me)
Canvas objects are Components.
Components are gui components which are added to the "screen" (whatever
form it might be: Panel, Applet Window etc)
Once they have been displayed you can use a Canvas to draw all sorts of
lines, rectangles, polygons, cirlces etc via the use of the Graphics object
associated with that canvas.
To get the Graphics object you need to call canvasName.getGraphics() after
the Canvas has been added . for example in an applet's init() method
	
	Canvas canvas1 = new Canvas();
	this.add(canvas1);

then in some other method or other. perhaps in the paint(Graphics g)
method. If you try before the canvas itselft is visible you will get a null
pointer exception because there is no Graphics object if the thing isn't
visible(not strictly true.. you can have non visible Graphics objects for
double buffering but why complicate things more)

	Graphics gc = canvas1.getGraphics();
	//then to draw a line say
	gc.drawLine(x1,y1,x2,y2);

for a specialised application you should create a subclass of Canvas and
override the paint(Graphics g) method to draw whatever you want to draw.
Note that the Graphics object passed to the paint method of any component
is the Graphics object of that particular component. So to create your
custom look to any particular component just overide the paint method and
put in your own stuff.
Hope that helps a bit.

Nathan
-- 
To reply to me remove the REMOVE1234 from address. :) 
Isn't it sad we have to do this! Fight spam!
Technical Details
Message-ID: <01be4a79$00100260$LocalHost@default>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36ACB450.E797B4A8@cityweb.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,34baf81d6c16ff59
X-Google-Attributes: gid10d6db,public
From: "Nathan" <KinsalisREMOVE1234@hotmail.com>
Subject: Re: Canvas
Date: 1999/01/28
Message-ID: <01be4a79$00100260$LocalHost@default>
X-Deja-AN: 437798171
Cache-Post-Path: mercedes.iniaccess.net.au!unknown@inia-te02.laa.com.au
References: <36ACB450.E797B4A8@cityweb.de>
X-Trace: 28 Jan 1999 13:10:32 -0800, mailer01.iniaccess.net.au
Organization: Desiin Pty Ltd T/A INIAccess
Newsgroups: aus.computers.java