PerrySenior
2021-06-28 11:01
采纳率: 85.7%
浏览 19
已采纳

Java为什么显示不出文本框

package exam.pengbozuishuai;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class SystemExam extends JFrame {
	
	JTextField dormitory,number,name,sex,age,clas;
	
	public SystemExam() {
		this.setTitle("宿舍成员管理系统");
		this.setSize(400, 400);
		
		dormitory = new JTextField(6);
		JPanel j1 = new JPanel();
		JLabel j1Labe1 = new JLabel("宿舍号:");
		j1.add(j1Labe1);
		j1.add(dormitory);
		
		
		
		
		number = new JTextField(6);
		JPanel j2 = new JPanel();
		JLabel j1Labe2 = new JLabel("学号:");
		j2.add(j1Labe2);
		j2.add(number);
		
		
		name = new JTextField(6);
		JPanel j3 = new JPanel();
		JLabel j1Labe3 = new JLabel("姓名:");
		j3.add(j1Labe3);
		j3.add(name);
		
		
		sex = new JTextField(6);
		JPanel j4 = new JPanel();
		JLabel j1Labe4 = new JLabel("性别:");
		j4.add(j1Labe4);
		j4.add(sex);
		
		
		age = new JTextField(6);
		JPanel j5 = new JPanel();
		JLabel j1Labe5 = new JLabel("年龄:");
		j5.add(j1Labe5);
		j5.add(age);
		
		
		JLabel j1Labe6 = new JLabel("班级:");
		JPanel j6 = new JPanel();
		clas = new JTextField(6);
		j6.add(j1Labe6);
		j6.add(dormitory);
		
		
		this.setLayout(new GridLayout(8, 1));
		this.add(j1);
		this.add(j2);
		this.add(j3);
		this.add(j4);
		this.add(j5);
		this.add(j6);
		this.setVisible(true);
		
		
	}
	
	
	public static void main(String[] args) {
		new SystemExam();
	}

}

为啥宿舍号后面没有文本框。。。。。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 404警告 2021-06-28 11:10
    已采纳

    已采纳该答案
    评论
    解决 1 无用
    打赏 举报
  • 404警告 2021-06-28 11:09

    你的j6把j1覆盖了:代码如下

    package exam.pengbozuishuai;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class SystemExam extends JFrame {
    	
    	JTextField dormitory,number,name,sex,age,clas;
    	
    	public SystemExam() {
    		this.setTitle("宿舍成员管理系统");
    		this.setSize(400, 400);
    		
    		dormitory = new JTextField(6);
    		JPanel j1 = new JPanel();
    		JLabel j1Labe1 = new JLabel("宿舍号:");
    		j1.add(j1Labe1);
    		j1.add(dormitory);
    		
    		
    		
    		
    		number = new JTextField(6);
    		JPanel j2 = new JPanel();
    		JLabel j1Labe2 = new JLabel("学号:");
    		j2.add(j1Labe2);
    		j2.add(number);
    		
    		
    		name = new JTextField(6);
    		JPanel j3 = new JPanel();
    		JLabel j1Labe3 = new JLabel("姓名:");
    		j3.add(j1Labe3);
    		j3.add(name);
    		
    		
    		sex = new JTextField(6);
    		JPanel j4 = new JPanel();
    		JLabel j1Labe4 = new JLabel("性别:");
    		j4.add(j1Labe4);
    		j4.add(sex);
    		
    		
    		age = new JTextField(6);
    		JPanel j5 = new JPanel();
    		JLabel j1Labe5 = new JLabel("年龄:");
    		j5.add(j1Labe5);
    		j5.add(age);
    		
    		
    		JLabel j1Labe6 = new JLabel("班级:");
    		JPanel j6 = new JPanel();
    		clas = new JTextField(6);
    		j6.add(j1Labe6);
    		j6.add(clas);
    		
    		
    		this.setLayout(new GridLayout(8, 1));
    		this.add(j1);
    		this.add(j2);
    		this.add(j3);
    		this.add(j4);
    		this.add(j5);
    		this.add(j6);
    		this.setVisible(true);
    		
    		
    	}
    	
    	
    	public static void main(String[] args) {
    		new SystemExam();
    	}
    }

    错误点

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题