Results 1 to 3 of 3
  1. #1
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Beginner GUI - JTextEdit

    Hi All,

    I've just made my first GUI. There are some text fields and a reset button. When the reset is pressed all of the field must go blank.

    There seem to be a few ways to do this, and I'm not too happy with the way I've done it. Basically, I feel like I should be able to do a c.repaint(), where c is my Container, in actionPerformed(), but instead I am looping through each box doing setText("") from inside actionPerformed. Any thoughts about this? In general, where should I be trying to put the bulk of my code?


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Beginner GUI - JTextEdit

    You could create a collection of JTextComponent (which includes JTextFields, JTextAreas, JEditorPane, JTextPane,...), give your gui a public void reset() method, and in this method, loop through the collection clearing each text component.

  3. #3
    Lowest0ne is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: Beginner GUI - JTextEdit

    Thanks Fubarable. If I have you correctly, I should write a function reset() and then call it if the action event equals the reset button? This aught to work :)

    Still a very beginner here, The program has a paint(Graphics g) method, which is apparently called whenever the frame needs to be repainted (resizing for example). But I never explicitly call paint(). My teacher has hinted that there is a similar "update" method being called behind the scenes, and we should use this as well. If a "Play" button is pressed, the program should do things, but at the same time the "Stop" button needs to be available (I guess I assume an infinite loop inside of actionPerformed is a bad idea).

    Edit: And I have been searching for this answer, problem is I hardly know what to search for, basic Java Application "something" I guess.

    "Paint, Repaint, Update", the fact that they exist is all I know from my class notes..

    Edit: Pressing the "play" button disables it, so what I really need is something that will run update (called by repaint I guess), if the play button is disabled.

    Sorry about the edits, but I'm not just waiting for the answer :)

    Final Edit: Looks like I got it, I needed a SwingWorker. Man, teacher is putting us through some ropes
    Last edited by Lowest0ne; 04-09-2012 at 01:49 AM.

Similar Threads

  1. Need Help - Beginner
    By ooooohmaul in forum New To Java
    Replies: 4
    Last Post: 08-08-2010, 05:22 AM
  2. Beginner, need a little help
    By jimmy-lin in forum New To Java
    Replies: 6
    Last Post: 10-10-2009, 02:00 AM
  3. beginner please
    By shroomiin in forum New To Java
    Replies: 6
    Last Post: 09-16-2009, 12:06 AM
  4. Beginner needs help!
    By Polyy in forum New To Java
    Replies: 1
    Last Post: 11-27-2008, 06:12 AM
  5. almost done...beginner needs help plz..
    By shongo in forum New To Java
    Replies: 15
    Last Post: 11-10-2008, 09:14 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