?? j02323.java
字號:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
class ButtonFrame extends Button //定義按扭子類
{
ButtonFrame(String s)
{
super(s);//調用父類的默認函數
setSize(100,400);//想改變按扭大小結果沒成功
}
}
public class J02323 extends Applet implements ActionListener
{
Label prompt1,prompt2;
TextField input1,input2;
double double1,double2;
ButtonFrame bun1,bun2,bun3,bun4;
Font fnt= new Font("serief",Font.BOLD,12); //定義字體類型和大小
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT,0,10));//設置空件排列方式即從左到右從上到下和它們的水平和垂直距離
prompt1=new Label("攝氏溫度:");
prompt2= new Label("華氏溫度:");
input1= new TextField(10);
input2=new TextField(10);
bun1=new ButtonFrame(" 轉華氏 ");
bun2=new ButtonFrame(" 轉攝氏 ");
bun3=new ButtonFrame(" 退 出 ");
bun4=new ButtonFrame(" 清 除 ");
bun1.setFont(fnt);
bun2.setFont(fnt);
bun3.setFont(fnt);
bun4.setFont(fnt);
add(prompt1);
add(input1);
add(prompt2);
add(input2);
add(bun1,BorderLayout.WEST); //設置按扭邊界布局
add(bun2,BorderLayout.EAST);
add(bun3,BorderLayout.CENTER);
add(bun4);
input1.addActionListener(this); //給按扭和文本框加事件監聽器
input2.addActionListener(this);
bun1.addActionListener(this);
bun2.addActionListener(this);
bun3.addActionListener(this);
bun4.addActionListener(this);
}
public void paint(Graphics g)
{
setSize(200,300);
setBackground(Color.green);
setLocation(10,10);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bun1||(e.getSource()==input1)) //響應鼠標和鍵盤兩種操作
{
double1=Double.valueOf(input1.getText()).doubleValue(); //提取輸入內容轉化為double型
double2=(double1*9)/5+32; // 根據公式轉換
//input1.setText("");
input2.setText(Double.toString(double2));
}
else
if(e.getSource()==bun2||(e.getSource()==input2))//響應鼠標和鍵盤兩種操作
{
double2=Double.valueOf(input2.getText()).doubleValue();//提取輸入內容轉化為double型
double1=Math.round(5*(double2-32)/9); // 根據公式轉換
input1.setText(Double.toString(double1));
//input2.setText( "");
}
else
{
if(e.getSource()==bun3)
System.exit(0);
else
{
input1.setText("");
input2.setText("");
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -