aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes New to GUI's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "New to GUI Watch "New to GUI New topic
Author

New to GUI's

Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
Hi all. im both new to GUI's and new to this forum so i apologize if i mess up along the lines somewhere.
My goal with this GUI is to save what i enter into a text field to a txt document. that is working for me and its not over writing the older text. So happy days. I got that far. But now im having problems with a few things and hopefully someone can help me get to where i want to be. So heres what im trying to fix.

1. Exit button only works when the text fields are filled in.
2. Save button only works when the Age, Height and Weight text fields are filled in. I want to be able to save maybe one field and ignore any left blank. Or fill in unknown if it is left blank.
3. Add a clear button to clear text fields. Adding the button wouldnt be hard. But I have no idea how to make it do what i want.
4. Have only 2 text fields / combo boxes per line. in other words im looking for something like the <br> tag in html

heres my code so far




im going to add a pic of the GUI and error code i get when i click the exit button when the text fields are clear


Sorry the page is a bit streched with the code. I cant see how to make the code box any smaller :/

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Gnaz Kull wrote:Sorry the page is a bit streched with the code. I cant see how to make the code box any smaller :/

Break up long lines. I've done it for you, for example, on line 9 of your 2nd snippet. You can also save space by not using tabs for indenting.

But thanks for reading the UseCodeTags page properly. You'd be surprised how many don't.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
oh right cool. thanks man. i thought there might be a way to add it all into its own little scroll box or something. cool. i know for the next time.
i'm not completely new to forums tho. so i know a little when it comes to tags
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Gnaz Kull wrote:My goal with this GUI is to save what i enter into a text field to a txt document. that is working for me and its not over writing the older text. ... So heres what im trying to fix..

This seems like a job for the GUI experts (of which I'm not a club member), so I'm going to move this to our Swing forum.

Winston
Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
ok thanks man.

Update: i have the clear button kind of woring. but again it will not work unless every text field has been used. code i used was this

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2316
    
  49
1. Exit button only works when the text fields are filled in.

This is a symptom of have a single listener to handle more than one button's event. Each button should have it's own ActionListener which does only what that button requires to be done. For simple cases like yours you can use anonymous inner classes.

2. Save button only works when the Age, Height and Weight text fields are filled in. I want to be able to save maybe one field and ignore any left blank. Or fill in unknown if it is left blank.

I guess that's because you are trying to convert some of the missing input to doubles and it is throwing an exception. Check there is some input before doing the conversion to a double. You may also want to look at catching the exception to handle the case where someone enters something like "AB" instead of "21".

3. Add a clear button to clear text fields. Adding the button wouldnt be hard. But I have no idea how to make it do what i want.

Add the button and add an ActionListener that sets each of the input fields to "";

4. Have only 2 text fields / combo boxes per line. in other words im looking for something like the
tag in html

Try a different layout manager ie GridLayout.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Have only 2 text fields / combo boxes per line.


Read up on Layout Managers. Keep the tutorial handy, it will answer most of your Swing questions.
Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
ok ive googled it and tried a few things but im still having trouble with the buttons. i dont know how to add multiple actionlisteners without causing more errors.
the results from my search came up with this code a few times


but im just clueless on how to implement it into my code.

so forgetting problem no. 3 as i have the button and its working but again its only if the textfields are used. im guessing this problem is being cause by not having its own actionlistener.
and i will leave problem 4 to one side for the moment as its only cosmetic. functionality is more important
Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
To any admin or mod. its ok to close or delete this thread.

update on my problems. Ive ditched my old code and started from scratch. and i have it all working fine now. Thanks for your help guys
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

I have marked the topic as resolved. We do not delete topics.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to GUI's