Hi, there, very new to Java. I'm looking to get a number from a text box, then use the number in a calculation, and then put the answer into another text box.
JButton convertButton = new JButton ("Convert to Fahrenheit");
final JTextField celsiusText = new JTextField ("Enter temperature in Celsius to convert");
final JTextField fahrenheitText = new JTextField (" ");
JPanel buttons = new JPanel();
buttons.setLayo ut (new FlowLayout());
buttons.add (convertButton) ;
setTitle("Doubl er Frame");
setLayout(new BorderLayout()) ;
add(fahrenheitT ext, BorderLayout.SO UTH);
add(buttons, BorderLayout.CE NTER);
add(celsiusText , BorderLayout.NO RTH);
convertButton.a ddActionListene r (new ActionListener( )
{
public void actionPerformed ( ActionEvent e)
{
fahrenheit = (9/5)* + 33.8;
fahrenheitText. setText(Tempera ture in Fahrenheit: " + fahrenheit);
}
});
This is the main part of the code, I'm very confused and can't figure out whats wrong.
Hope you guys can spot my mistake.
I get an answer of 33.8, no matter what I enter in the first text box.
Would much appreciate help. Thanks!
JButton convertButton = new JButton ("Convert to Fahrenheit");
final JTextField celsiusText = new JTextField ("Enter temperature in Celsius to convert");
final JTextField fahrenheitText = new JTextField (" ");
JPanel buttons = new JPanel();
buttons.setLayo ut (new FlowLayout());
buttons.add (convertButton) ;
setTitle("Doubl er Frame");
setLayout(new BorderLayout()) ;
add(fahrenheitT ext, BorderLayout.SO UTH);
add(buttons, BorderLayout.CE NTER);
add(celsiusText , BorderLayout.NO RTH);
convertButton.a ddActionListene r (new ActionListener( )
{
public void actionPerformed ( ActionEvent e)
{
fahrenheit = (9/5)* + 33.8;
fahrenheitText. setText(Tempera ture in Fahrenheit: " + fahrenheit);
}
});
This is the main part of the code, I'm very confused and can't figure out whats wrong.
Hope you guys can spot my mistake.
I get an answer of 33.8, no matter what I enter in the first text box.
Would much appreciate help. Thanks!
Comment