A java applet that converts Fahrenheit temperatures to Celsius temperatures



Yüklə 38 Kb.
tarix07.11.2018
ölçüsü38 Kb.
#78524

// A Java applet that converts Fahrenheit temperatures to Celsius temperatures.
import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

import appletIO.AppletIO;


public class TempConversion extends Applet

{

private Button Calculate;



private Label lblFahrenheit, lblCelsius;

private TextField txtFahrenheit, txtCelsius;

private Panel p;

public void init ()

{

setBackground (Color.cyan);



p = new Panel ();

p.setLayout (new GridLayout (5, 1, 12, 12));

txtFahrenheit = setField (p, txtFahrenheit, lblFahrenheit, "Fahrenheit");

txtCelsius = setField (p, txtCelsius, lblCelsius, "Celsius");

Calculate = new Button ("Calculate");

Calculate.addActionListener (new CalculateListener ());

p.add (Calculate);

add (p);


} // method init

// Method to create a TextField and a Label and add them to the Panel.

private TextField setField (Panel p, TextField txt, Label lbl, String label)

{

txt = new TextField (10);



lbl = new Label (label);

p.add (lbl);

p.add (txt);

return txt;

} // method setField

// Inner class to listen for the Calculate button.

class CalculateListener implements ActionListener

{

public void actionPerformed (ActionEvent event)



{

double fahrenheit, celsius;

fahrenheit = AppletIO.getDouble (txtFahrenheit);

celsius = (fahrenheit - 32) * 5 / 9;

txtCelsius.setText ("" + AppletIO.decimals (celsius));

} // method actionPerformed



} // class CalculateListener

} // class TempConversion
Yüklə 38 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə