| | |
Help with GUI
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 0
Hi everybody, I'm new to GUI and was wondering if someone could help me with my fraction calculator if they input text in the fields or if they leave something blank. I'm not quite sure how to do that. Here's my code, and if someone could guide me to how to do it, I'd be very thankful.
fractionNumeratorOne = (int)(Integer.parseInt(firstNumerator.getText()));
fractionDenominatorOne = (int)(Integer.parseInt(firstDenominator.getText()));
fractionNumeratorTwo = (int)(Integer.parseInt(secondNumerator.getText()));
fractionDenominatorTwo = (int)(Integer.parseInt(secondDenominator.getText()));
if (fractionDenominatorOne==0 || fractionDenominatorTwo==0)
{
JOptionPane.showMessageDialog(null, "Zero isn't the right number, it will equal a positive infinity","Error", JOptionPane.ERROR_MESSAGE);
}
if(fractionNumeratorOne==) {
JOptionPane.showMessageDialog(null, "Zero isn't the right number, it will equal a positive infinity","Error", JOptionPane.ERROR_MESSAGE);
} basically you need to check if they have a value. if the enter nothing then the string will be null or "". If you try to set a integer equal to null, you will get an exception, so you need to check the value of the fraction inputs before you turn them into integers.
do so this simly use an if statement
hope that helps
do so this simly use an if statement
java Syntax (Toggle Plain Text)
if(firstDenominator.getText().equals(""){ //handle null value }
this.love(*);
&hea/rts;
&hea/rts;
hmm,
There is no clean way i can think of, but you can do
There is no clean way i can think of, but you can do
java Syntax (Toggle Plain Text)
try{ int num=Integer.parseInt(firstDenominator.getText()); //if it gets to here its valid }catch(NumberFormatException e){ //invalid number }
Last edited by nschessnerd; Oct 23rd, 2007 at 12:53 am.
this.love(*);
&hea/rts;
&hea/rts;
![]() |
Similar Threads
- How do I make a GUI in C++ (C++)
- GUI development in LINUX (Window and Desktop Managers)
- Project on offer - GUI for ATi Drivers (Software Development Job Offers)
- GUI Library help (C++)
- Help with gui loop. (C)
Other Threads in the Java Forum
- Previous Thread: Array in Dice Program
- Next Thread: any one have idia about this.
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows





