🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
2 messages
2 total messages Started by Marcel Hazrat Mon, 25 Jan 1999 00:00
Canvas
#1252
Author: Marcel Hazrat
Date: Mon, 25 Jan 1999 00:00
11 lines
836 bytes
Hi everybody,

i�m a german student an we�re jsut learning how to use java.

Now we have to implement a complete LOGO programming language with an
IDE.
The problem is, that we don�t really know, how to use CANVAS-Objekts.

Would be great, if anyone could help!

Marcel, Berlin
Re: Canvas
#1255
Author: 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!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads