aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes gui problems 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 » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "gui problems" Watch "gui problems" New topic
Author

gui problems

James Du
Ranch Hand

Joined: Mar 23, 2001
Posts: 186
I have 2 problems
1) I want to replace the default icon with mines for the application, how to achieve that and do you guys think there's a need to do so?
2) I want to create my JTextField component which only accept key 0-9, all other keys can not even be entered in the Field, is there any solution to do that? how do you address the problem of interpreting the user input for the the seat number?
your input is highly appreciated
James
Mike Piotrowski
Ranch Hand

Joined: Apr 24, 2002
Posts: 82
James,
1) I want to replace the default icon with mines for the application, how to achieve that and do you guys think there's a need to do so?

Not sure how to do that off hand, but I do not believe that will get you any extra points.
2) I want to create my JTextField component which only accept key 0-9, all other keys can not even be entered in the Field, is there any solution to do that? how do you address the problem of interpreting the user input for the the seat number?

I just checked to make sure that the number of seats entered was a positive number and not any other character, if it wasn't I notified the user to enter a valid number. Best thing to do is keep things simple. You don't seem to get any extra points for neat little features.
Mike
Alex Gregory
Ranch Hand

Joined: Jun 15, 2002
Posts: 46
you could catch a NumberFormatException to detect whether a number was entered.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

There is a PlainDocument class that handles this and is very easy to implement. You extend the JTextfield. Just create one new Constructor, call the setDocument() method, passing a new instance of the PlainDocument class. You will actually extend the PlainDocument to create say a NumericDocument class, that checks that it !Character.isDigit.
Or you could just use the Character.isDigit, and that it is positive in your code, if you are ok to allow Alpha letters in the JTextField.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Originally posted by Alex Gregory:
you could catch a NumberFormatException to detect whether a number was entered.

This is just my two cents, but I would avoid using catching an exception for normal, expected things such as input validation. Exception handling is expensive from a processing perspective and should be reserved for exceptional situations.
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
How about avoiding editing altogether by using a combo box to select the number of seats? That's what Travelocity and Expedia do.
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Great idea Robin; I'm going to change my GUI to use that.
Richard Mok
Greenhorn

Joined: Jun 19, 2002
Posts: 8
Hello,
I created a class called TextFilter which extends PlainDocument to allow numeric value only for the quanity textfield. However, how can I avoid a blank textfield to be submitted?
By the way, I would like to take this chance to thank you all you guys who are so resourceful to answer the questions. Although this is my first post in javaranch, I already learned a lot and cleared much of the confusion for my assignment.
Keep on the good job.
Thanks,
Richard
cindy sung
Ranch Hand

Joined: Jul 02, 2002
Posts: 34
Hi,
Can I ask another GUI question?
If I use JComboBox to store the codes of origin airport, destination airport and carrier, how to get the information? Do you just hardcoded it in the GUI? Do we need to make it be able to change dynamicly while the database is updated in future?
Thanks.
cindy


SCJP2; SCJD2;
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117

This is your design decision. There's a tradeoff of having up-to-date info from the database versus a long startup time if there's alot of records in the database.
Mike Piotrowski
Ranch Hand

Joined: Apr 24, 2002
Posts: 82
Cindy,
I hardcoded them into the GUI, but did mention in my design choices that obtaining them dynamically from the database could be a future enhancement. Only lost one point on my gui, so that could be where I lost it.
Mike
Eduard Jodas
Ranch Hand

Joined: May 14, 2002
Posts: 80

Richard Mok:
I created a class called TextFilter which extends PlainDocument to allow numeric value only for the quanity textfield. However, how can I avoid a blank textfield to be submitted?

Disable the book button if the textfield is blank. You can get notified of text changes adding a DocumentListener to your Document
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Cindy, you can create methods that get the data from the Data class. That's what I did, and it wasn't too hard to implement. These methods are actually in my Facade class, so if you don't have a Facade you will have to put it into your DataAccess classes that implement your Data interface.
Mark
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

1) I want to replace the default icon with mines for the application, how to achieve that and do you guys think there's a need to do so?

Try this:

This is actually more than you need to do. The code above can actually retreive the icon from a JAR.
Eugene.
bogdan
Greenhorn

Joined: Jul 08, 2002
Posts: 3
About having a JTextField that only accpets 1-9...
Every JTextField has a method
protected void processKeyEvent () { .. }
Now in order to have a text field that only accepts 0 through 9 you NEED to subclass JTextField in the following manner:
class CustomJTextField extends JTextField {
public void processKeyEvent (KeyEvent e) {
if (Character.isDigit(e.getKeyChar()))
super.processKeyEvent(e);
}
}
when you create a CustomJTextField and add it to a container, it only alows 0 though 9 or whatever you wish... You can change the condition...
I hope this answers one of the questions
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

"bogdan"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
cindy sung
Ranch Hand

Joined: Jul 02, 2002
Posts: 34
Hi, Mark:
Thanks for your advice. That's what my origianl design is. And now I've implemented it.
Just another confirmation:
At the client side, I have used both mediator pattern and facade patten, and I use the mediator class to call methods from the facade class, which is in charge of communicating the the DataAccess. And the mediator is mainly used to control the gui components. Is my design correct?
And what should I put into the 'Help' menu?
Thanks.
cindy
 
Consider Paul's rocket mass heater.
 
subject: gui problems