Results 1 to 3 of 3
Thread: Beginner GUI - JTextEdit
- 04-08-2012, 02:40 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
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?
Thanks
-
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.
- 04-08-2012, 08:06 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
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 ropesLast edited by Lowest0ne; 04-09-2012 at 12:49 AM.
Similar Threads
-
Need Help - Beginner
By ooooohmaul in forum New To JavaReplies: 4Last Post: 08-08-2010, 04:22 AM -
Beginner, need a little help
By jimmy-lin in forum New To JavaReplies: 6Last Post: 10-10-2009, 01:00 AM -
beginner here...help please
By shroomiin in forum New To JavaReplies: 6Last Post: 09-15-2009, 11:06 PM -
Beginner needs help!
By Polyy in forum New To JavaReplies: 1Last Post: 11-27-2008, 05:12 AM -
almost done...beginner needs help plz..
By shongo in forum New To JavaReplies: 15Last Post: 11-10-2008, 08:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks