基于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.其他系统实现

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五星资源

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值