• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to GUI's

 
Gnaz Kull
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9452
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gnaz Kull
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9452
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have marked the topic as resolved. We do not delete topics.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic