Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Drawing on panel Object

Thread view: 
lrantisi - 24 Nov 2006 22:39 GMT
I am using the Panel object to represent a drawing area that the user
can use to draw different shapes.
I s there a clear example about how to draw points on the surface on
the Panel object.
Thanks
Wesley Hall - 24 Nov 2006 22:54 GMT
> I am using the Panel object to represent a drawing area that the user
> can use to draw different shapes.
> I s there a clear example about how to draw points on the surface on
> the Panel object.
> Thanks

Firstly, don't use Panel. Panels are designed as containers for other
components, not generic drawing areas. The class you are looking for is
java.awt.Canvas which IS designed as a generic drawing area.

Secondly, what you need to do is overide the paint method of Canvas...
something like this...

public class DrawingCanvas
{

   public void paint(Graphics graphics)
   {
        //manipulate graphics object here
   }

}

The Graphics object contains all the methods you will need to draw onto
the canvas.

Check your API docs under java.awt.Graphics for a list of all the
methods available for your drawing needs.
lrantisi - 24 Nov 2006 23:10 GMT
Thank you for your answer.
But I am originally using an Applet. My Panel was put on the surface of
the Applet.
Now how can I put the Canvas on the Applet instead of the Panel. The
Canvas is not one of the components that can be created by (Darg-Drop).
I am using Exclipse software from IBM. I checked the components window,
there is no canvas to (drag-drop) over the Applet face, as it is the
case with the Panel.
Thanks
.

> > I am using the Panel object to represent a drawing area that the user
> > can use to draw different shapes.
[quoted text clipped - 20 lines]
> Check your API docs under java.awt.Graphics for a list of all the
> methods available for your drawing needs.
Wesley Hall - 24 Nov 2006 23:49 GMT
See below...

>>> I am using the Panel object to represent a drawing area that the user
>>> can use to draw different shapes.
[quoted text clipped - 20 lines]
>> Check your API docs under java.awt.Graphics for a list of all the
>> methods available for your drawing needs.

" Thank you for your answer.
But I am originally using an Applet. My Panel was put on the surface of
the Applet.
Now how can I put the Canvas on the Applet instead of the Panel. The
Canvas is not one of the components that can be created by (Darg-Drop).
I am using Exclipse software from IBM. I checked the components window,
there is no canvas to (drag-drop) over the Applet face, as it is the
case with the Panel.
Thanks "

Please post your replies underneath rather than on top. Posting at the
top is (unsurprisingly) known as 'top-posting' and is frowned upon
because it makes it more difficult to see context as you read from top
to bottom.

Why not add the canvas to your panel? :)

Set your panel's layout manager to 'BorderLayout', and add the canvas
using BorderLayout.CENTER. To do this... first go the constructor of
your panel and make sure the constructor says...

Panel panel = new Panel(new BorderLayout());

...you can probably do this by setting the layout manager using eclipse,
I wouldn't know :)

Now you can create your canvas instance and add it to the panel...

Canvas canvas = new DrawingCanvas();
panel.add(canvas, BorderLayout.CENTER);

...and there you go.

If you are confused on how to do this kind of GUI creation in code
rather than through eclipse, you have just discovered why it is a bad
idea to learn Swing/AWT development with GUI editing tools. With the
kind of code you are writing you will not be able to do everything
through eclipse so it is time to get your hands dirty and learn what is
really going on. You will be a much better developer for it.

I happen to use a GUI editing tool for any Swing GUIs I write (with is
rare nowdays), but because I know I can open the code and do it by hand
if the sh.t hits the fan, for me a GUI editor is a tool rather than a
crutch.

Break away, break free, and rise above all those VB monkeys :oP
kevin.c.ott@gmail.com - 28 Nov 2006 10:49 GMT
There are a number of basic examples of drawing with AWT at
http://exampledepot.com.

You might want to check out this example:

http://www.exampledepot.com/egs/java.awt/BasicDraw.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.