Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Bunch of <JFrame> and <JPanel> Questions

Reply
Thread Tools

Bunch of <JFrame> and <JPanel> Questions

 
 
KevinSimonson
Guest
Posts: n/a
 
      09-22-2009
I haven't done anything with Swing for a while, and decided I wanted
to brush up my skills, so I thought I'd write a Java program that drew
lines on a <JPanel> on a <JFrame>. Does anybody know how to get ac-
cess to a <JPanel> on a <JFrame>? What the steps are to draw the
lines that show up in the <JPanel> on the <JFrame>?

I think that I want to modify one of the <paint()> or
<paintComponent()> methods of the <JPanel>, and do <drawLine()> calls
with its <Graphics> object. Does anybody know what the difference is
between modifying <paint()> and <paintComponent()> so I can know which
I want to use?

I'd also like to have some code that changes the lines that are drawn
depending on where the user clicks the mouse. If I remember right I
need to make my <JPanel> object implement an interface in order for
that to happen, and the interface will include some methods that get
called when the user clicks the mouse. And is there another interface
that defines the methods that get called when the user _resizes_ the
<JFrame>, so that I can have my application draw the <JPanel> with the
new size? And when the user _moves_ the <JFrame>, so that I can have
my application redraw the <JPanel> in its new location?

Any pointers anybody can give me on this would be greatly appreciated.

Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      09-22-2009
In article
<a3b93942-5710-4717-bb36->,
KevinSimonson <> wrote:

> I haven't done anything with Swing for a while, and decided I wanted
> to brush up my skills, so I thought I'd write a Java program that
> drew lines on a <JPanel> on a <JFrame>. Does anybody know how to get
> ac- cess to a <JPanel> on a <JFrame>? What the steps are to draw the
> lines that show up in the <JPanel> on the <JFrame>?


Definitely start with the tutorial:

<http://java.sun.com/docs/books/tutorial/uiswing/>

> I think that I want to modify one of the <paint()> or
> <paintComponent()> methods of the <JPanel>, and do <drawLine()> calls
> with its <Graphics> object. Does anybody know what the difference is
> between modifying <paint()> and <paintComponent()> so I can know
> which I want to use?


<http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html>
<http://java.sun.com/products/jfc/tsc/articles/painting/>

> I'd also like to have some code that changes the lines that are drawn
> depending on where the user clicks the mouse. If I remember right I
> need to make my <JPanel> object implement an interface in order for
> that to happen, and the interface will include some methods that get
> called when the user clicks the mouse.


Here's a simple object drawing example:

<http://sites.google.com/site/drjohnbmatthews/graphpanel>

> And is there another interface that defines the methods that get
> called when the user _resizes_ the <JFrame>, so that I can have my
> application draw the <JPanel> with the new size? And when the user
> _moves_ the <JFrame>, so that I can have my application redraw the
> <JPanel> in its new location?


Look at using a layout manager and component listener:

<http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html>
<http://java.sun.com/docs/books/tutor...ponentlistener
..html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help! I erased a bunch of stuff and now I have no sound mixer76er Computer Support 4 03-04-2008 05:53 PM
Bunch of questions following David Thielen ASP .Net Security 2 06-02-2006 12:18 PM
F-Secure and a bunch of crap John Vogel Computer Security 4 07-22-2004 03:47 PM
Versioning, GAC, ASP.NET and a BUNCH of sites - Please Help! Nayt Grochowski ASP .Net 2 12-03-2003 12:03 AM
A bunch of RMI questions Sony Antony Java 5 07-02-2003 01:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57