hello all i have a finished program that i worked on last week and i think is running well but i wanted to know how to convert it to have JTextField where the user inputs a value which must appear in the upper part of the frame. There should be a set of three radio buttons which indicate the input scale of the value to be converted.
i wanted to know how to go about this
this is my code

/*
A basic extension of the java.applet.Applet class
*/

import java.awt.*;
import java.applet.*;

public class ahmadassignment2 extends Applet
{
public void init()
{

setLayout(null);
setSize(325,250);
add(CelsiusField);
CelsiusField.setBounds(12,12,62,35);
Fahrenheit.setText("Fahrenheit");
add(Fahrenheit);
Fahrenheit.setBounds(84,132,66,29);
Status.setEditable(false);
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
add(Status);
Status.setBackground(java.awt.Color.white);
Status.setBounds(10,204,276,36);
FahrenheitKelvin.setLabel("Fahrenheit -> Kelvin");
add(FahrenheitKelvin);
FahrenheitKelvin.setBackground(java.awt.Color.BLUE );
FahrenheitKelvin.setBounds(180,156,132,24);
KelvinCelsius.setLabel("Kelvin -> Celsius");
add(KelvinCelsius);
KelvinCelsius.setBackground(java.awt.Color.BLUE);
KelvinCelsius.setBounds(180,72,132,24);
add(FahrenheitField);
FahrenheitField.setBounds(12,132,62,35);
Kelvin.setText("Kelvin");
add(Kelvin);
Kelvin.setBounds(84,72,66,29);
FahrenheitCelsius.setLabel("Fahrenheit -> Celsius");
add(FahrenheitCelsius);
FahrenheitCelsius.setBackground(java.awt.Color.RED );
FahrenheitCelsius.setBounds(180,132,132,24);
CelsiusFahrenheit.setLabel("Celsius -> Fahrenheit");
add(CelsiusFahrenheit);
CelsiusFahrenheit.setBackground(java.awt.Color.RED );
CelsiusFahrenheit.setBounds(180,36,132,24);
add(KelvinField);
KelvinField.setBounds(12,72,62,35);
Celsius.setText("Celsius");
add(Celsius);
Celsius.setBounds(84,12,66,29);
KelvinFahrenheit.setLabel("Kelvin -> Fahrenheit");
add(KelvinFahrenheit);
KelvinFahrenheit.setBackground(java.awt.Color.BLUE );
KelvinFahrenheit.setBounds(180,96,132,24);
CelsiusKelvin.setLabel("Celsius -> Kelvin");
add(CelsiusKelvin);
CelsiusKelvin.setBackground(java.awt.Color.GREEN);
CelsiusKelvin.setBounds(180,12,132,24);



SymAction lSymAction = new SymAction();
CelsiusKelvin.addActionListener(lSymAction);
CelsiusFahrenheit.addActionListener(lSymAction);
KelvinCelsius.addActionListener(lSymAction);
KelvinFahrenheit.addActionListener(lSymAction);
FahrenheitCelsius.addActionListener(lSymAction);
FahrenheitKelvin.addActionListener(lSymAction);

}


java.awt.TextField CelsiusField = new java.awt.TextField();
java.awt.Label Fahrenheit = new java.awt.Label();
java.awt.TextField Status = new java.awt.TextField();
java.awt.Button FahrenheitKelvin = new java.awt.Button();
java.awt.Button KelvinCelsius = new java.awt.Button();
java.awt.TextField FahrenheitField = new java.awt.TextField();
java.awt.Label Kelvin = new java.awt.Label();
java.awt.Button FahrenheitCelsius = new java.awt.Button();
java.awt.Button CelsiusFahrenheit = new java.awt.Button();
java.awt.TextField KelvinField = new java.awt.TextField();
java.awt.Label Celsius = new java.awt.Label();
java.awt.Button KelvinFahrenheit = new java.awt.Button();
java.awt.Button CelsiusKelvin = new java.awt.Button();


class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == CelsiusKelvin)
CelsiusKelvin_ActionPerformed(event);
else if (object == CelsiusFahrenheit)
CelsiusFahrenheit_ActionPerformed(event);
else if (object == KelvinCelsius)
KelvinCelsius_ActionPerformed(event);
else if (object == KelvinFahrenheit)
KelvinFahrenheit_ActionPerformed(event);
else if (object == FahrenheitCelsius)
FahrenheitCelsius_ActionPerformed(event);
else if (object == FahrenheitKelvin)
FahrenheitKelvin_ActionPerformed(event);
}
}

void CelsiusKelvin_ActionPerformed(java.awt.event.Actio nEvent event)
{
double temp = Double.valueOf(CelsiusField.getText()).doubleValue ();
if (temp >= -273)
{
temp+=273;
FahrenheitField.setText("");
KelvinField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
KelvinField.setText("");
FahrenheitField.setText("");
Status.setText("Temperatures below minus 273 degrees Celsius are impossible");
}
}

void CelsiusFahrenheit_ActionPerformed(java.awt.event.A ctionEvent event)
{
double temp = Double.valueOf(CelsiusField.getText()).doubleValue ();
if (temp >= -273)
{
temp = 9 * temp / 5 + 32;
KelvinField.setText("");
FahrenheitField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
KelvinField.setText("");
FahrenheitField.setText("");
Status.setText("Temperatures below minus 273 degrees Celsius are impossible");
}
}

void KelvinCelsius_ActionPerformed(java.awt.event.Actio nEvent event)
{
double temp = Double.valueOf(KelvinField.getText()).doubleValue( );
if (temp >= 0)
{
temp -= 273;
FahrenheitField.setText("");
CelsiusField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
FahrenheitField.setText("");
CelsiusField.setText("");
Status.setText("Temperatures below zero Kelvin are impossible");
}
}

void KelvinFahrenheit_ActionPerformed(java.awt.event.Ac tionEvent event)
{
double temp = Double.valueOf(KelvinField.getText()).doubleValue( );
if (temp >= 0)
{
temp -= 273;
temp = 9 * temp / 5 + 32;
CelsiusField.setText("");
FahrenheitField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
CelsiusField.setText("");
FahrenheitField.setText("");
Status.setText("Temperatures below zero Kelvin are impossible");
}
}

void FahrenheitCelsius_ActionPerformed(java.awt.event.A ctionEvent event)
{
double temp = Double.valueOf(FahrenheitField.getText()).doubleVa lue();
if (temp >= -459.4)
{
temp -= 32;
temp = 5 * temp / 9;
KelvinField.setText("");
CelsiusField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
KelvinField.setText("");
CelsiusField.setText("");
Status.setText("Temperatures below minus 459.4 degrees Fahrenheit are impossible");
}
}

void FahrenheitKelvin_ActionPerformed(java.awt.event.Ac tionEvent event)
{
double temp = Double.valueOf(FahrenheitField.getText()).doubleVa lue();
if (temp >= -459.4)
{
temp -= 32;
temp = 5 * temp / 9;
temp += 273;
CelsiusField.setText("");
KelvinField.setText(String.valueOf(temp));
Status.setText("Enter Temperature Value You Want to Convert Then Choose Type of Conversion");
}
else
{
KelvinField.setText("");
CelsiusField.setText("");
Status.setText("Temperatures below minus 459.4 degrees Fahrenheit are impossible");
}
}
}

Recommended Answers

All 2 Replies

I really do wan't to help you, but I can't. Your code is hard to read.
I would recommend you to indent your code. Then give it a try and see
what happens. Then maybe shorten it as much as possible to show us
what problem you are having.

ok i want to know how to change the output gui to radio buttons and text field instead of buttons

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.