Alternative Nation
Go Back   Alternative Nation

Notices

View Single Post
Old 8th April 2008, 9:40pm   #1
Sazzarella
moot moot
 
Sazzarella's Avatar
 
Join Date: Apr 2006
Location: Edinburgh
Posts: 2,916
Sazzarella = 2nd BestSazzarella = 2nd BestSazzarella = 2nd Best
Send a message via MSN to Sazzarella
Java, text box functions

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);
            }
        });
    }
}
__________________

See I'm no king I wear no crown, But desperate times seem over now, But still I weaken somehow It tears me apart.
Sazzarella is offline   Reply With Quote
 







Powered by vBadvanced CMPS v3.0.0


All times are GMT +0. The time now is 3:20am.

Forums Directory
Copyright 2000-2008, Alternative Nation
Page generated in 0.20341 seconds with 11 queries