📄 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("请输入你的数据:");
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);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -