JAVA 作业:图形界面

自己动手写的一个小JAVA 程序:

一个学生管理小系统,虽然很挫,但是这我学JAVA的第一步。学了2天JAVA没有白费!

 

  1 import java.awt.*;
  2 import java.awt.event.*;
  3 import java.util.ArrayList;
  4 
  5 import javax.swing.*;
  6 
  7 class Demo {
  8     public static void main(String[] args) {
  9         new MyFrame();
 10     }                
 11 }
 12 
 13 class Student{
 14 
 15     private String _stuId;
 16     private String _name;
 17     private char[] _secret;
 18     private String _sex;
 19     private String _jiguan;
 20     private String _xibie;
 21     private String _course;
 22     public String get_stuId() {
 23         return _stuId;
 24     }
 25     public void set_stuId(String _stuId) {
 26         this._stuId = _stuId;
 27     }
 28     public String get_name() {
 29         return _name;
 30     }
 31     public void set_name(String _name) {
 32         this._name = _name;
 33     }
 34     public String get_sex() {
 35         return _sex;
 36     }
 37     public void set_sex(String _sex) {
 38         this._sex = _sex;
 39     }
 40     public String get_jiguan() {
 41         return _jiguan;
 42     }
 43     public void set_jiguan(String _jiguan) {
 44         this._jiguan = _jiguan;
 45     }
 46     public String get_xibie() {
 47         return _xibie;
 48     }
 49     public void set_xibie(String _xibie) {
 50         this._xibie = _xibie;
 51     }
 52     public String get_course() {
 53         return _course;
 54     }
 55     public void set_course(String _course) {
 56         this._course = _course;
 57     }
 58     public char[] get_secret() {
 59         return _secret;
 60     }
 61     public void set_secret(char[] dd_secret) {
 62         this._secret = dd_secret;
 63     }
 64 }
 65 
 66 
 67 
 68 class MyFrame extends JFrame {
 69     
 70     ArrayList<Student> students=new ArrayList<Student>();
 71     public MyFrame() {
 72         Box baseBox,box1,box2;
 73         setTitle("学生信息录用");
 74         setSize(350, 650);
 75         setVisible(true);
 76         setResizable(false);
 77         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 78         
 79         box1 = Box.createVerticalBox();
 80         box1.add(Box.createVerticalStrut(30));
 81         box1.add(new JLabel("学号"));
 82         box1.add(Box.createVerticalStrut(30));
 83         box1.add(new JLabel("姓名"));
 84         box1.add(Box.createVerticalStrut(30));
 85         box1.add(new JLabel("密码"));
 86 
 87         box2 = Box.createVerticalBox();
 88         box2.add(Box.createVerticalStrut(30));
 89         final JTextField TF_stuid = new JTextField(10);
 90         box2.add(TF_stuid);
 91         box2.add(Box.createVerticalStrut(30));
 92         final JTextField TF_name = new JTextField(10);
 93         box2.add(TF_name);
 94         box2.add(Box.createVerticalStrut(30));
 95         final JPasswordField TF_secret = new JPasswordField(10);
 96         box2.add(TF_secret);
 97         
 98         Box box3 =  Box.createHorizontalBox();
 99         ButtonGroup g = new ButtonGroup();
100         final String JRb1 = "男";
101         final String JRb2 = "女";
102         final JRadioButton b1 = new JRadioButton(JRb1);
103         final JRadioButton b2 = new JRadioButton(JRb2);
104 
105         
106         //final String sex ;
107         g.add(b1);
108         g.add(b2);
109         box3.add(new JLabel("性别"));
110         box3.add(Box.createHorizontalStrut(20));
111         box3.add(b1);
112         box3.add(Box.createHorizontalStrut(20));
113         box3.add(b2);
114         
115         baseBox = Box.createHorizontalBox();
116         baseBox.add(box1);
117         baseBox.add(Box.createHorizontalStrut(30));
118         baseBox.add(box2);
119         //baseBox.add(box3);
120         //add(baseBox);
121         Box box5,box6,box7;
122         box5 = Box.createVerticalBox();
123         box5.add(Box.createVerticalStrut(30));
124         box5.add(new JLabel("籍贯"));
125         box5.add(Box.createVerticalStrut(30));
126         box5.add(new JLabel("系别"));
127 
128         final String[] xibie = {"计算机与科学", "软件工程", "网络工程", "嵌入式系统开发", "信息工程"};
129         final JComboBox jb = new JComboBox(xibie);
130         box6 = Box.createVerticalBox();
131         box6.add(Box.createVerticalStrut(30));
132         final JTextField TF_jiguan = new JTextField(10);
133         box6.add(TF_jiguan);
134         box6.add(Box.createVerticalStrut(30));
135         box6.add(jb);
136 
137         box7 = Box.createHorizontalBox();
138         box7.add(box5);
139         box7.add(Box.createHorizontalStrut(30));
140         box7.add(box6);
141         
142         final JCheckBox[] ch = new JCheckBox[6];
143         ch[0]=new JCheckBox("C++程序设计");
144         ch[1]=new JCheckBox("计算机组成原理");
145         ch[2]=new JCheckBox("汇编原理");
146         ch[3]=new JCheckBox("数据结构");
147         ch[4]=new JCheckBox("数据库设计原理");
148         ch[5]=new JCheckBox("软件工程");
149         
150         
151         Box box8,box9,box10;
152         box8 = Box.createVerticalBox();
153         box8.add(new JLabel("课程"));
154         
155         box9 = Box.createVerticalBox();
156         box9.add(ch[0]);
157         box9.add(ch[1]);
158         box9.add(ch[2]);
159         box9.add(ch[3]);
160         box9.add(ch[4]);
161         box9.add(ch[5]);
162         
163         box10 = Box.createHorizontalBox();
164         box10.add(box8);
165         box10.add(Box.createHorizontalStrut(100));
166         box10.add(box9);
167         
168         JButton dd1 = new JButton("确认", new ImageIcon("3.JPG"));
169         JButton dd2 = new JButton("取消");
170         
171         dd1.addActionListener(new ActionListener(){
172             
173             public void actionPerformed(ActionEvent e){
174                 
175                 String dd_stuid = TF_stuid.getText(); 
176                 if(dd_stuid.equals("")) System.out.println(123);
177                 String dd_name = TF_name.getText();
178                 String dd_jiguan = TF_jiguan.getText();
179                 char[] dd_secret = TF_secret.getPassword();
180                 
181                 String dd_sex = null;
182                 if(b1.isSelected())
183                     dd_sex = "男";
184                 if(b2.isSelected())
185                     dd_sex = "女";
186                 String course = "";
187                 String[] sz_course = {"C++程序设计 ", "计算机组成原理 ", "汇编原理 ", "数据结构 ", "数据库设计原理 ","软件工程 "};
188         
189                 for(int i=0;i<6;++i)
190                     if(ch[i].isSelected())
191                         course+=sz_course[i];
192                 
193                 int int_jb = jb.getSelectedIndex();
194                 String dd_xibie = xibie[int_jb];
195                 System.out.println(xibie[int_jb]);
196                 Student st = new Student();
197                 st.set_stuId(dd_stuid);
198                 st.set_name(dd_name);
199                 st.set_secret(dd_secret);
200                 st.set_jiguan(dd_jiguan);
201                 st.set_sex(dd_sex);
202                 st.set_xibie(dd_xibie);
203                 st.set_course(course);
204         
205                 students.add(st);
206                 if(TF_stuid.getText().equals("")||TF_name.getText().equals("") ||TF_jiguan.getText().equals("") )
207                     JOptionPane.showMessageDialog(null, "录入失败");
208                 else JOptionPane.showMessageDialog(null, "录入成功");
209                 
210                 TF_stuid.setText("");
211                 TF_name.setText("");
212                 TF_jiguan.setText("");
213                 TF_secret.setText("");
214             }
215         });
216         
217         dd2.addActionListener(new ActionListener(){
218             public void actionPerformed(ActionEvent e){
219                 dispose();
220             }
221         });
222         
223         
224         Box box11 = Box.createHorizontalBox();
225         box11.add(dd1);
226         box11.add(Box.createHorizontalStrut(30));
227         box11.add(dd2);
228         
229         Box box4 = Box.createVerticalBox();
230         box4.add(baseBox);
231         box4.add(Box.createVerticalStrut(10));
232         box4.add(box3);
233         box4.add(box7);
234         box4.add(Box.createVerticalStrut(20));
235         box4.add(box10);
236         box4.add(Box.createVerticalStrut(20));
237         box4.add(box11);
238         add(box4);
239             
240         
241 
242         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
243         int x = (screenSize.width - getWidth()) / 2;
244         int y = (screenSize.height - getHeight()) / 2;
245         setLocation(x, y);
246 
247         setLayout(new FlowLayout());
248         validate();
249 
250     }
251 }

 

