请写一个java 1.综合使用卡片布局管理器,菜单,单选框,复选框和文本域,标签等,开发一个考试管理系统: (1) 点击“考生信息”菜单,选择“登录”子菜单,进入到用户登录界面。 提示:把登录界面中的所有组件放入到一个JPanel-1 (2) 点击“试卷类型”菜单,选择“数学试卷”,进入数学试卷界面。 提示:把数学试卷界面中的所有组件放入到一个JPanel-2 (3) 点击“试卷类型”菜单,选择“计算机试卷”,进入计算机试卷界面。 提示:把计算机试卷界面中的所有组件放入到一个JPanel-3 然后在卡片布局上,切换3个JPanel

时间: 2024-02-09 09:08:43 浏览: 21
以下是一个简单的Java代码实现考试管理系统,实现了菜单、单选框、复选框、文本域、标签等组件的使用,同时使用卡片布局管理器实现了3个JPanel的切换: ``` import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ExamManagementSystem extends JFrame implements ActionListener{ // 菜单栏 private JMenuBar menuBar; private JMenu studentMenu, paperMenu; private JMenuItem loginItem, mathItem, computerItem; // 卡片布局 private CardLayout cardLayout; private JPanel cardPanel; // 登录界面组件 private JPanel loginPanel; private JLabel userLabel, passLabel; private JTextField userField; private JPasswordField passField; private JButton loginBtn; // 数学试卷界面组件 private JPanel mathPanel; private JLabel mathLabel; private JRadioButton mathOption1, mathOption2, mathOption3; private JButton mathSubmitBtn; // 计算机试卷界面组件 private JPanel computerPanel; private JLabel computerLabel; private JCheckBox computerOption1, computerOption2, computerOption3; private JButton computerSubmitBtn; public ExamManagementSystem(){ // 初始化菜单栏 menuBar = new JMenuBar(); studentMenu = new JMenu("考生信息"); paperMenu = new JMenu("试卷类型"); loginItem = new JMenuItem("登录"); mathItem = new JMenuItem("数学试卷"); computerItem = new JMenuItem("计算机试卷"); studentMenu.add(loginItem); paperMenu.add(mathItem); paperMenu.add(computerItem); menuBar.add(studentMenu); menuBar.add(paperMenu); loginItem.addActionListener(this); mathItem.addActionListener(this); computerItem.addActionListener(this); setJMenuBar(menuBar); // 初始化卡片布局 cardLayout = new CardLayout(); cardPanel = new JPanel(cardLayout); // 初始化登录界面 loginPanel = new JPanel(new GridLayout(3, 2)); userLabel = new JLabel("用户名:"); passLabel = new JLabel("密 码:"); userField = new JTextField(); passField = new JPasswordField(); loginBtn = new JButton("登录"); loginPanel.add(userLabel); loginPanel.add(userField); loginPanel.add(passLabel); loginPanel.add(passField); loginPanel.add(new JLabel()); loginPanel.add(loginBtn); cardPanel.add(loginPanel, "login"); // 初始化数学试卷界面 mathPanel = new JPanel(new GridLayout(4, 1)); mathLabel = new JLabel("1+1="); mathOption1 = new JRadioButton("1"); mathOption2 = new JRadioButton("2"); mathOption3 = new JRadioButton("3"); ButtonGroup mathGroup = new ButtonGroup(); mathGroup.add(mathOption1); mathGroup.add(mathOption2); mathGroup.add(mathOption3); mathSubmitBtn = new JButton("提交"); mathPanel.add(mathLabel); mathPanel.add(mathOption1); mathPanel.add(mathOption2); mathPanel.add(mathOption3); mathPanel.add(mathSubmitBtn); cardPanel.add(mathPanel, "math"); // 初始化计算机试卷界面 computerPanel = new JPanel(new GridLayout(4, 1)); computerLabel = new JLabel("你会哪些编程语言?"); computerOption1 = new JCheckBox("Java"); computerOption2 = new JCheckBox("Python"); computerOption3 = new JCheckBox("C++"); computerSubmitBtn = new JButton("提交"); computerPanel.add(computerLabel); computerPanel.add(computerOption1); computerPanel.add(computerOption2); computerPanel.add(computerOption3); computerPanel.add(computerSubmitBtn); cardPanel.add(computerPanel, "computer"); // 添加卡片布局到窗口中 add(cardPanel); setTitle("考试管理系统"); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e){ if(e.getSource() == loginItem){ cardLayout.show(cardPanel, "login"); }else if(e.getSource() == mathItem){ cardLayout.show(cardPanel, "math"); }else if(e.getSource() == computerItem){ cardLayout.show(cardPanel, "computer"); } } public static void main(String[] args){ new ExamManagementSystem(); } } ```

相关推荐

最新推荐

recommend-type

HTML+CSS实现单选框、复选框美观的样式

主要介绍了HTML+CSS实现单选框、复选框美观的样式,需要的朋友可以参考下
recommend-type

java选择框、单选框和单选按钮

本文给大家介绍的是java中选择框、单选框和单选按钮的操作方法,十分的简单实用,有需要的小伙伴可以参考下。
recommend-type

Bootstrap3 多选和单选框(checkbox)

多选框(checkbox)用于选择列表中的一个或多个选项,而单选框(radio)用于从多个选项中只选择一个。接下来通过本文给大家介绍Bootstrap3 多选和单选框,一起看看吧
recommend-type

浏览器如何自动填写网页下拉列表框、单选框和复选框

针对不同的网页元素控件,详细讲述使用不同的方法自动填写。在浏览器里就可以实现,不需要另外安装软件。自动填表方案放在软件收藏栏,使用时就像打开一个网址一样简单。
recommend-type

表格分页保存复选框状态

用的是element-ui,方法有两个 ...2.toggleRowSelection用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中) //手动单选 onTableSelect(ro
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。