• 基于java+swing+mysql北方传统民居信息管理系统


    一、系统介绍

    用户:民居信息浏览、民居详细信息
    管理员:民居信息浏览、民居信息添加、民居信息详情、民居信息删除
    用户信息管理

    二、功能展示

    1.用户登陆

    在这里插入图片描述

    2.用户界面

    在这里插入图片描述

    3.管理员界面

    在这里插入图片描述

    4.民居信息修改

    在这里插入图片描述

    5.民居信息详情

    在这里插入图片描述

    三、系统实现

    1.ManageMainFrame.java

    package Guanliyuan;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.GraphicsConfiguration;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.HeadlessException;
    import java.awt.Image;
    import java.awt.Transparency;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import javax.imageio.ImageIO;
    import javax.swing.Box;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    /*
     * 信息录入界面
     */
    
    import Util.DbUtil;
    
    public class Xiugai extends JFrame implements ActionListener {
    
    	JTextField field1,field2,field3,field4,field5,field6;
    	Box box1,box2,box3,box4,box5,box6,box7,baseBox;
    	JButton buttonOfQueDing,buttonOfReset,buttonOfQuXIAO,buttonOfAddImg;
    	Connection con = null;
    	Statement stmt = null;
    	ResultSet rs = null;
    	JLabel jLabelImg =null;
    	BufferedImage buffimg = null;
    	ImageIcon ic;
    	Image ia, l;
    	String filepath = "";
    	String filename = "";
    	public Xiugai(String number)
    	{
    		
    		init(number);
    		setVisible(true);
    //		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(0, 0, 900, 800);
    		setTitle("民居信息修改界面");
    	}
    	void init(String number)
    	{
    		JLabel label1 = new JLabel(" 序        号  : ");
    		JLabel label2 = new JLabel(" 地        址  : ");
    		JLabel label3 = new JLabel(" 房        主  : ");
    		JLabel label4 = new JLabel("面积(平米):");
    		JLabel label5 = new JLabel(" 外       表  : ");
    		JLabel label6 = new JLabel("已住用(是/否):");
    		jLabelImg = new JLabel("", JLabel.CENTER);
    		
    		field1 = new JTextField();
    		field2 = new JTextField();
    		field3 = new JTextField();
    		field4 = new JTextField();
    		field5 = new JTextField();
    		field6 = new JTextField();
    		
    		buttonOfQueDing = new JButton("提交");
    		buttonOfReset = new JButton("重置");
    		buttonOfQuXIAO = new JButton("取消");
    		buttonOfAddImg = new JButton("添加图片");
    		buttonOfQueDing.addActionListener(this);
    		buttonOfQuXIAO.addActionListener(this);
    		buttonOfReset.addActionListener(this);
    		buttonOfAddImg.addActionListener(this);
    		
    		
    		box1 = Box.createHorizontalBox();
    		box1.add(box1.createHorizontalStrut(8));
    		box1.add(label1);
    		box1.add(box1.createHorizontalStrut(8));
    		box1.add(field1);
    		box1.add(box1.createHorizontalStrut(8));
    		
    		box2 = Box.createHorizontalBox();
    		box2.add(box2.createHorizontalStrut(8));
    		box2.add(label2);
    		box2.add(box2.createHorizontalStrut(8));
    		box2.add(field2);
    		box2.add(box2.createHorizontalStrut(8));
    		
    		box3 = Box.createHorizontalBox();
    		box3.add(box3.createHorizontalStrut(8));
    		box3.add(label3);
    		box3.add(box3.createHorizontalStrut(8));
    		box3.add(field3);
    		box3.add(box3.createHorizontalStrut(8));
    		
    		box4 = Box.createHorizontalBox();
    		box4.add(box4.createHorizontalStrut(8));
    		box4.add(label4);
    		box4.add(box4.createHorizontalStrut(8));
    		box4.add(field4);
    		box4.add(box4.createHorizontalStrut(8));
    		
    		box5 = Box.createHorizontalBox();
    		box5.add(box5.createHorizontalStrut(8));
    		box5.add(label5);
    		box5.add(box5.createHorizontalStrut(8));
    		box5.add(field5);
    		box5.add(box5.createHorizontalStrut(8));
    		
    		box6 = Box.createHorizontalBox();
    		box6.add(box6.createHorizontalStrut(8));
    		box6.add(label6);
    		box6.add(box6.createHorizontalStrut(8));
    		box6.add(field6);
    		box6.add(box6.createHorizontalStrut(8));
    				
    		box7 = Box.createHorizontalBox();
    		box7.add(box7.createHorizontalStrut(8));
    		box7.add(buttonOfAddImg);
    		box7.add(box7.createHorizontalStrut(8));
    		box7.add(buttonOfQueDing);
    		box7.add(box7.createHorizontalStrut(8));
    		box7.add(buttonOfQuXIAO);
    		box7.add(box7.createHorizontalStrut(8));
    		box7.add(buttonOfReset);
    		box7.add(box7.createHorizontalStrut(8));
    		
    		baseBox = Box.createVerticalBox();
    		baseBox.add(Box.createVerticalStrut(15));
    		baseBox.add(box1);
    		baseBox.add(Box.createVerticalStrut(10));
    		baseBox.add(box2);
    		baseBox.add(Box.createVerticalStrut(10));
    		baseBox.add(box3);
    		baseBox.add(Box.createVerticalStrut(10));
    		baseBox.add(box4);
    		baseBox.add(Box.createVerticalStrut(10));
    		baseBox.add(box5);
    		baseBox.add(Box.createVerticalStrut(10));
    		//baseBox.add(box6);
    		//baseBox.add(Box.createVerticalStrut(10));
    		JScrollPane pane = new JScrollPane(jLabelImg);
    		pane.setPreferredSize(new Dimension(300, 500));
    		baseBox.add(pane);
    		baseBox.add(Box.createVerticalStrut(10));
    		baseBox.add(box7);
    		baseBox.add(Box.createVerticalStrut(15));
    		
    		add(baseBox);
    		
    		
    		this.connDB();
    		try {
    			stmt = con.createStatement();
    			String sql = "select * from building where number='"+number+"'; ";
    			rs = stmt.executeQuery(sql);
    		} catch (SQLException e2) {
    			e2.printStackTrace();
    		}
    		String imgPath="";
    		try {			
    			if(rs.next())
    			{
    				 String num = rs.getString("number");
    				 String location = rs.getString("location");
    				 String name = rs.getString("name");
    				 String space = rs.getString("space");
    				 String color = rs.getString("color");
    				 String  img= rs.getString("img");
    				 imgPath = rs.getString("img");
    				 String username= rs.getString("username");
    				 field1.setText(num);
    				 field1.setEnabled(false);
    				 field2.setText(location);
    				 //field2.setEnabled(false);
    				 field3.setText(username);
    				 //field3.setEnabled(false);
    				 field4.setText(space);
    				 //field4.setEnabled(false);
    				 field5.setText(color);
    				 //field5.setEnabled(false);
    			}
    			else
    			{
    				JOptionPane.showMessageDialog(null,"没有此编号的民居的详细信息!");
    				new Guanliyuan(true);
    			}
    			
    		} catch (HeadlessException e2) {
    			e2.printStackTrace();
    		} catch (SQLException e2) {
    			e2.printStackTrace();
    		}
    		if(imgPath!=""&&imgPath!=null) {
    			File file3 = new File(imgPath);
    			try {
    				buffimg = ImageIO.read(file3);
    			} catch (IOException a) {
    				a.printStackTrace();
    			}
    			filename = file3.getName();
    			String cat = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
    			if (cat.equalsIgnoreCase("JPG") || cat.equalsIgnoreCase("GIF") || cat.equalsIgnoreCase("PNG")
    					|| cat.equalsIgnoreCase("JPEG")) {
    
    				ic = new ImageIcon(imgPath);
    				ia = ic.getImage();
    				int height = ic.getIconHeight();
    				int width = ic.getIconWidth();
    				jLabelImg.setSize(width, height);
    				jLabelImg.setIcon(ic);
    				repaint();
    			} else {
    				JOptionPane.showMessageDialog(null, " 该软件只支持 JPG 、GIF 、 PNG格式的图像文件 ", " 提示 ",
    						JOptionPane.INFORMATION_MESSAGE);
    			}
    		}
    	}
    	
    	
    	public void connDB() { // 连接数据库
    		try {
    			Class.forName("com.mysql.jdbc.Driver");//注册驱动
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		try {//创建连接
    			con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);
    			
    		} catch (SQLException e) {
    			e.printStackTrace();
    			
    		}
    		
    	}
    
    	public void closeDB() // 关闭连接
    	{
    		try {
    			stmt.close();
    			con.close();
    		} 
    		catch (SQLException e) {
    			e.printStackTrace();
    		}
    		
    	}
    	
    	public static boolean isNumeric(String str){
    		   for (int i = str.length();--i>=0;){   
    		    if (!Character.isDigit(str.charAt(i))){
    		     return false;
    		    }
    		   }
    		   return true;
    		  }//判断 编号输入的是不是整数!
    	
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		Object source = e.getSource();
    		String number = field1.getText();
    		String cartype = field2.getText() ;
    		String carower = field3.getText() ;
    		String price = field4.getText();
    		String color = field5.getText();
    		//String hire = field6.getText();
    //		if(field6.getText().equals("是")&&field6.getText().equals("已经")&&field6.getText().equals("已租用")&&field6.getText().equals("已"))
    //		{
    //			hire = "1";
    //		}
    //		else 
    //		{
    //			hire = "0";
    //		}
    		
    		
    		if(source == buttonOfQueDing)
    		{
    			if(number.equals("")||cartype.equals("")||carower.equals("")||price.equals("")||color.equals(""))
    			{
    				JOptionPane.showMessageDialog(null, "请填写完整!");
    			}
    			else if(!isNumeric(number))
    			{
    				JOptionPane.showMessageDialog(null, "序号 请输入整数!");
    			}
    			else
    			{
    				this.connDB();
    				try {
    					//保存图片
    			        Date date = new Date();//获取当年日期
    			        //日期格式化
    			        // SimpleDateFormat 负责日期格式化
    			        //yyyy年   MM 月 dd日 hh时  mm分 ss秒  SSS毫秒
    			        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    			        String nowTime =  sdf.format(date);//直接用format返回字符串
    			        String  path = "E:\\\\img\\\\"+nowTime;
    			        File paths = new File(path);
    			        if(!paths.exists()) {
    			        	paths.mkdirs();
    			        }
    			        String newpath = path+"\\\\"+filename;
    			        File newpaths = new File(newpath);
    			        File filepaths = new File(filepath);
    			        if (!newpaths.exists()) {
    			            try {
    							Files.copy(filepaths.toPath(), newpaths.toPath());
    						} catch (IOException e1) {
    							// TODO Auto-generated catch block
    							e1.printStackTrace();
    						}
    			        } else {
    			            newpaths.delete();
    			            try {
    							Files.copy(filepaths.toPath(), newpaths.toPath());
    						} catch (IOException e1) {
    							// TODO Auto-generated catch block
    							e1.printStackTrace();
    						}
    			        }
    
    					int numberint = Integer.parseInt(field1.getText());
    					stmt = con.createStatement();
    					newpath.replaceAll("\\\\", "/");
    					System.out.print(newpath);
    					String str = "update building set location='"+cartype+"',name='"+cartype+"',space='"+carower+"',color='"+color+"',img='"+newpath+"' where  number='"+numberint+"'";
    					System.out.print(str);
    					stmt.executeUpdate(str);
    					JOptionPane.showMessageDialog(null, "录入成功!");
    					this.closeDB();
    					this.dispose();
    					new Guanliyuan(true);
    	
    				
    				} catch (SQLException e1) {
    //				e1.printStackTrace();
    					
    				JOptionPane.showMessageDialog(null, "此编号已经被使用,请换一个编号!");
    				}
    				
    				
    			}
    			
    		}
    		else if(source == buttonOfQuXIAO)
    		{
    			this.dispose();
    			new Guanliyuan(false);
    			
    		}
    		else if(source == buttonOfReset)
    		{
    			//field1.setText("");
    			field2.setText("");
    			field3.setText("");
    			field4.setText("");
    			field5.setText("");
    			field6.setText("");
    			
    			
    		}else if(source == buttonOfAddImg) {
    			JFileChooser chooser = new JFileChooser();
    
    			if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
    				String strSelectedPath = chooser.getSelectedFile().getPath();
    				File file3 = chooser.getSelectedFile();
    				try {
    					buffimg = ImageIO.read(file3);
    				} catch (IOException a) {
    					a.printStackTrace();
    				}
    				filename = chooser.getSelectedFile().getName();
    				String cat = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
    				if (cat.equalsIgnoreCase("JPG") || cat.equalsIgnoreCase("GIF") || cat.equalsIgnoreCase("PNG")
    						|| cat.equalsIgnoreCase("JPEG")) {
    					filepath = strSelectedPath;
    					ic = new ImageIcon(filepath);
    					ia = ic.getImage();
    					int height = ic.getIconHeight();
    					int width = ic.getIconWidth();
    					jLabelImg.setSize(width, height);
    					jLabelImg.setIcon(ic);
    					repaint();
    				} else {
    					JOptionPane.showMessageDialog(null, " 该软件只支持 JPG 、GIF 、 PNG格式的图像文件 ", " 提示 ",
    							JOptionPane.INFORMATION_MESSAGE);
    				}
    			}
    		}
    		
    		
    	}
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412

    四、其它

    1.其他系统实现

    Java+Swing实现学生选课管理系统
    Java+Swing实现学校教务管理系统
    Java+Swing+sqlserver学生成绩管理系统
    Java+Swing用户信息管理系统
    Java+Swing实现的五子棋游戏
    基于JavaSwing 银行管理系统
    Java+Swing+mysql仿QQ聊天工具
    Java+Swing 聊天室
    Java+Swing+dat文件存储实现学生选课管理系统
    Java+Swing可视化图像处理软件
    Java+Swing学生信息管理系统
    Java+Swing图书管理系统
    Java+Swing图书管理系统2.0
    基于java+swing+mysql图书管理系统3.0

  • 相关阅读:
    Docker入门之安装Tomcat
    (附源码)计算机毕业设计SSM基于框架的在线问答平台
    【周报2023-11-17】
    万字逐行解析与实现Transformer,并进行德译英实战(三)
    亚商投资顾问 早餐FM/0919世界制造业大会将召开
    nginx - 使用nginx部署vue项目到本地以及代理和负载均衡
    《上海悠悠接口自动化平台》-4.注册用例集实战演示
    Ubuntu快速安装MSF命令
    TS类中初始化属性语法糖
    dns服务解析流程
  • 原文地址:https://blog.csdn.net/Timi2019/article/details/128091201