java手游 《剑心》_java

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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("转华式(F)");

button2=new Button("转摄氏(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));

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值