• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

gui problems

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you could catch a NumberFormatException to detect whether a number was entered.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great idea Robin; I'm going to change my GUI to use that.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic