2个回答
展开全部
public class Sum {
public static void main(String[] str) {
final JFrame frame = new JFrame();
frame.setSize(400, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
JPanel panel = new JPanel();
JPanel panel1=new JPanel();
final JTextField input1 = new JTextField(10);
final JTextField input2 = new JTextField(10);
final JTextField input3 = new JTextField(10);
final JTextField input4 = new JTextField(10);
final JTextArea jtx=new JTextArea(300,400);
jtx.setVisible(true);
JLabel label = new JLabel("姓名");
JLabel label1 = new JLabel("性别");
JLabel label2 = new JLabel("年龄");
JLabel label3 = new JLabel("学号");
JButton button = new JButton("显示");
BorderLayout layout=new BorderLayout(5,5);
GridLayout gl=new GridLayout(5,2,5,5);
panel.setLayout(gl);
panel1.setLayout(layout);
panel.add(label);
panel.add(input1);
panel.add(label1);
panel.add(input2);
panel.add(label2);
panel.add(input3);
panel.add(label3);
panel.add(input4);
panel.add(button);
panel1.add(panel,"North");
panel1.add(jtx,"Center");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String str1 = input1.getText().trim();
String str2 = input2.getText().trim();
String str3 = input3.getText().trim();
String str4 = input4.getText().trim();
jtx.setText("姓名"+str1+"\n"+"性别"+str2+"\n"+"年龄"+str3+"\n"+"学号"+str4);
}
});
frame.add(panel1, BorderLayout.NORTH);
frame.setVisible(true);
}
}
public static void main(String[] str) {
final JFrame frame = new JFrame();
frame.setSize(400, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
JPanel panel = new JPanel();
JPanel panel1=new JPanel();
final JTextField input1 = new JTextField(10);
final JTextField input2 = new JTextField(10);
final JTextField input3 = new JTextField(10);
final JTextField input4 = new JTextField(10);
final JTextArea jtx=new JTextArea(300,400);
jtx.setVisible(true);
JLabel label = new JLabel("姓名");
JLabel label1 = new JLabel("性别");
JLabel label2 = new JLabel("年龄");
JLabel label3 = new JLabel("学号");
JButton button = new JButton("显示");
BorderLayout layout=new BorderLayout(5,5);
GridLayout gl=new GridLayout(5,2,5,5);
panel.setLayout(gl);
panel1.setLayout(layout);
panel.add(label);
panel.add(input1);
panel.add(label1);
panel.add(input2);
panel.add(label2);
panel.add(input3);
panel.add(label3);
panel.add(input4);
panel.add(button);
panel1.add(panel,"North");
panel1.add(jtx,"Center");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String str1 = input1.getText().trim();
String str2 = input2.getText().trim();
String str3 = input3.getText().trim();
String str4 = input4.getText().trim();
jtx.setText("姓名"+str1+"\n"+"性别"+str2+"\n"+"年龄"+str3+"\n"+"学号"+str4);
}
});
frame.add(panel1, BorderLayout.NORTH);
frame.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询