转载于:https://www.cnblogs.com/firstrate/p/3446789.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377519.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一、Pytorch对自定义表达式自动求导

例如&#xff1a;y ax bx c&#xff0c;分别对a&#xff0c;b&#xff0c;c求导 若当a3&#xff0c;b4&#xff0c;c5&#xff0c;x1时 import torch from torch import autogradx torch.tensor(1.) a torch.tensor(3.,requires_gradTrue) b torch.tensor(4.,requires…

css菜单下拉菜单_在CSS中创建下拉菜单

css菜单下拉菜单CSS | 创建下拉菜单 (CSS | Creating Dropdown) Trivia: 琐事&#xff1a; We know the importance of navigation bar on our webpage, we know the importance of a list of items too on our webpage but what is the importance of dropdown in web pages?…

C++ 内存基本构件new/delete的意义、运用方式以及重载方式

目录一、对new的理解1、new做了什么2、new被编译器转为了什么3、operate_new源代码长啥样二、对delete的理解1、delete做了什么2、delete被编译器转为了什么3、operator delete源代码长啥样三、构造函数与析构函数的直接调用参考一、对new的理解 1、new做了什么 C告诉我们&am…

二、线性代数

一、张量 张量表示由一个数值组成的数组&#xff0c;这个数组可能有多个维度 import torchx torch.arange(15) x # tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])1&#xff0c;shape shape属性可以访问张量的形状 x.shape # torch.Size([15])2&a…

