m0_47731808 2021-05-28 16:34 采纳率: 100%
浏览 151
已采纳

Java-GUI界面编译成功但什么都不显示

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.TitledBorder;
import javax.swing.border.Border;

class MyFrame extends JPanel implements ActionListener
{
		JFrame  jfrm= new JFrame();
	 public void actionPerformed(ActionEvent e)
	 {
	 	}

		MyFrame() {
			//Set the panel and choosing area

			JPanel jpan1 = new JPanel();
			jpan1.setBorder(BorderFactory.createTitledBorder("Date of Birth"));

			JPanel jpan2 = new JPanel();
			jpan2.setBorder(BorderFactory.createTitledBorder("Date of Birth"));

			JPanel jpan3 = new JPanel();
			jpan3.setBorder(BorderFactory.createTitledBorder("Programme"));

			JPanel jpan4 = new JPanel();
			jpan4.setBorder(BorderFactory.createTitledBorder("Email"));

			JPanel jpan5 = new JPanel();
			jpan5.setBorder(BorderFactory.createTitledBorder("Phone number"));

			JPanel jpan6 = new JPanel();
			jpan6.setBorder(BorderFactory.createTitledBorder("Booking reference code"));

			JPanel jpan7 = new JPanel();
			JPanel jpan8 = new JPanel();
			JPanel jpanName1 = new JPanel();
			jpanName1.setBorder(BorderFactory.createTitledBorder("First Name"));

			JPanel jpanName2 = new JPanel();
			jpanName2.setBorder(BorderFactory.createTitledBorder("Surname"));

			JPanel jpanMonth = new JPanel();
			jpanMonth.setBorder(BorderFactory.createTitledBorder("Month"));

			JPanel jpanYear = new JPanel();
			jpanYear.setBorder(BorderFactory.createTitledBorder("Year"));

			JButton bt1 = new JButton("Next step");
			JButton bt2 = new JButton("Clear");
			JButton bt3 = new JButton("Exit");
			JTextField JTextFirst = new JTextField();
			JTextField JTextSur = new JTextField();
			JTextField JTextEmail = new JTextField();
			JTextField JTextNumber = new JTextField();
			JTextField JTextCode = new JTextField();
			JCheckBox Box1 = new JCheckBox("I have red and agree to the terms and conditions");
			JCheckBox Box2 = new JCheckBox("I confirm that the information provided is correct");


//Set the Year/Month in JComboBox

			String[] arr1 = new String[8];
			for (int i = 0; i < 8; i++) {
				arr1[i] = String.valueOf(i + 1998);
			}
			String[] arr2 = new String[12];
			for (int i = 0; i < 12; i++) {
				arr2[i] = String.valueOf(i + 1);
			}

			JComboBox Month = new JComboBox(arr2);
			JComboBox BirthYear = new JComboBox(arr1);

//Set the major and year

			String[] arrMajor = new String[2];
			arrMajor[0] = "Telecommunications Engineering with Management";
			arrMajor[1] = "Other Majors";
			String[] arrYear = new String[4];
			for (int i = 0; i < 4; i++) {
			arrYear[i] = String.valueOf(i + 1);
			}
			JComboBox Major = new JComboBox(arrMajor);
			JComboBox stuYear = new JComboBox(arrYear);


			jpan1.add(jpanName1);
			jpan1.add(jpanName2);
			jpanName1.add(JTextFirst);
			jpanName2.add(JTextSur);

			jpan2.add(jpanMonth);
			jpan2.add(jpanYear);
			jpanMonth.add(Month);
			jpanYear.add(BirthYear);

			jpan3.add(Major);
			jpan3.add(stuYear);

			jpan4.add(JTextEmail);

			jpan5.add(JTextNumber);

			jpan6.add(JTextCode);

			jpan7.add(Box1);
			jpan7.add(Box2);

			jpan8.add(bt1);
			jpan8.add(bt2);
			jpan8.add(bt3);
		


		}

}


public class CheckIn extends JFrame{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyFrame jfrm = new MyFrame();
		jfrm.setLayout(new GridLayout(1,9));
		jfrm.setVisible(true);
	}

}
  • 写回答

