//<html> //<head> //<title>CelsiusToFahrenheit</title> //</html> //<body> //<p align = "center"> //<applet code = AppletControlsDemo.class width =501 height = 100></applet> //</body> //</html> import java.applet.*; import java.awt.*; import java.awt.event.*; public class AppletControlsDemo extends Applet implements ActionListener { Label lblCelsius, lblFahrenheit; TextField txtCelsius, txtFahrenheit; Button btnTransfer; public void init() { lblCelsius = new Label("Celsius"); lblFahrenheit = new Label("Fahrenheit"); txtCelsius = new TextField(20); txtFahrenheit = new TextField(20); btnTransfer = new Button("Celsius to Fahrenheit"); add(lblCelsius); add(txtCelsius); add(lblFahrenheit); add(txtFahrenheit); add(btnTransfer); btnTransfer.addActionListener(this); } public void actionPerformed(ActionEvent ae) { float f = Integer.parseInt(txtCelsius.getText()); f = f*9/5 +32; txtFahrenheit.setText(String.valueOf(f)); } }
第一个有实际意义的applet(AppletControlsDemo.java)
最新推荐文章于 2022-10-07 12:10:26 发布