Bunch of <JFrame> and <JPanel> Questions

Discussion in 'Java' started by KevinSimonson, Sep 22, 2009.

  1. 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_
    KevinSimonson, Sep 22, 2009
    #1
    1. Advertising

  2. In article
    <>,
    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/tutorial/uiswing/events/componentlistener
    ..html>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, Sep 22, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green
    Replies:
    0
    Views:
    3,034
    Roedy Green
    Jul 30, 2003
  2. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    26,956
  3. jakester
    Replies:
    3
    Views:
    1,795
    jakester
    Apr 3, 2007
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,505
    John B. Matthews
    Jul 18, 2008
  5. t1m1976
    Replies:
    1
    Views:
    2,387
    t1m1976
    Nov 7, 2010
Loading...

Share This Page