java手游 《剑心》_java
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
package txt2;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class MyPanel extends Frame implements ActionListener{
TextField tf1;
TextField tf2;
Button button1;
Button button2;
Label lb1;
Label lb2;
public MyPanel(){
GridLayout gl1=new GridLayout(3, 2);
this.setLayout(gl1);
lb1=new Label("攝氏溫度(C)");
lb2=new Label("華氏溫度(F)");
button1=new Button("轉(zhuǎn)華式(F)");
button2=new Button("轉(zhuǎn)攝氏(C)");
tf1=new TextField(10);
tf2=new TextField(10);
this.add(lb1);
this.add(tf1);
this.add(lb2);
this.add(tf2);
this.add(button1);
this.add(button2);
this.setSize(250, 150);
this.setVisible(true);
button1.addActionListener(this);
button2.addActionListener(this);
tf1.setBounds(10, 30, 100, 25);
tf2.setBounds(130,30, 100, 25);
lb1.setBounds(10, 58, 100, 25);
lb2.setBounds(130, 58, 100, 25);
button1.setBounds(10, 88, 100, 25);
button2.setBounds(130, 88, 100, 25);
}
public static void main(String[] args) {
MyPanel mp=new MyPanel();
mp.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==button2){
double sum=Double.parseDouble(tf2.getText());
double answer=(sum-32)*5/9;
tf1.setText(Double.toString(answer));
}
if(e.getSource()==button1){
double sum=Double.parseDouble(tf1.getText());
double answer=sum*9/5+32;
tf2.setText(Double.toString(answer));
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java手游 《剑心》_java的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AOP底层原理与注解配置详解
- 下一篇: Golang——切片使用大全(创建、初始