📄 cicle.java
字号:
//import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Cicle extends JFrame implements ActionListener{
JLabel j1,j2,j3,j4;
TextField t,t1,t2,t3;
JButton jb1,jb2;
final double PI=3.14;
public Cicle()
{
super("用于圆柱面积和体积的计算");
Container c1 = getContentPane();
c1.setLayout(null);
j1=new JLabel("请输入半径:");
j2=new JLabel("请输入高:");
j3=new JLabel("面积为:");
j4=new JLabel("体积为:");
t=new TextField();
t1=new TextField();
t2=new TextField();
t3=new TextField();
jb1=new JButton("确定");
jb2=new JButton("取消");
j1.setBounds(3,50,130,25);
t.setBounds(80,50,130,25);
j2.setBounds(240,50,130,25);
t1.setBounds(300,50,130,25);
j3.setBounds(3,100,130,25);
t2.setBounds(80,100,130,25);
j4.setBounds(240,100,130,25);
t3.setBounds(300,100,130,25);
jb1.setBounds(150,150,90,40);
jb2.setBounds(250,150,90,40);
jb1.setBackground(Color.red);
jb2.setBackground(Color.green);
c1.setBackground(Color.yellow);
c1.add(t);
c1.add(t1);
c1.add(t2);
c1.add(t3);
c1.add(j1);
c1.add(j2);
c1.add(j3);
c1.add(j4);
c1.add(jb1);
c1.add(jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
setBounds(300, 200, 450, 300);
//setSize(600,600);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
try
{
if(e.getSource()==jb1)
{
int r = Integer.parseInt(t.getText());
int h=Integer.parseInt(t1.getText());
t2.setText(""+2*PI*r*(r+h));
t3.setText((PI*r*r*h)+"");
}
else
{
t.setText("");
t1.setText("");
t2.setText("");
t3.setText("");
}
}
catch(Exception e1)
{
System.out.println("你输入的数据类型不对");
}
}
/*
public void show()
{
double s,t;
s=2*PI*r*(r+h);
t=PI*r*r*h;
System.out.println("你输入的半径和高为:"+r+","+h);
System.out.println("面积为:"+s);
System.out.println("体积为:"+t);
}
public void setR(double rb)
{
r=rb;
}
public void setH(double hb)
{
h=hb;
}*/
public static void main(String[] args)
{
/*try
{
double rs,rh;
BufferedReader bin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入半径和高:");
rs=Double.parseDouble(bin.readLine());
c.setR(rs);
rh=Double.parseDouble(bin.readLine());
c.setH(rh);
c.show();
}
catch(IOException e)
{
System.out.println("你输入的数据有误!");
}
*/
new Cicle();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -