基于java+mysql的swing小区物业管理系统(java+swing+mysql+jdbc)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java的Swing小区物业管理系统(java+swing+mysql+jdbc)
启动类:StartApplication.java
管理员:
admin 123456
业主:
owner1 123456
owner2 123456
包含登录,缴费,报修,投诉,修改个人信息等
catch(SQLException eee){}
}
return true;
}
}
class Owneramend extends JDialog implements ActionListener
{
JTextField txtownerID;
JTextField txtownerName;
JRadioButton radownerSexM;
JRadioButton radownerSexF;
JTextField txtownerTel;
JTextField txtownerAddress;
ButtonGroup g;
JTextField txthouseID;
JTextField txtmoveinDate;
JTextField txtcarNumber;
JTextArea txtmemo;
//JLabel labownerPhoto;
JButton btnAdd,btnOk,btnCancel;
String fname;
Ownerdata ownerdata;
PicPanel2 pic2;
Vector vsp;
Owneramend(Ownerdata o)
{
ownerdata=o;
pic2=new PicPanel2();
Container c=this.getContentPane();
txtownerID=new JTextField(10);
txtownerID.setEditable(false);
txtownerName=new JTextField(10);
radownerSexM=new JRadioButton("男",true);
radownerSexF=new JRadioButton("女",false);
g=new ButtonGroup();
g.add(radownerSexM);
g.add(radownerSexF);
txtownerTel=new JTextField(10);
txtownerAddress=new JTextField(30);
txthouseID=new JTextField(10);
txtmoveinDate=new JTextField(10);
txtmemo=new JTextArea();
txtmemo.setLineWrap(true);
txtcarNumber=new JTextField(10);
pstmt.close();
con.close();
}
catch(SQLException ee)
{
}
}
return v;
}
public static Vector charge1all()
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;
ResultSet rs=null;
Vector v=new Vector();
if(con==null)
{
return v;
}
try
{
pstmt=con.prepareStatement("select * from charge1");
rs=pstmt.executeQuery();
while(rs.next())
{
Charge1data c1=new Charge1data(
rs.getString("ownerName"),
rs.getString("houseID"),
rs.getString("chargeName"),
rs.getString("much"),
rs.getString("money"),
rs.getString("date"),
rs.getString("receiver"));
v.addElement(c1);
}
}
catch(SQLException e)
{
e.printStackTrace();
return new Vector();
}
finally
{
try
{
Repairdata r;
String mode;
String id;
Vector vsp;
Repairadd(String mode,String id)
{
this.mode=mode;
this.id=id;
Container c=this.getContentPane();
repairID=new JTextField(10);
repairID.setEditable(false);
houseID=new JTextField(10);
repairItem=new JTextArea();
repairItem.setLineWrap(true);
repairDate=new JTextField(10);
finish=new JTextField(10);
receiver=new JTextArea();
receiver.setLineWrap(true);
btnOk=new JButton("确定");
btnCancel=new JButton("取消");
JPanel bottom=new JPanel(new FlowLayout(FlowLayout.CENTER,5,0));
JPanel center=new JPanel(new BorderLayout());
JPanel center2=new JPanel(new BorderLayout());
JPanel center3=new JPanel(new BorderLayout());
JPanel top=new JPanel(new GridLayout(2,1));
JPanel top2=new JPanel(new GridLayout(2,1));
JPanel topleft0=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel topleft1=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel topleft2=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel topleft3=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel topleft4=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel topleft5=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
topleft0.add(new JLabel("维修编号:"));
topleft0.add(repairID);
topleft1.add(new JLabel("房间编号:"));
topleft1.add(houseID);
topleft2.add(new JLabel("报修说明:"));
JScrollPane jsp=new JScrollPane(repairItem);
jsp.setPreferredSize(new Dimension(330,100));
topleft2.add(jsp);
topleft3.add(new JLabel("报修日期:"));
topleft3.add(repairDate);
topleft4.add(new JLabel("维修人员:"));
topleft4.add(finish);
topleft5.add(new JLabel("处理结果:"));
odw.setMaximum(true);
}
catch(Exception ee)
{
}
odw.setResizable(false);
back.add(odw);
odw.toFront();
}
else if(obj==item41 || obj==jb4)
{
Complainwindows cw=new Complainwindows();
cw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
cw.setMaximum(true);
}
catch(Exception ee)
{
}
cw.setResizable(false);
back.add(cw);
cw.toFront();
}
else if(obj==item42 || obj==jb3)
{
new Choose();
}
else if(obj==item43 || obj==jb5)
{
Repairwindows rw=new Repairwindows();
rw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
rw.setMaximum(true);
}
catch(Exception ee)
{
}
rw.setResizable(false);
back.add(rw);
rw.toFront();
}
else if(obj==item51 || obj==jb2)
{
Housebrowse hb=new Housebrowse();
hb.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
hb.setMaximum(true);
}
else if(obj==item31 || obj==jb1)
{
new Owneradd("add",null);
}
else if(obj==item32)
{
Owneramendwindows oaw=new Owneramendwindows();
oaw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
oaw.setMaximum(true);
}
catch(Exception ee)
{
}
oaw.setResizable(false);
back.add(oaw);
oaw.toFront();
}
else if(obj==item33)
{
Ownerdeletewindows odw=new Ownerdeletewindows();
odw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
odw.setMaximum(true);
}
catch(Exception ee)
{
}
odw.setResizable(false);
back.add(odw);
odw.toFront();
}
else if(obj==item41 || obj==jb4)
{
Complainwindows cw=new Complainwindows();
cw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
cw.setMaximum(true);
}
catch(Exception ee)
pstmt=con.prepareStatement("insert into repair(houseID,repairItem,repairDate,finish,receiver) values(?,?,?,?,?)");
pstmt.setString(1,this.houseID);
pstmt.setString(2,this.repairItem);
pstmt.setString(3,this.repairDate);
pstmt.setString(4,this.finish);
pstmt.setString(5,this.receiver);
pstmt.execute();
}
catch(SQLException e)
{
//e.printStackTrace();
return false;
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
return true;
}
public boolean delete()
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;//预处理对象
if(con==null)
{
return false;
}
try
{
pstmt=con.prepareStatement("delete from repair where repairID=?");
pstmt.setInt(1,Integer.parseInt(repairID));
pstmt.execute();
}
catch(SQLException e)
{
return false;
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
class Charge2data
{
private String houseID;
private String ownerName;
private String chargeName;
private String much;
private String money;
private String date;
private String receiver;
Charge2data()
{
}
Charge2data(String ownerName,String houseID,String chargeName,String much, String money, String date, String receiver)
{
this.ownerName = ownerName;
this.houseID = houseID;
this.chargeName = chargeName;
this.much = much;
this.money = money;
this.date = date;
this.receiver = receiver;
}
public void setOwnerName(String ownerName)
{
this.ownerName = ownerName;
}
public String getOwnerName()
{
return this.ownerName;
}
public void setHouseID(String houseID)
{
this.houseID = houseID;
}
public String getHouseID()
{
return this.houseID;
}
public void setChargeName(String chargeName)
{
this.chargeName = chargeName;
}
public String getChargeName()
{
return this.chargeName;
}
public void setMuch(String much)
{
jb5.setHorizontalTextPosition(AbstractButton.CENTER);
jb5.setVerticalTextPosition(AbstractButton.BOTTOM);
jb1.setToolTipText("业主登记"); //设置注释
jb2.setToolTipText("房屋查询");
jb3.setToolTipText("物业收费");
jb4.setToolTipText("业主投诉");
jb5.setToolTipText("业主报修");
toolbar.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
toolbar.add(jb1);
toolbar.add(jb2);
toolbar.add(jb3);
toolbar.add(jb4);
toolbar.add(jb5);
jb1.addMouseMotionListener(new task(this));
jb2.addMouseMotionListener(new task(this));
jb3.addMouseMotionListener(new task(this));
jb4.addMouseMotionListener(new task(this));
jb5.addMouseMotionListener(new task(this));
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
jb5.addActionListener(this);
c.add(toolbar,"North");
}
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==item14)
{
dispose();
System.exit(0); //如果选item14选项钮,退出
}
else if(obj==item21)
{
toolbar.setVisible(item21.isSelected()); //如果选中item21,显示工具条
}
else if(obj==item22)
{
if(item22.isSelected())
{
jb1.setText("业主登记"); //如果选中item22显示标题
jb2.setText("房屋查询");
jb3.setText("物业收费");
jb4.setText("业主投诉");
jb5.setText("业主报修");
}
else
public String getReceiver()
{
return this.receiver;
}
public static Vector charge1query(String ownerName)
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;
ResultSet rs=null;
Vector v=new Vector();
if(con==null)
{
return v;
}
try
{
pstmt=con.prepareStatement("select * from charge1 where ownerName=?");
pstmt.setString(1,ownerName);
rs=pstmt.executeQuery();
while(rs.next())
{
Charge1data c1=new Charge1data(
rs.getString("ownerName"),
rs.getString("houseID"),
rs.getString("chargeName"),
rs.getString("much"),
rs.getString("money"),
rs.getString("date"),
rs.getString("receiver"));
v.addElement(c1);
}
}
catch(SQLException e)
{
e.printStackTrace();
return new Vector();
}
finally
{
try
{
rs.close();
pstmt.close();
con.close();
}
catch(SQLException ee)
{
}
topleft.add(topleft5);
topleft.add(topleft6);
//topright.setPreferredSize(new Dimension(100,10));
topright.add(pic2,"Center");
topright.add(btnAdd,"South");
top.add(topleft);
top.add(topright);
JPanel center1=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel center3=new JPanel(new FlowLayout(FlowLayout.CENTER,5,0));
center1.add(new JLabel("户口所在地:"));
center3.add(txtownerAddress);
JPanel center2=new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
JPanel center4=new JPanel(new FlowLayout(FlowLayout.CENTER,5,0));
jsp.setPreferredSize(new Dimension(350,100));
center2.add(new JLabel(" 备 份:"));
center4.add(jsp);
JPanel center5=new JPanel(new BorderLayout());
center5.add(center1,"West");
center5.add(center3,"Center");
JPanel center6=new JPanel(new BorderLayout());
center6.add(center2,"West");
center6.add(center4,"Center");
center.add(center5,"North");
center.add(center6,"Center");
bottom.add(btnOk);
bottom.add(btnCancel);
btnOk.addActionListener(this);
btnCancel.addActionListener(this);
btnAdd.addActionListener(this);
c.add(top,"North");
c.add(center,"Center");
c.add(bottom,"South");
this.setModal(true);
this.setResizable(false);
setSize(460,450);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((screen.width-getWidth())/2,(screen.height-getHeight())/2);
setTitle("修改业主信息");
txtownerID.setText(o.getownerID());
txtownerName.setText(o.getownerName());
if(o.getownerSex().equals("男"))
radownerSexM.setSelected(true);
else
radownerSexF.setSelected(true);
txtownerTel.setText(o.getownerTel());
txtownerAddress.setText(o.getownerAddress());
txthouseID.setText(o.gethouseID());
txtmoveinDate.setText(o.getmoveinDate());
txtcarNumber.setText(o.getcarNumber());
{
dispose();
}
}
else if(e.getSource()==btnCancel)
{
dispose();
}
else
{
JFileChooser jf=new JFileChooser();
if(jf.showOpenDialog(this)==jf.APPROVE_OPTION)
{
File file=jf.getSelectedFile();
fname=file.getPath();
Image im=this.getToolkit().getImage(fname);
pic.draw(im);
}
}
}
}
class PicPanel extends JPanel
{ Image im;
MediaTracker mt;
PicPanel()
{
this.setPreferredSize(new Dimension(100,10));
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
public void paintComponent(Graphics g)
{
if(im!=null)g.drawImage(im,0,0,getWidth(),getHeight(),this);
}
void draw(Image image)
{
mt=new MediaTracker(this);
this.im=image;
mt.addImage(im,0);
try
{
mt.waitForAll();
}
catch(Exception e){}
repaint();
}
}
try
{
pstmt=con.prepareStatement("update charge3 set houseID=?,chargeName=?,much=?,money=?,date=?,receiver=? where ownerName=?");
pstmt.setString(1,this.houseID);
pstmt.setString(2,this.chargeName);
pstmt.setString(3,this.much);
pstmt.setString(4,this.money);
pstmt.setString(5,this.date);
pstmt.setString(6,this.receiver);
pstmt.setString(7,this.ownerName);
pstmt.execute();
}
catch(Exception er)
{
er.printStackTrace();
return false;
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
return true;
}
}
class Complaindata
{
private String complainID;
private String houseID;
private String complainItem;
private String complainDate;
private String finish;
private String receiver;
Complaindata()
{
}
Complaindata(String complainID,String houseID,String complainItem,String complainDate,String finish,String receiver)
{
this.complainID=complainID;
this.houseID=houseID;
this.complainItem=complainItem;
this.complainDate=complainDate;
this.finish=finish;
this.receiver=receiver;
}
public void setComplainID(String complainID)
{
item42.addActionListener(this);
item43.addActionListener(this);
item51.addActionListener(this);
item52.addActionListener(this);
item61.addActionListener(this);
item12.addMouseMotionListener(new task(this));
item13.addMouseMotionListener(new task(this));
item14.addMouseMotionListener(new task(this));
item21.addMouseMotionListener(new task(this));
item22.addMouseMotionListener(new task(this));
item30.addMouseMotionListener(new task(this));
item31.addMouseMotionListener(new task(this));
item32.addMouseMotionListener(new task(this));
item33.addMouseMotionListener(new task(this));
item41.addMouseMotionListener(new task(this));
item42.addMouseMotionListener(new task(this));
item43.addMouseMotionListener(new task(this));
item51.addMouseMotionListener(new task(this));
item52.addMouseMotionListener(new task(this));
item61.addMouseMotionListener(new task(this));
this.setJMenuBar(menubar);
}
public void createToolBar() //设置工具条
{
Container c=this.getContentPane();
toolbar=new JToolBar();
jb1=new JButton("业主登记",new ImageIcon(".\\image\\5.jpg")); //生成4个按钮
jb2=new JButton("房屋查询",new ImageIcon(".\\image\\10.jpg"));
jb3=new JButton("物业收费",new ImageIcon(".\\image\\6.jpg"));
jb4=new JButton("业主投诉",new ImageIcon(".\\image\\11.jpg"));
jb5=new JButton("业主报修",new ImageIcon(".\\image\\12.jpg"));
jb1.setHorizontalTextPosition(AbstractButton.CENTER); //设置文字在中心
jb1.setVerticalTextPosition(AbstractButton.BOTTOM); //设置位置
jb2.setHorizontalTextPosition(AbstractButton.CENTER);
jb2.setVerticalTextPosition(AbstractButton.BOTTOM);
jb3.setHorizontalTextPosition(AbstractButton.CENTER);
jb3.setVerticalTextPosition(AbstractButton.BOTTOM);
jb4.setHorizontalTextPosition(AbstractButton.CENTER);
jb4.setVerticalTextPosition(AbstractButton.BOTTOM);
jb5.setHorizontalTextPosition(AbstractButton.CENTER);
jb5.setVerticalTextPosition(AbstractButton.BOTTOM);
jb1.setToolTipText("业主登记"); //设置注释
jb2.setToolTipText("房屋查询");
jb3.setToolTipText("物业收费");
jb4.setToolTipText("业主投诉");
jb5.setToolTipText("业主报修");
toolbar.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
try
{
rw.setMaximum(true);
}
catch(Exception ee)
{
}
rw.setResizable(false);
back.add(rw);
rw.toFront();
}
else if(obj==item51 || obj==jb2)
{
Housebrowse hb=new Housebrowse();
hb.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
hb.setMaximum(true);
}
catch(Exception ee)
{
}
hb.setResizable(false);
back.add(hb);
hb.toFront();
}
else if(obj==item52)
{
Housewindows hw=new Housewindows();
hw.setMaximumSize(new Dimension(back.getWidth(),back.getHeight()));
try
{
hw.setMaximum(true);
}
catch(Exception ee)
{
}
hw.setResizable(false);
back.add(hw);
hw.toFront();
pstmt.setString(5,this.receiver);
pstmt.setString(6,this.repairID);
pstmt.execute();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
return true;
}
}
class Housedata
{
private String houseID;
private String houseingID;
private String houseUnit;
private String houseFloor;
private String houseArea;
Housedata()
{
}
Housedata(String houseID,String houseingID,String houseUnit,String houseFloor,String houseArea)
{
this.houseID=houseID;
this.houseingID=houseingID;
this.houseUnit=houseUnit;
this.houseFloor=houseFloor;
this.houseArea=houseArea;
}
public void sethouseID(String houseID)
catch(SQLException eee){}
}
return true;
}
public boolean delete()
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;//预处理对象
if(con==null)
{
return false;
}
try
{
pstmt=con.prepareStatement("delete from owner where ownerID=?");
pstmt.setInt(1,Integer.parseInt(ownerID));
pstmt.execute();
}
catch(SQLException e)
{
return false;
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
return true;
}
public boolean amend()
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;//预处理对象
if(con==null)
{
return false;
}
pstmt.setString(5,this.money);
pstmt.setString(6,this.date);
pstmt.setString(7,this.receiver);
pstmt.execute();
}
catch(SQLException e)
{
//e.printStackTrace();
return false;
}
finally
{
try
{
pstmt.close();
con.close();
}
catch(SQLException eee){}
}
return true;
}
public boolean delete()
{
Connection con=ConnectServer.connect("jdbc:odbc:yzgl","","");
PreparedStatement pstmt=null;//预处理对象
if(con==null)
{
return false;
}
try
{
pstmt=con.prepareStatement("delete from charge2 where ownerName=?");
pstmt.setString(1,ownerName);
pstmt.execute();
}
catch(SQLException e)
{
e.printStackTrace();
return false;
}
finally
{