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

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条)

报告相同问题?

悬赏问题

  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 Mac(标签-IDE|关键词-File) idea
  • ¥15 潜在扩散模型的Unet特征提取
  • ¥15 iscsi服务无法访问,如何解决?
  • ¥15 感应式传感器制作的感应式讯响器