?? e10_3.java
字號:
/**
* @(#)E10_3.java
*
* Sample Applet application
*
* @author
* @version 1.00 06/10/26
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class E10_3 extends Applet implements ActionListener
{
double x,y;
double z;
TextField text1,text2,text3;
Button button1,button2,button3,button4;
public void init()
{
setBackground(Color.yellow);
text1=new TextField(10);
text2=new TextField(10);
text3=new TextField(10);
text3.setEditable(false);
//text3.setBackground(Color.pink);
button1=new Button("加");
button2=new Button("差");
button3=new Button("積");
button4=new Button("除");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
add(new Label("請輸入x的值:"));
add(text1);
add(new Label("請輸入y的值:"));
// button1.setBackground(Color.pink);
// button2.setBackground(Color.cyan);
// button3.setBackground(Color.blue);
// button4.setBackground(Color.yellow);
add(text2);
add(text3);
add(button1);
add(button2);
add(button3);
add(button4);
}
public void actionPerformed(ActionEvent e)
{
try
{
x=Double.parseDouble(text1.getText());
y=Double.parseDouble(text2.getText());
if(e.getSource()==button1)
{
//z=x+y;
text3.setText(x+"+"+y+"="+(x+y));
}
if(e.getSource()==button2)
{
z=x-y;
text3.setText(x+"-"+y+"="+z);
}
if(e.getSource()==button3)
{
z=x*y;
text3.setText(x+"*"+y+"="+z);
}
if(e.getSource()==button4)
{
if(y!=0)
{ z=x/y;
text3.setText(x+"/"+y+"="+z);
}
else text3.setText("除數為0");
}
}
catch(NumberFormatException ee)
{
text3.setText("請輸入數字字符");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -