2 回答
TA贡献58条经验 获得超75个赞
import java.awt.*;
import javax.swing.*;
public class FirstSwingApplication extends JFrame
{
private JTextField text1,text2,text3;
private JTextField text_sum;
private JButton btnresult,btnshow;
public
FirstSwingApplication(){
s();
d();
setSize(300,200);
setTitle("first ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
private void s(){
text1=new JTextField(10);
text2=new JTextField(10);
text1=new JTextField(10);
text_sum=new JTextField(10);
String str1 ="操作数1";
String str2 ="运算数";
String str3 ="操作数2";
String str4 ="结果";
btnresult=new JButton("计算");
btnshow=new JButton("清楚");
}
private void d(){
Container a=getContentPane();
setLayout(new GridLayout(4,1));
JPanel pane1=new JPanel();
pane1.add(new Label(str1));
pane1.add(text1);
JPanel pane2=new JPanel();
pane2.add(new Label(str2));
pane2.add(text2);
JPanel pane3=new JPanel();
pane3.add(new Label(str3));
pane3.add(text_sum);
JPanel pane4=new JPanel();
pane4.add(new Label(str4));
pane4.add(btnresult);
JPanel pane5=new JPanel();
pane5.add(btnshow);
a.add(pane1);
a.add(pane2);
a.add(pane3);
a.add(pane4);
a.add(pane5);
}
public static void main(String[] args){
JFrame.setDefaultLookAndFeelDecorated(true);
FirstSwingApplication frame=new FirstSwingApplication();
frame.setVisible(true);
}
}
添加回答
举报