



Program finds the minimum of 3 numbers
Post your code here.






More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS
Void (Default)
Life
Earth
Wind
Water
Fire
Lightweight
10:42 pm - April 5th, 2009
14 Mar 09 3:15 PM MST
Hello, one again, I went with the GUI version:
Here’s the heart of the code that does it all:
public void Calculation(){
float number1, number2, number3;
number1 = Float.parseFloat(jTextField1.getText());
number2 = Float.parseFloat(jTextField2.getText());
number3 = Float.parseFloat(jTextField3.getText());
float answer = Math.min( number1, Math.min(number2, number3));
jTextField4.setText(String.valueOf(answer));
}
public void Clear(){
//clears all text boxes
jTextField1.setText(”");
jTextField2.setText(”");
jTextField3.setText(”");
jTextField4.setText(”");
}
and the buttons that calls these methods.
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Clear();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Calculation();
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
Calculation();
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
Clear();
}
I made the two methods, and within the calculate and clear buttons/menu items (under my options pane), I called these methods. I decided to do this because it makes no sense to write the code multiple times in each button. I wrote the code once and called it four times.
here’s my screen shot:
10:45 pm - April 5th, 2009
14 Mar 09 3:19 PM MST
OK, the following 3 text files contain the codes for you to look at:
ryanmin0f3numbersaboutbox.txt
ryanmin0f3numbersapp.txt
ryanmin0f3numbersview.txt
10:46 pm - April 5th, 2009
14 Mar 09 3:26 PM MST
The following zip file is the complete package, download, unzip and tweak how ever you want it!
it’s simple, create gui application.
add 2 buttons,
4 textboxes,
within the program code make the method:
public void Calculation(){
float number1, number2, number3;
number1 = Float.parseFloat(jTextField1.getText());
number2 = Float.parseFloat(jTextField2.getText());
number3 = Float.parseFloat(jTextField3.getText());
float answer = Math.min( number1, Math.min(number2, number3));
jTextField4.setText(String.valueOf(answer));
}
——–+++++and ++++——
public void Clear(){
//clears all text boxes
jTextField1.setText(”");
jTextField2.setText(”");
jTextField3.setText(”");
jTextField4.setText(”");
}
Here’s calculate button code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Calculation();
}
and here’s the clear button code:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Clear();
}
You’re done, you have a running application, you should add labels to explain what does what though.

10:47 pm - April 5th, 2009
Brooke Estabrook-Fishinghawk 15 Mar 09 6:43 AM MST
Response to Ryan
You will be our go to GUI guy.