Results 1 to 8 of 8
  1. #1
    Aga^^ is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default Use of Start button's action

    hi guys i'm a newbie in java and i have a question.

    i have 3 class but i used threads in 2 of them.In one class i used run function and in the another one's main used start function.I also used paint and paintComponent function in the class which i used start function. ( i have a user interface in this class )

    in paint function i draw a few rectangles and paintCompenent function i added a few rectangles.

    what i want is when i clicked the start button : run,start and paintCompenent functions start.

    i am waiting your answers, thanks...

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Creating a GUI with JFC/Swing
    and more specifically
    Writing Event Listeners

    Also, why are you using a Thread if all you call run() instead of start()? Why are you using both paint() and paintComponent()? You should only use paintComponent(). You also shouldn't add any Components in paintComponent().
    Last edited by OrangeDog; 04-18-2009 at 08:23 PM.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Aga^^ is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default

    i learned that when i call start(), run() works.

    i used both paint() and paintComponent() because, first i drew somethings and program do a few changes so i used paintComponent() to show the changes.

    please give me your ideas

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Yes, you implement the run() method, but you should never call it. Similarly, you should override the paintComponent() method in order to draw on the component, but you should never call it. Call repaint() instead when things need updating.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    Aga^^ is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default

    ok i got the run() part. But in paintComponent() part, i draw new rectangles in the form how can i implement this?

  6. #6
    Aga^^ is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default

    ok i got the run() part. But in paintComponent() part, i draw new rectangles in the form how can i implement this?

    i wanted to do somethings like, i wrote a paintComponent() there i drew 2 new rectangles and wanted to show them in the form.

    at the end when i clicked the start button i want ( if it can ) paintComponent() func runs. ( or you can say me another idea )

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    in paintComponent() use the drawing methods on the Graphics object as described in the tutorials linked above. If you want to change what is displayed, you will need additional flags that determine what you draw in paintComponent().
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #8
    Aga^^ is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 03-20-2009, 10:04 PM
  2. action class
    By jayagowri in forum Web Frameworks
    Replies: 1
    Last Post: 05-07-2008, 03:23 PM
  3. jsp:forward action
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 10:04 AM
  4. jsp:param action
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 10:03 AM
  5. Few action in one Jbutton
    By kubiasty in forum New To Java
    Replies: 0
    Last Post: 07-25-2007, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •