一、系统简介
1.1、简介
本系统提供了学生信息管理中常见的基本功能,主要包括管理员。管理员的主要功能有对学生信息进行增加、删除、修改、查找等操作,对信息进行管理,对信息进行修改、查找等操作。
二、功能设计
2.1 需求分析
21世纪是信息化时代,信息化已更快捷更方便为目标来融入各行各业。学校也不例外。当前,我国的学校正在加紧实施信息化建设,其中学生信息管理是相对重要的 一部分。
目前,社会上信息管理系统发展飞快,各个企事业单位都引入了信息化管理软件来管理自己日益增长的各种信息,学生信息管理系统也是有了很快的发展,商业化软件也不少。但本程序功能简介明了,功能较为齐全,而且操作简单。
学生信息管理系统是一个教育单位不可缺少的一部分,它的内容对于学校的管理者来书及其重要,所以学生信息管理系统应该能够为用户提供充足的信息和查询的快捷手段。
2.2 模块详细设计
1、学生信息管理模块
学生信息管理模块包括增加、删除、修改、查询、显示全部等。具体的结构图如图所示。
学生信息管理模块结构图
三、数据库设计
3.1数据库设计图
在数据库学生中的一张数据表:s(学生信息表),下面定义每张表的字段名称和数据类型。
(学生信息表)
字段名称 |
数据类型 |
描述 |
姓名 |
char (20) |
姓名 |
年龄 |
int(20) |
年龄 |
性别 |
char(20) |
性别 |
学号 |
char (20) |
学号 |
专业 |
char (20) |
专业 |
爱好 |
Char(20) |
爱好 |
3.2源代码:
1 package Bp;
2 import java.awt.*;
3
4 import javax.swing.*;
5
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.MouseEvent;
9 import java.awt.event.MouseListener;
10 import java.sql.Connection;
11 import java.sql.DriverManager;
12 import java.sql.ResultSet;
13 import java.sql.SQLException;
14 import java.sql.Statement;
15 import java.util.logging.Level;
16 import java.util.logging.Logger;
17
18 import javax.swing.*;
19 import javax.swing.event.MouseInputListener;
20
21 public class B {
22
23 public static void main(String[] args) {
24 // TODO Auto-generated method stub
25 // TODO Auto-generated method stub
26 My_object1 my =new My_object1();
27
28 }
29
30 }
31 class My_object1 extends JFrame{
32
33 public JTextField j3;
34 public JTextField j4;
35 ImageIcon img = null;
36 JPanel p;
37 public My_object1(){
38
39 img = new ImageIcon( "C:\\用户\\zhangye123\\图片\\1569976476.jpg ");
40
41 setTitle("登录");
42 setSize(200,150);
43
44 //、、JFrame j=new JFrame();
45 JPanel p=new JPanel();
46 LayoutManager icon = (LayoutManager) new ImageIcon("c:\\用户\\zhangye123\\图片\\1569976476.jpg");
47
48
49 getContentPane().add(p);
50
51 JLabel j1=new JLabel("密码 ");
52 JLabel j2=new JLabel("用户名");
53 JLabel j7=new JLabel(img);
54 j3=new JTextField(10);
55 j4=new JTextField(10);
56 JButton j5=new JButton("确定");
57 JButton j6=new JButton("取消");
58 p.add(j7);
59 p.add(j2);
60 p.add(j3);
61 p.add(j1);
62 p.add(j4);
63 p.add(j5);
64 p.add(j6);
65 j6.addActionListener(new ActionListener() {
66
67 @Override
68 public void actionPerformed(ActionEvent e) {
69 // TODO 自动生成的方法存根
70 if(e.getActionCommand().equals("取消")){
71 System.exit(0);
72 }
73 }
74 });
75 // final String userName = "abc";
76 //final String passwrod = "123";
77
78 j5.addMouseListener(new Mouselen());
79 setLocationRelativeTo(null);
80 setVisible(true);
81 }
82 class Mouselen implements MouseListener{
83
84 @Override
85 public void mouseClicked(MouseEvent e) {
86 // TODO Auto-generated method stub
87 if(!j3.getText().equals("123456"))
88 //System.out.println("用户名错误");
89 JOptionPane.showMessageDialog(null, "账号错误");
90 if(!j4.getText().equals("789"))
91 //System.out.println("密码错误");
92 JOptionPane.showMessageDialog(null, "密码错误");
93 else //System.out.println("输入正确");
94 //JOptionPane.showMessageDialog(null, "登录成功");
95 {
96 //System.exit(0);
97 new guanli();
98 }
99 }
100
101 @Override
102 public void mouseEntered(MouseEvent e) {
103 // TODO Auto-generated method stub
104
105 }
106
107 @Override
108 public void mouseExited(MouseEvent e) {
109 // TODO Auto-generated method stub
110
111 }
112
113 @Override
114 public void mousePressed(MouseEvent e) {
115 // TODO Auto-generated method stub
116
117 }
118
119 @Override
120 public void mouseReleased(MouseEvent e) {
121 // TODO Auto-generated method stub
122
123 }
124
125
126 }
127
128 }
129 class guanli extends JFrame{
130 JButton b1;
131 JButton b2;
132 public guanli(){
133 setSize(550,370);
134 Toolkit tk=getToolkit();
135 Dimension d1=tk.getScreenSize();
136 int w=(int)d1.getWidth();
137 int h=(int)d1.getHeight();
138 setLocation(w/2-550/2, h/2-370/2);
139 setVisible(true);
140 setTitle("信息管理系统");
141 //Image img1=tk.getImage("./src/jame/1-140326154313.jpg");
142 //setIconImage(img1);
143 ImageIcon img2 = new ImageIcon("./src/jame/13.jpg"); //相对路径获取图片
144 JLabel imgLabel = new JLabel(img2); //创建图片标签
145 this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
146 //为标签设置为容器最底层;getLayeredPane()作用是为容器添加深度,允许组件互相重叠;Integer.MIN_VALUE最底层
147 imgLabel.setBounds(0,0,img2.getIconWidth(), img2.getIconHeight());
148 Container cp=getContentPane(); //获取*容器
149 ((JPanel)cp).setOpaque(false); //设置透明以使底层背景图片显示
150 cp.setLayout(null);
151
152 JLabel imgLable=new JLabel();
153 JLabel j2=new JLabel("***欢迎登陆学生管理系统***");
154 JLabel j1=new JLabel("~~请在左侧选择所做的操作~~");
155 JButton b1=new JButton("查询");
156 JButton b2=new JButton("取消");
157 JButton b3=new JButton("修改");
158 JButton b4=new JButton("增添");
159 JButton b5=new JButton("删除");
160 JTextArea t3=new JTextArea(150,150);
161 cp.add(j2);
162 j2.setBounds(220,110,190,25);
163 cp.add(j1);
164 j1.setBounds(220,150,190,25);
165 cp.add(b1);
166 b1.setBounds(0, 70, 90, 25);
167 cp.add(b2);
168 b2.setBounds(250, 250, 70, 25);
169 cp.add(b4);
170 b4.setBounds(0,110,90,25);
171 cp.add(b3);
172 b3.setBounds(0,150,90,25);
173 cp.add(b5);
174 b5.setBounds(0,190,90,25);
175 b2.addActionListener(new ActionListener() {
176
177 @Override
178 public void actionPerformed(ActionEvent e) {
179 // TODO 自动生成的方法存根
180 if(e.getActionCommand().equals("取消")){
181 System.exit(0);
182 }
183 }
184 });
185 b1.addActionListener(new ActionListener() {
186
187 @Override
188 public void actionPerformed(ActionEvent e) {
189 // TODO 自动生成的方法存根
190 new chaxun();
191
192 }
193 });
194 b3.addActionListener(new ActionListener() {
195
196 @Override
197 public void actionPerformed(ActionEvent e) {
198 // TODO 自动生成的方法存根
199 new xiugai();
200
201 }
202 });
203 b4.addActionListener(new ActionListener() {
204
205 @Override
206 public void actionPerformed(ActionEvent e) {
207 // TODO 自动生成的方法存根
208 new zengtian();
209
210 }
211 });
212 b5.addActionListener(new ActionListener() {
213
214 @Override
215 public void actionPerformed(ActionEvent e) {
216 // TODO 自动生成的方法存根
217 new shanchu();
218
219 }
220 });
221 }
222 }
223
224 class chaxun extends JFrame{
225 TextField t1;
226 TextField t2;
227
228 public chaxun(){
229 setTitle("查询");
230 setSize(550, 370);
231 JPanel p1=new JPanel();
232 //getContentPane().add(p1);
233 JLabel j1=new JLabel("学号: " );
234 JLabel j2=new JLabel("姓名: ");
235 JLabel j3=new JLabel("专业: ");
236 TextField t1=new TextField(70);
237 TextField t2=new TextField(70);
238 TextField t3=new TextField(70);
239 JButton b=new JButton("查询");
240 JButton b1=new JButton("取消");
241 ImageIcon img2 = new ImageIcon("./src/1-140326154313.jpg"); //相对路径获取图片
242 JLabel imgLabel = new JLabel(img2); //创建图片标签
243 this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
244 //为标签设置为容器最底层;getLayeredPane()作用是为容器添加深度,允许组件互相重叠;Integer.MIN_VALUE最底层
245 imgLabel.setBounds(0,0,img2.getIconWidth(), img2.getIconHeight());
246 Container p11=getContentPane(); //获取*容器
247 ((JPanel)p11).setOpaque(false); //设置透明以使底层背景图片显示
248 p11.setLayout(null);
249 p11.add(j2);
250 j2.setBounds(50, 70, 70, 25);
251 p11.add(t1);
252 t1.setBounds(150, 70,100, 20);
253 p11.add(j1);
254 j1.setBounds(50, 150, 70, 25);
255 p11.add(t2);
256 t2.setBounds(150,150,100, 20);
257 p11.add(j3);
258 j3.setBounds(50,230,70, 25);
259 p11.add(t3);
260 t3.setBounds(150, 230,100, 20);
261 p11.add(b);
262 b.setBounds(400,140,90,25);
263 p11.add(b1);
264 b1.setBounds(400,170,90,25);
265 setLocationRelativeTo(null);
266 setVisible(true);
267 final String url = "jdbc:mysql://localhost:3306/test";
268 b1.addActionListener(new ActionListener() {
269
270 @Override
271 public void actionPerformed(ActionEvent e) {
272 // TODO 自动生成的方法存根
273 if(e.getActionCommand().equals("取消")){
274 System.exit(0);
275 }
276 }
277 });
278 b.addActionListener(new ActionListener() {
279
280 @Override
281 public void actionPerformed(ActionEvent arg0) {
282 // TODO Auto-generated method stub
283
284
285 try (Connection conn = DriverManager.getConnection(url,"root","1234"))
286 {
287 Statement state = conn.createStatement();
288 ResultSet result = state.executeQuery("SELECT name FROM xuesheng");
289
290
291 } catch (SQLException ex) {
292
293 ex.getSQLState();
294 }
295 }
296 });
297 }
298 }
299
300 class xiugai extends JFrame{
301 public xiugai(){
302 setTitle("修改");
303 setSize(550, 370);
304 JPanel p1=new JPanel();
305 getContentPane().add(p1);
306 setLocationRelativeTo(null);
307 setVisible(true);
308
309 }
310 }
311
312 class zengtian extends JFrame{
313 public zengtian(){
314 setTitle("增添");
315 setSize(550, 370);
316 JPanel p1=new JPanel();
317 getContentPane().add(p1);
318 setLocationRelativeTo(null);
319 setVisible(true);
320 }
321 }
322
323 class shanchu extends JFrame{
324 public shanchu(){
325 setTitle("删除");
326 setSize(550, 370);
327 JPanel p1=new JPanel();
328 getContentPane().add(p1);
329 setLocationRelativeTo(null);
330 setVisible(true);
331 }
332 }
四、程序运行结果及分析
4.1程序运行图
此文链接:http://makaidong.com/zhuzhu520/11674_156814.html
转载请注明出处:java实现简单的数据库的增删查改,并布局交互界面