2条回答 默认 最新

  • 关注

    帮你修改了一下代码,但还有很多问题,可以显示了:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    class MyFrame extends JFrame implements ActionListener {
    
    	public void actionPerformed(ActionEvent e) {
    	}
    
    	public MyFrame() {
    		setLayout(new GridLayout(1, 9));
    		JPanel jpan1 = new JPanel();
    		jpan1.setBorder(BorderFactory.createTitledBorder("Date of Birth"));
    
    		JPanel jpan2 = new JPanel();
    		jpan2.setBorder(BorderFactory.createTitledBorder("Date of Birth"));
    
    		JPanel jpan3 = new JPanel();
    		jpan3.setBorder(BorderFactory.createTitledBorder("Programme"));
    
    		JPanel jpan4 = new JPanel();
    		jpan4.setBorder(BorderFactory.createTitledBorder("Email"));
    
    		JPanel jpan5 = new JPanel();
    		jpan5.setBorder(BorderFactory.createTitledBorder("Phone number"));
    
    		JPanel jpan6 = new JPanel();
    		jpan6.setBorder(BorderFactory.createTitledBorder("Booking reference code"));
    
    		JPanel jpan7 = new JPanel();
    		JPanel jpan8 = new JPanel();
    		JPanel jpanName1 = new JPanel();
    		jpanName1.setBorder(BorderFactory.createTitledBorder("First Name"));
    
    		JPanel jpanName2 = new JPanel();
    		jpanName2.setBorder(BorderFactory.createTitledBorder("Surname"));
    
    		JPanel jpanMonth = new JPanel();
    		jpanMonth.setBorder(BorderFactory.createTitledBorder("Month"));
    
    		JPanel jpanYear = new JPanel();
    		jpanYear.setBorder(BorderFactory.createTitledBorder("Year"));
    
    		JButton bt1 = new JButton("Next step");
    		JButton bt2 = new JButton("Clear");
    		JButton bt3 = new JButton("Exit");
    		JTextField JTextFirst = new JTextField();
    		JTextField JTextSur = new JTextField();
    		JTextField JTextEmail = new JTextField();
    		JTextField JTextNumber = new JTextField();
    		JTextField JTextCode = new JTextField();
    		JCheckBox Box1 = new JCheckBox("I have red and agree to the terms and conditions");
    		JCheckBox Box2 = new JCheckBox("I confirm that the information provided is correct");
    
    //Set the Year/Month in JComboBox
    
    		String[] arr1 = new String[8];
    		for (int i = 0; i < 8; i++) {
    			arr1[i] = String.valueOf(i + 1998);
    		}
    		String[] arr2 = new String[12];
    		for (int i = 0; i < 12; i++) {
    			arr2[i] = String.valueOf(i + 1);
    		}
    
    		JComboBox Month = new JComboBox(arr2);
    		JComboBox BirthYear = new JComboBox(arr1);
    
    
    		String[] arrMajor = new String[2];
    		arrMajor[0] = "Telecommunications Engineering with Management";
    		arrMajor[1] = "Other Majors";
    		String[] arrYear = new String[4];
    		for (int i = 0; i < 4; i++) {
    			arrYear[i] = String.valueOf(i + 1);
    		}
    		JComboBox Major = new JComboBox(arrMajor);
    		JComboBox stuYear = new JComboBox(arrYear);
    
    		jpan1.add(jpanName1);
    		jpan1.add(jpanName2);
    		jpanName1.add(JTextFirst);
    		jpanName2.add(JTextSur);
    
    		jpan2.add(jpanMonth);
    		jpan2.add(jpanYear);
    		jpanMonth.add(Month);
    		jpanYear.add(BirthYear);
    
    		jpan3.add(Major);
    		jpan3.add(stuYear);
    
    		jpan4.add(JTextEmail);
    
    		jpan5.add(JTextNumber);
    
    		jpan6.add(JTextCode);
    
    		jpan7.add(Box1);
    		jpan7.add(Box2);
    
    		jpan8.add(bt1);
    		jpan8.add(bt2);
    		jpan8.add(bt3);
    		add(jpan1);
    		add(jpan2);
    		add(jpan3);
    		add(jpan4);
    		add(jpan5);
    		add(jpan6);
    		add(jpan7);
    		add(jpan8);
    		
    		setSize(500,500);
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setLocationRelativeTo(null);
    
    	}
    
    
    	public static void main(String[] args) {
    		new MyFrame();
    	}
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vscode里面怎么用plaformio强调串口啊
  • ¥20 针对计算后数据做一致性检验可以用Bland Altman法吗
  • ¥15 win32如何自绘编辑框的背景图片(语言-c++|操作系统-windows)
  • ¥15 微信夜间被转走了1w对,当天手机剪切板里就出现了这个乱码,有铁子可以看看是啥吗可以
  • ¥50 跑通github上的代码 深度学习 pytorch
  • ¥50 求写,批处理调用分区助手分区脚本
  • ¥15 求购HI3519AV100开发板
  • ¥15 请问1553 RT怎么测试,没有BC有方法吗
  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?