Wordpress prettyPhoto插件跨站脚本漏洞

漏洞名称&#xff1a;Wordpress prettyPhoto插件跨站脚本漏洞CNNVD编号&#xff1a;CNNVD-201311-413发布时间&#xff1a;2013-11-28更新时间&#xff1a;2013-11-28危害等级&#xff1a; 漏洞类型&#xff1a;跨站脚本威胁类型&#xff1a;远程CVE编号&#xff1a; 漏洞来源…

JavaScript学习笔记1

Netscape 公司 DOM模型&#xff0c;层(layer)-用ID标识。 HTML标记页面上的元素&#xff0c; <div id "mydiv">This is my div</div> CSS为这个页面元素定位 #mydiv{ position:absolute; left:320px; top:110px; } JavaScript 访问 (DOM模块不同&#x…

c# 中关键字_C#中的“使用”关键字

c# 中关键字Prerequisite: Namespace in C# 先决条件&#xff1a; C&#xff03;中的命名空间 If you want to include namespace in a program then we need to use using keyword. For example we use Console class which is defined in System namespace that’s why we n…

C++ 内存基本构件new [] /delete []的意义、内存泄漏原因、VC下cookie的基本布局

目录一、对new [] delete [] 的理解1、delete的[]遗漏会带来什么影响二、以示例探讨三、cookie的理解一、对new [] delete [] 的理解 new的对象是个array类型的。 Complex* pca new Complex[3]; //唤起三次ctor //无法借由参数给予初值 ... delete[] pca; //唤起3次dtor如下…

OpenJudge计算概论-找出第k大的数

