Right I am in no way shape or form any good at Java yet and im el stucko and the sun website isnt proveing fruitful
Ive got some crappy wee code, generator to change Fahrenheit to Celcius and atm im using an option pane to get input from the user but I should be using a textbox and getText() but I have no idea how to use it :/ sounds simple but its just no worky worky, if someone can point me in the right direction of where im ment to put it then would be muchos appriciated. HALP
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Temperature {
public static void main(String[] args) {
Temp buttonFrame = new Temp();
buttonFrame.setSize(350,120);
buttonFrame.setLocation(250,100);
buttonFrame.setVisible(true);
}
}
class Temp extends JFrame{
int celsius = 0;
int fahrenheit = 0;
public Temp ()
{
celsius = Integer.parseInt(JOptionPane.showInputDialog(null,"Please enter temperature in Celsius"));
final JTextField convertText = new JTextField ("Celsius: " + celsius);
JButton convertButton = new JButton ("Convert");
JButton quitButton = new JButton("Quit");
JPanel buttons = new JPanel();
buttons.setLayout (new FlowLayout());
buttons.add (convertButton);
buttons.add (quitButton);
setTitle("Temperature Frame");
setLayout(new BorderLayout());
add(buttons, BorderLayout.SOUTH);
add(convertText, BorderLayout.NORTH);
convertButton.addActionListener (new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
fahrenheit=9/5*celsius+32;
convertText.setText("Fahrenheit: " + fahrenheit);
}
});
quitButton.addActionListener (new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
System.exit(1);
}
});
}
}