JAVA 作业:图形界面
自己动手写的一个小JAVA 程序:
一个学生管理小系统,虽然很挫,但是这我学JAVA的第一步。学了2天JAVA没有白费!
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList; import javax.swing.*; class Demo {
public static void main(String[] args) {
new MyFrame();
}
} class Student{ private String _stuId;
private String _name;
private char[] _secret;
private String _sex;
private String _jiguan;
private String _xibie;
private String _course;
public String get_stuId() {
return _stuId;
}
public void set_stuId(String _stuId) {
this._stuId = _stuId;
}
public String get_name() {
return _name;
}
public void set_name(String _name) {
this._name = _name;
}
public String get_sex() {
return _sex;
}
public void set_sex(String _sex) {
this._sex = _sex;
}
public String get_jiguan() {
return _jiguan;
}
public void set_jiguan(String _jiguan) {
this._jiguan = _jiguan;
}
public String get_xibie() {
return _xibie;
}
public void set_xibie(String _xibie) {
this._xibie = _xibie;
}
public String get_course() {
return _course;
}
public void set_course(String _course) {
this._course = _course;
}
public char[] get_secret() {
return _secret;
}
public void set_secret(char[] dd_secret) {
this._secret = dd_secret;
}
} class MyFrame extends JFrame { ArrayList<Student> students=new ArrayList<Student>();
public MyFrame() {
Box baseBox,box1,box2;
setTitle("学生信息录用");
setSize(350, 650);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); box1 = Box.createVerticalBox();
box1.add(Box.createVerticalStrut(30));
box1.add(new JLabel("学号"));
box1.add(Box.createVerticalStrut(30));
box1.add(new JLabel("姓名"));
box1.add(Box.createVerticalStrut(30));
box1.add(new JLabel("密码")); box2 = Box.createVerticalBox();
box2.add(Box.createVerticalStrut(30));
final JTextField TF_stuid = new JTextField(10);
box2.add(TF_stuid);
box2.add(Box.createVerticalStrut(30));
final JTextField TF_name = new JTextField(10);
box2.add(TF_name);
box2.add(Box.createVerticalStrut(30));
final JPasswordField TF_secret = new JPasswordField(10);
box2.add(TF_secret); Box box3 = Box.createHorizontalBox();
ButtonGroup g = new ButtonGroup();
final String JRb1 = "男";
final String JRb2 = "女";
final JRadioButton b1 = new JRadioButton(JRb1);
final JRadioButton b2 = new JRadioButton(JRb2); //final String sex ;
g.add(b1);
g.add(b2);
box3.add(new JLabel("性别"));
box3.add(Box.createHorizontalStrut(20));
box3.add(b1);
box3.add(Box.createHorizontalStrut(20));
box3.add(b2); baseBox = Box.createHorizontalBox();
baseBox.add(box1);
baseBox.add(Box.createHorizontalStrut(30));
baseBox.add(box2);
//baseBox.add(box3);
//add(baseBox);
Box box5,box6,box7;
box5 = Box.createVerticalBox();
box5.add(Box.createVerticalStrut(30));
box5.add(new JLabel("籍贯"));
box5.add(Box.createVerticalStrut(30));
box5.add(new JLabel("系别")); final String[] xibie = {"计算机与科学", "软件工程", "网络工程", "嵌入式系统开发", "信息工程"};
final JComboBox jb = new JComboBox(xibie);
box6 = Box.createVerticalBox();
box6.add(Box.createVerticalStrut(30));
final JTextField TF_jiguan = new JTextField(10);
box6.add(TF_jiguan);
box6.add(Box.createVerticalStrut(30));
box6.add(jb); box7 = Box.createHorizontalBox();
box7.add(box5);
box7.add(Box.createHorizontalStrut(30));
box7.add(box6); final JCheckBox[] ch = new JCheckBox[6];
ch[0]=new JCheckBox("C++程序设计");
ch[1]=new JCheckBox("计算机组成原理");
ch[2]=new JCheckBox("汇编原理");
ch[3]=new JCheckBox("数据结构");
ch[4]=new JCheckBox("数据库设计原理");
ch[5]=new JCheckBox("软件工程"); Box box8,box9,box10;
box8 = Box.createVerticalBox();
box8.add(new JLabel("课程")); box9 = Box.createVerticalBox();
box9.add(ch[0]);
box9.add(ch[1]);
box9.add(ch[2]);
box9.add(ch[3]);
box9.add(ch[4]);
box9.add(ch[5]); box10 = Box.createHorizontalBox();
box10.add(box8);
box10.add(Box.createHorizontalStrut(100));
box10.add(box9); JButton dd1 = new JButton("确认", new ImageIcon("3.JPG"));
JButton dd2 = new JButton("取消"); dd1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String dd_stuid = TF_stuid.getText();
if(dd_stuid.equals("")) System.out.println(123);
String dd_name = TF_name.getText();
String dd_jiguan = TF_jiguan.getText();
char[] dd_secret = TF_secret.getPassword(); String dd_sex = null;
if(b1.isSelected())
dd_sex = "男";
if(b2.isSelected())
dd_sex = "女";
String course = "";
String[] sz_course = {"C++程序设计 ", "计算机组成原理 ", "汇编原理 ", "数据结构 ", "数据库设计原理 ","软件工程 "}; for(int i=0;i<6;++i)
if(ch[i].isSelected())
course+=sz_course[i]; int int_jb = jb.getSelectedIndex();
String dd_xibie = xibie[int_jb];
System.out.println(xibie[int_jb]);
Student st = new Student();
st.set_stuId(dd_stuid);
st.set_name(dd_name);
st.set_secret(dd_secret);
st.set_jiguan(dd_jiguan);
st.set_sex(dd_sex);
st.set_xibie(dd_xibie);
st.set_course(course); students.add(st);
if(TF_stuid.getText().equals("")||TF_name.getText().equals("") ||TF_jiguan.getText().equals("") )
JOptionPane.showMessageDialog(null, "录入失败");
else JOptionPane.showMessageDialog(null, "录入成功"); TF_stuid.setText("");
TF_name.setText("");
TF_jiguan.setText("");
TF_secret.setText("");
}
}); dd2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
}); Box box11 = Box.createHorizontalBox();
box11.add(dd1);
box11.add(Box.createHorizontalStrut(30));
box11.add(dd2); Box box4 = Box.createVerticalBox();
box4.add(baseBox);
box4.add(Box.createVerticalStrut(10));
box4.add(box3);
box4.add(box7);
box4.add(Box.createVerticalStrut(20));
box4.add(box10);
box4.add(Box.createVerticalStrut(20));
box4.add(box11);
add(box4); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screenSize.width - getWidth()) / 2;
int y = (screenSize.height - getHeight()) / 2;
setLocation(x, y); setLayout(new FlowLayout());
validate(); }
}
JAVA 作业:图形界面的更多相关文章
- Java的图形界面依然是跨平台的
Awt:抽象窗口工具箱,它由三部分组成: ①组件:界面元素: ②容器:装载组件的容器(例如窗体): ③布局管理器:负责决定容器中组件的摆放位置. 图形界面的应用分四步: ① 选择一个容器: ⑴wind ...
- Java Swing 图形界面开发(目录)
Java Swing 图形界面开发(目录) 2017年05月30日 23:50:42 阅读数:5228 本文链接: http://blog.csdn.net/xietansheng/article/d ...
- Java Swing图形界面开发
本文转自xietansheng的CSDN博客内容,这是自己见过的最通俗易懂.最适合快速上手做Java GUI开发的教程了,这里整合一下作为自己以后复习的笔记: 原文地址:https://blog.cs ...
- Java自学-图形界面 容器
Swing 的容器 JFrame和JDialog java的图形界面中,容器是用来存放 按钮,输入框等组件的. 窗体型容器有两个,一个是JFrame,一个是JDialog 步骤 1 : JFrame ...
- 【计项02组01号】Java版图形界面计算器
Java版图形界面计算器1.0版本 项目分析[1.0] 组成部分 代码结构 (1)窗口的创建 在<JDK 核心 API>中我们提到,创建一个窗口需要使用 JFrame 类.在本实验中,我们 ...
- JAVA与图形界面开发(Applet应用程序、AWT库、Swing)
Applet 1)简单说,Applet就是嵌入到网页中的小程序,Java代码. 2)编写Applet程序,要继承JApplet类,并根据自己需要覆写相关方法(init.start.stop.destr ...
- Java GUI图形界面开发工具
Applet 应用程序 一种可以在 Web 浏览器中执行的小程序,扩展了浏览器中的网页功能. 缺: 1.需要下载 Applet 及其相关文件 2.Applet 的功能是受限制的 优: 3.无需 ...
- Java自学-图形界面 Swing中的线程
Swing中的线程 步骤 1 : 三种线程 在Swing程序的开发中,需要建立3种线程的概念 初始化线程 初始化线程用于创建各种容器,组件并显示他们,一旦创建并显示,初始化线程的任务就结束了. 事件调 ...
- java的图形界面初学惯用
1.单一界面的创建 public void mainFrame() { HashMap<String, Component> views = new HashMap<String, ...
- Java实现图形界面的三部曲及IDE中的窗口设计
设计和实现图形用户界面的工作主要有以下几点: • (1)创建组件(Component) • 创建组成界面的各种元素,如按钮.文本框等.• (2)指定布局(Layout) • 根据具体需要排列它们的位置 ...
随机推荐
- mac 配置Python集成开发环境
mac 配置Python集成开发环境(Eclipse +Python+Pydev) 1.下载Mac版64位的Eclipse. 进入到Eclipse官方网站的下载页面(http://www.eclips ...
- (转).net webconfig使用IConfigurationSectionHandler自定section
自定义配置结构 (使用IConfigurationSectionHandler) 假设有以下的配置信息,其在MyInfo可以重复许多次,那么应如何读取配置呢?这时就要使用自定义的配置程序了.<m ...
- Unobtrusive JavaScript 是什么?
Unobtrusive JavaScript 是什么? <!--以下是常规Javascript下写出来的Ajax--><div id="test">< ...
- P31RestKit.dll 2.0 Unity3d json
using System.Collections.Generic; using UnityEngine; using System.Collections; using Prime31; public ...
- XEvent – SQL Server Log文件对磁盘的写操作大小是多少
原文:XEvent – SQL Server Log文件对磁盘的写操作大小是多少 本篇是上一篇SQL Server Log文件对磁盘的写操作大小是多少的续,使用XEvent收集SQL Server D ...
- 【百度地图API】百度API卫星图使用方法和卫星图对比工具
原文:[百度地图API]百度API卫星图使用方法和卫星图对比工具 百度地图API推出卫星图接口也有一个月啦~ 本文除了介绍如何使用百度地图API来操作卫星图外,还顺带制作了个卫星图对比工具. 一.百度 ...
- winform屏幕截图
原文:winform屏幕截图 屏幕截图是一个比较常用的功能,在项目中出现的比例也比较高,至少我做过的每个项目都有屏幕截图这个功能,从全屏截图到区域截图都有出现过.当然区域截图已然包含了全屏截图. 全屏 ...
- Factorization Machines 学习笔记(二)模型方程
近期学习了一种叫做 Factorization Machines(简称 FM)的算法,它可对随意的实值向量进行预測.其主要长处包含: 1) 可用于高度稀疏数据场景:2) 具有线性的计算复杂度.本文 ...
- PHP经验——获得PHP版本信息及版本比较
原文:PHP经验--获得PHP版本信息及版本比较 偶然看到别人写的一句代码: <?php if (version_compare("5.2", PHP_VERSION, &q ...
- 图片alpha blending的计算
转载时请注明出处和作者联系方式:http://blog.csdn.net/mimepp作者联系方式:YU TAO <yut616 at sohu dot com> 一幅彩色图像的每一个像素 ...