/* 找出第k大的数 总时间限制: 1000ms 内存限制: 1000kB 描述 用户输入N和K&#xff0c;然后接着输入N个正整数&#xff08;无序的&#xff09;&#xff0c;程序在不对N个整数排序的情况下&#xff0c;找出第K大的数。注意&#xff0c;第K大的数意味着从大到小排在第K位的数。并…

01背包怎么不重复_带有重复物品的背包

01背包怎么不重复Problem statement: 问题陈述&#xff1a; Weights and values are given for n items along with the maximum capacity allowed W. What is the maximum value we can achieve if we can pick any weights, any number of times for the total allowed capa…

jQuery数组处理汇总

有段时间没写什么了, 打算把jquery中的比较常用的数组处理方法汇总一下 $.each(array, [callback])遍历,很常用 ?12345678var arr [javascript, php, java, c, c#, perl, vb, html, css, objective-c];$.each(arr, function(key, val) {// firebug consoleconsole.log(index …

C++ 内存基本构件 placement new

用法以及编译器解释 placement new 允许我们将object构建于已经分配的内存上。(所以此时必须有个指针指向已经分配好的内存) 没有所谓的placement delete &#xff0c;因为placement new根本没有分配内存. 也有种说法&#xff0c;是将placement new对应的内存释放掉的操作为pl…

二维数组for遍历

<?php$conarray(array(1,高某,A公司,北京市,010,abc),array(2,罗某,B公司,天津市,020,bcd),array(3,冯某,C公司,上海市,021,cdf),array(4,书某,D公司,重庆市,022,dfg));echo <table border"1" width"600" align"center">;echo <cap…

Xcode调试相关小结

一.设置NSZombieEnabled 使用NSZombieEnabled功能,当代码中访问已经释放了内存的地方,会给你下面这样的提示,而不仅仅是EXEC_BAD_ACCESS: 2008-10-03 18:10:39.933 HelloWorld[1026:20b] *** -[GSFont ascender]: message sent to deallocated instance 0x126550 如果要查看上面…

ONGC的完整形式是什么?

ONGC&#xff1a;石油天然气公司 (ONGC: Oil and Natural Gas Corporation) ONGC is an abbreviation of Oil and Natural Gas Corporation. It is an Indian multinational corporation that is one of the leading producers of crude oil and natural gas in India. Its hea…

C/C++代码优化方法

目录优化概述_O0优化_O1优化_O2优化_O3优化volatile关键字避免优化优化概述 如果将未经优化的C语言程序直接运行会发现运行效率较低&#xff0c;并且产生的代码较大&#xff0c;而通过优化可以较好地解决这些问题。 优化的作用是对循环进行化简&#xff0c;重新组织表达式和声…

大学生应当趁早谋划未来(二)--给表弟的建议

背景表弟&#xff0c;大四&#xff0c;湖北某二本院校&#xff0c;计算机相关专业。大学期间&#xff0c;对Java等编程没有兴趣&#xff0c;几乎没怎么学习。平时&#xff0c;课程比较多&#xff0c;每天6节左右。课外&#xff0c;自己去挣点生活费,父亲生病了。困境最近在找工…

UVa 490 - Rotating Sentences

把输入的字符顺时针旋转90度。 1 #include<stdio.h>2 #include<string.h>3 4 int main()5 {6 int i, j, max, n, m;7 char s[105][105];8 max0;9 memset(s, \0, sizeof(s)); 10 for (i0; gets(s[i]); i) 11 { 12 nstrlen(s[i]); 1…

node 大写_大写Node.js模块

node 大写Today, lets see a third party module that helps us in working with upper-case letters without necessarily typing them in upper-case in our source code. 今天&#xff0c;让我们看一个第三方模块&#xff0c;它可以帮助我们处理大写字母&#xff0c;而不必在…

1704:baoge的洗漱难题[黄]

baoge的洗漱难题[黄] Time Limit: 5000 ms Memory Limit: 65536 KB Total Submit: 79 Accepted: 21 Description众所周知&#xff0c;地大19楼的盥洗室非常小&#xff0c;所以经常会非常拥挤&#xff0c;很多时候去洗漱的时候不得不排很长的队。有时候baoge会排上半小时…