?? mybox.java
字號:
import java.awt.*;
import java.awt.event.*;
//import javax.swing.JOptionPane;
public class mybox{
static Frame fram=new Frame("this is mybox");
static Button but=new Button("計 算");
static TextField text1 =new TextField();
static TextField text2=new TextField();
static TextField text3=new TextField();
static Button exit=new Button("退 出");
static Button creal=new Button("清 空");
static Label lab4=new Label("");
public static void main(String[] args){
fram.setLayout(null);
fram.setSize(280,280);
fram.setLocation(350,150);
Label lab1=new Label("長:");
Label lab2=new Label("寬:");
Label lab3=new Label("高:");
Label lab=new Label("請輸入你的數(shù)據(jù):");
lab.setBounds(40,40,100,20);
lab1.setBounds(40,70,20,20);
lab2.setBounds(40,100,20,20);
lab3.setBounds(40,130,20,20);
lab4.setBounds(30,220,160,20);
text1.setBounds(90,70,80,20);
text2.setBounds(90,100,80,20);
text3.setBounds(90,130,80,20);
but.setBounds(40,170,40,22);
exit.setBounds(160,170,40,22);
creal.setBounds(100,170,40,22);
fram.add(lab);
fram.add(lab1);
fram.add(lab2);
fram.add(lab3);
fram.add(text1);
fram.add(text2 );
fram.add(text3);
fram.add(but);
fram.add(exit);
fram.add(creal);
fram.add(lab4);
but.addActionListener(new action());
exit.addActionListener(new action());
creal.addActionListener(new action());
fram.setVisible(true);
}
static class action implements ActionListener{
public void actionPerformed(ActionEvent e){
String a,b,c;
int x,y,z,v;
Button click=(Button)e.getSource();
if (click==but)
{a=text1.getText();
b=text2.getText();
c=text3.getText();
// if (a==""||b==""||c=="")
//JOptionPane.showMessageDialog(null,"this is not empty","liang",JOptionPane.QUESTION_MESSAGE);
x=Integer.parseInt(a);
y=Integer.parseInt(b);
z=Integer.parseInt(c);
v=x*y*z;
lab4.setText("該立方體的體積為:"+Integer.toString(v));
}//Integer.toString(v)
else if (click==creal)
{text1.setText("");
text2.setText("");
text3.setText("");
}
else
System.exit(0);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -