房屋中介管理系统设计说明书
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
山东建筑大学计算机科学与技术学院
程序设计实用案例选讲
大作业说明书
题目:房地产中介管理系统
课程: 程序设计实用案例选讲
院(部):计算机科学与技术
专业:网络工程
班级: 网络131
学生姓名:高雷
学号:20131113033
指导教师: 袁卫华
完成日期:2014/01/08
目录
房地产中介管理系统错误!未定义书签。
一、问题描述1
二、设计思想1
三、系统结构1
四、程序流程(或模块划分)2
五、源程序3
六、系统测试及操作界面22
结论30
参考文献322
房地产中介管理系统
一、问题描述
某房屋中介公司主要的业务包括房屋出租和二手房买卖,请编程实现“房屋中介管理系统”,具体要求如下:
一、房源基本信息管理,(房屋编号,户型(如两室一厅,三室两厅),具体地址(坐落位置),建造年月,状态(待售,待出租,已售,已出租等),价格(租金/月或售价),房主姓名,联系方式等),
请编程实现这些基本信息的增、删、改、查等操作。
二、房屋出租操作,对于所有“待出租"状态的房屋,可以执行出租操作,其状态转换为“已出租",
根据出租的月数,计算租金,并征收中介费(中介费一般等于一个月的租金);处于“已出租”状态的房屋不能执行该操作。
三、房屋出售操作,对于所有“待出售”状态的房屋,可以执行出手操作,
其状态转换为“已售”,根据房价和中介费计算方法(自己查),计算应该征收的中介费
二、设计思想
此管理系统主要实现对房源的增删改查四个主要功能,以及将数据输出保存文件。
本系统分为管理员和普通用户两个类别用户,管理员可以对房源信息的增删改查等操作,普通用户无法更改信息,可以查询信息。
另外,针对大量的用户,可以注册新的用户。
管理员在添加新的房源信息时需要确保输入每一个信息,否则会提醒管理员输入完整。
修改信息可以修改一个信息,也可以同时修改多个信息,修改成功会依次提示。
查询时主要可以通过查询户型以及房屋状态查询。
用户查询到需要的房源时通过管理员修改房源信息,并将房屋的状态改变出租或出售给用户。
三、系统结构
房地产管理系统包括7个主要类:
BuildingSystem.Java:主操作界面,登录界面、选择用户类型等信息
Admin。
java管理员登录界面
Admin1。
java管理员操作界面
RegisterException。
java用于两次密码不一致时抛异常
User。
java普通用户登录界面
User1。
java普通用户操作界面
ZhuCe。
java新用户注册
四、程序流程(或模块划分)图4-1 程序流程图
五、源程序
BuildingStystem
packagegaolei;
publicclassBuildingSystemimplementsRunnable,ActionListener{
JFramef1;
JPanelp1, p2,p3,p4;
JLabell21;
JButtonfunction1,function2,function3,function4;
JButtonend;
ThreadscollWorsThread;
booleanstopScorlling;
BuildingSystem() {
f1 = new JFrame(”-—房屋中介管理系统--");
p1 = new JPanel();
p1.setBackground(Color.white);
p1。
setLayout(new GridLayout(5,1, 5,5));
function1 = new JButton(” 【管理员登录通道】");
p1。
add(function1);
function1.setBackground(Color。
getHSBColor(100,152,188));
function1.addActionListener(this);
function2 = new JButton("【普通用户登陆通道】");
function2.setBackground(Color。
getHSBColor(100, 152,188));
p1。
add(function2);
function2。
addActionListener(this);
function3 = new JButton(" 【新用户注册】”);
p1.add(function3);
function3。
setBackground(Color。
getHSBColor(100,152,188));
function3.addActionListener(this);
function4 = new JButton(” 【系统信息】");
p1。
add(function4);
function4.setBackground(Color.getHSBColor(100,152, 188));
function4。
addActionListener(this);
end = new JButton(” 【退出程序】");
p1。
add(end);
end.setBackground(Color。
getHSBColor(100, 152, 188));
end。
addActionListener(this);
f1。
add(BorderLayout.EAST, p1);
p2 = new JPanel();
p2。
setBackground(Color.getHSBColor(100,10,255));
p2.setLayout(new GridLayout(3, 1));
JLabelempty1=newJLabel(”");
p2.add(empty1);
l21 = new JLabel(" 高雷房地产公司欢迎您O(∩_∩)O~”);
l21.setForeground(Color。
DARK_GRAY);
l21.setFont(new Font("华文行楷”,1,17));
p2.add(l21);
JLabel empty2 = new JLabel(" ”);
p2。
add(empty2);
f1。
add(BorderLayout.NORTH,p2);
p3 = new JPanel(){
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
ImageIcon icon=new ImageIcon(”F:\\Java information\\12。
png");
Image image=icon。
getImage();
g。
drawImage(image, 0,0, null);
}};
p3。
setBackground(Color.white);
JLabel nn = new JLabel(" ”);
p3.add(nn);
f1.add(BorderLayout.SOUTH, p3);
p4 = new JPanel(){
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
ImageIcon icon=new Ima geIcon(”F:\\Java information\\12。
png”);
Image image=icon。
getImage();
g.drawImage(image, 0,0, null); } };
p4.setBackground(Color。
white);
f1.add(BorderLayout.CENTER, p4);
scollWorsThread = new Thread(this);
scollWorsThread.start();
f1。
setResizable(false);
f1.setSize(470,285);
f1.setVisible(true);
f1。
setLocation(400,180);
f1.setDefaultCloseOperation(JFrame。
EXIT_ON_CLOSE);}
public void run(){
while (true){
int x = l21。
getBounds().x;
int y = l21。
getBounds()。
y;
x += 5;
l21。
setLocation(x,y);
if (x 〉420) {
x = 0;
l21.setLocation(x, y);}
try {
Thread.sleep(1000);
}catch (InterruptedException e) {}
if (stopScorlling == true) {
return;}
}}
public void actionPerformed(ActionEvent e){
try {
if (e.getSource() == function1) {
new Admin();
}else if (e.getSource()== function2){
new User();
}else if (e.getSource()== function3) {
new ZhuCe();
}else if (e。
getSource()== function4){
JOptionPane。
showMessageDialog(null,this,”系统简介”,3);
}else if (e.getSource()== end) {
System。
exit(1);}
} catch (Exception e1) {
e1。
printStackTrace();
}}
public static void main(String[]args)throws Exception{
new BuildingSystem();
}}
Admin
package gaolei;
public class BuildingSystem implements Runnable,ActionListener {
JFrame f1;
JPanel p1, p2,p3,p4;
JLabel l21;
JButton function1, function2,function3, function4;
JButton end;
Thread scollWorsThread;
boolean stopScorlling;
BuildingSystem(){
f1 = new JFrame("-—房屋中介管理系统--”);
p1 = new JPanel();
p1.setBackground(Color。
white);
p1.setLayout(new GridLayout(5,1,5, 5));
function1 = new JButton(” 【管理员登录通道】”);
p1。
add(function1);
function1。
setBackground(Color。
getHSBColor(100,152,188));
function1.addActionListener(this);
function2 = new JButton("【普通用户登陆通道】”);
function2.setBackground(Color.getHSBColor(100, 152, 188));
p1.add(function2);
function2。
addActionListener(this);
function3 = new JButton(" 【新用户注册】");
p1.add(function3);
function3.setBackground(Color.getHSBColor(100, 152,188));
function3.addActionListener(this);
function4 = new JButton(” 【系统信息】”);
p1.add(function4);
function4。
setBackground(Color.getHSBColor(100, 152, 188));
function4。
addActionListener(this);
end = new JButton(" 【退出程序】”);
p1.add(end);
end。
setBackground(Color。
getHSBColor(100,152, 188));
end.addActionListener(this);
f1.add(BorderLayout。
EAST,p1);
p2 = new JPanel();
p2。
setBackground(Color.getHSBColor(100, 10,255));
p2.setLayout(new GridLayout(3,1));
JLabel empty1 = new JLabel(" ");
p2。
add(empty1);
l21 = new JLabel(" 高雷房地产公司欢迎您O(∩_∩)O~”);
l21。
setForeground(Color。
DARK_GRAY);
l21。
setFont(new Font("华文行楷”,1,17));
p2。
add(l21);
JLabel empty2 = new JLabel(” ”);
p2。
add(empty2);
f1.add(BorderLayout.NORTH,p2);
p3 = new JPanel(){
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
ImageIcon icon=new ImageIcon(”F:\\Java information\\12.png");
Image image=icon。
getImage();
g。
drawImage(image, 0,0, null); }};
p3.setBackground(Color.white);
JLabel nn = new JLabel(" ”);
p3。
add(nn);
f1。
add(BorderLayout.SOUTH, p3);
p4 = new JPanel(){
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
ImageIcon icon=new ImageIcon("F:\\Java information\\12。
png”);
Image image=icon。
getImage();
g。
drawImage(image, 0,0, null);
}
};
p4。
setBackground(Color.white);
f1。
add(BorderLayout。
CENTER, p4)
scollWorsThread = new Thread(this);
scollWorsThread.start();
f1。
setResizable(false);
f1.setSize(470, 285);
f1.setVisible(true);
f1。
setLocation(400,180);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run() {
while (true){
int x = l21.getBounds().x;
int y = l21.getBounds().y;
x += 5;
l21.setLocation(x,y);
if (x > 420){
x = 0;
l21.setLocation(x, y);}
try {
Thread。
sleep(1000);
}catch (InterruptedException e) {}
if (stopScorlling == true){
return;
}}}
public void actionPerformed(ActionEvent e){
try {
if (e.getSource()== function1) {
new Admin();
}else if (e.getSource()== function2) {
new User();
} else if (e.getSource()== function3) {
new ZhuCe();
}else if (e.getSource()== function4){
JOptionPane。
showMessageDialog(null,this,”系统简介”, 3);
}else if (e.getSource() == end){
System.exit(1);}
} catch (Exception e1) {
e1。
printStackTrace();
}}
public static void main(String[]args) throws Exception{
new BuildingSystem();
}
}
Admin1
package gaolei;;
public class Admin1 extends JFrame implements ActionListener{
JFrame f;
JLabel jl,j2,j3,j4,j5,j6,j7,j8;
JTextField jf1,jf2,jf3,jf4,jf5,jf6,jf7,jf8;
JButton jb1,jb2,jb3,jb4,jb5,jb6,jb7,jb8;
JPanel jp1;
int id;
int m=0;
JTextArea result;
String DBDriver=”sun.jdbc。
odbc。
JdbcOdbc Driver”;
String connectionStr=”jdbc:odbc:HouseInfo1”;
Statement stmt=null,s1=null;
Connection con=null;
ResultSet rs=null;
PreparedStatement stmt1=null,stmt2=null,stmt3=null,stmt4=null;public Admin1(){
f = new JFrame("房源基本信息”);
jp1=new JPanel();
jp1.setLayout(new GridLayout(5, 2));
jl=new JLabel(”编号:”);
j2=new JLabel(”房主姓名:”);
j3=new JLabel(”联系方式:”);
j4=new JLabel("坐落位置:”);
j5=new JLabel(”建造年月:");
j6=new JLabel("价格:");
j7=new JLabel(”户型”);
j8=new JLabel(”房屋状态");
jf1=new JTextField(10);
jf2=new JTextField(10);
jf3=new JTextField(10);
jf4=new JTextField(10);
jf5=new JTextField(10);
jf6=new JTextField(10);
jf7=new JTextField(10);
jf8=new JTextField(10);
jb1=new JButton("录入");
jb2=new JButton(”修改”);
jb3=new JButton("删除”);
jb4=new JButton("查询");
jp1.add(jl);
jp1。
add(jf1);
jp1。
add(j2);
jp1.add(jf2);
jp1.add(j3);
jp1.add(jf3);
jp1。
add(j4);
jp1。
add(jf4);
jp1。
add(j5);
jp1。
add(jf5);
jp1。
add(j6);
jp1。
add(jf6);
jp1。
add(j7);
jp1。
add(jf7);
jp1.add(j8);
jp1。
add(jf8);
jp1.add(jb1);
jp1。
add(jb2);
jp1。
add(jb3);
jp1.add(jb4);
jb1。
addActionListener(this);
jb2.addActionListener(this);
jb3。
addActionListener(this);
jb4.addActionListener(this);
f。
add(BorderLayout.NORTH, jp1);
result = new JTextArea(60,100);
result。
setEditable(false);
JScrollPane jScrollPane=new JScrollPane(result);
f.add(BorderLayout.CENTER, jScrollPane);
f。
setSize(500,600);
f.setLocation(600, 80);
f。
setVisible(true);
f。
validate();}
public void insert(){
int m=0;
try{
Class。
forName(DBDriver);//加载驱动器表达式
}catch(ClassNotFoundException e1){
e1。
printStackTrace();}
String id=jf1。
getText();
String name=jf2。
getText();
String tel=jf3。
getText();
String loc=jf4.getText();
String riqi=jf5.getText();
String price=jf6.getText();
String type=jf7。
getText();
String zt=jf8。
getText();
if(!id。
equals(””)&&!name.equals(””)&&!tel。
equals("")&&!loc。
equals("")&&!riqi.equals ("”)&&!price。
equals(””)&&!type.equals(”")&&!zt.equals("")){
try{
con=DriverManager。
getConnection(connectionStr,””,””);//建立数据库连接
String sql1=”INSERT INTO house(id,name,tel,loc,riqi,price,type,zt) values (?,?,?,?,?,?,?,?)";
PreparedStatement stmt1=con.prepareStatement(sql1);
stmt1.setString(1,id);
stmt1。
setString(2,name);
stmt1.setString(3,tel);
stmt1。
setString(4,loc);
stmt1.setString(5,riqi);
stmt1。
setString(6,price);
stmt1.setString(7,type);
stmt1。
setString(8,zt);
stmt1。
execute();
stmt1。
close();
con。
close();
m=1;}
catch (SQLException e1) {
e1.printStackTrace();}}
if(m==1){
JOptionPane。
showMessageDialog(this, "信息已经成功录入”);
}
if(m==0){
JOptionPane.showMessageDialog(this,"您输入的不符合要求");}} public void xiugai(){
try{
Class。
forName(DBDriver);//加载驱动器表达式
}catch(ClassNotFoundException e1){
e1。
printStackTrace();
} int n=0;
String id=jf1。
getText();
String name=jf2.getText();
String tel=jf3.getText();
String loc=jf4.getText();
String riqi=jf5。
getText();
String price=jf6.getText();
String type=jf7.getText();
String zt=jf8。
getText();
if(!id.equals("")){
try{
con=DriverManager.getConnection(connectionStr,"",””);//建立数据库连接if(!name.equals(”")){
String sql2=”Update house set name=?where id=?";
stmt1=con。
prepareStatement(sql2);
stmt1。
setString(2,id);
stmt1.setString(1,name);
stmt1。
execute();
JOptionPane。
showMessageDialog(this,"房主姓名已经成功修改”);
}
if(!tel.equals("”)){
String sql3=”Update house set tel=? where id=?";
stmt1=con。
prepareStatement(sql3);
stmt1。
setString(2,id);
stmt1.setString(1,tel);
stmt1。
execute();
stmt1.close();
JOptionPane.showMessageDialog(this, ”联系方式已经成功修改”);
}
if(!loc。
equals("”)){
String sql3="Update house set loc=? where id=?";
stmt1=con。
prepareStatement(sql3);
stmt1.setString(2,id);
stmt1。
setString(1,loc);
stmt1。
execute();
stmt1。
close();
JOptionPane。
showMessageDialog(this,”坐落位置已经成功修改”);
}
if(!riqi。
equals(”")){
String sql3="Update house set riqi=? where id=?”;
stmt1=con.prepareStatement(sql3);
stmt1。
setString(2,id);
stmt1。
setString(1,riqi);
stmt1.execute();
stmt1。
close();
JOptionPane。
showMessageDialog(this, "建造日期已经成功修改");
}
if(!price.equals("”)){
String sql3=”Update house set price=?where id=?”;
stmt1=con。
prepareStatement(sql3);
stmt1。
setString(2,id);
stmt1。
setString(1,price);
stmt1。
execute();
stmt1。
close();
JOptionPane.showMessageDialog(this, "价格已经成功修改");
}
if(!type。
equals(””)){
String sql3=”Update house set type=? where id=?";
stmt1=con。
prepareStatement(sql3);
stmt1。
setString(2,id);
stmt1.setString(1,type);
stmt1.execute();
stmt1。
close();
JOptionPane.showMessageDialog(this,”户型已经成功修改”);
}
if(!zt。
equals("")){
String sql3="Update house set zt=?where id=?";
stmt1=con。
prepareStatement(sql3);
stmt1.setString(2,id);
stmt1。
setString(1,zt);
stmt1。
execute();
stmt1.close();
JOptionPane。
showMessageDialog(this,"房屋状态已经成功修改”);
}
con.close();
n=1;
}catch (SQLException e1){
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(n==0){
JOptionPane.showMessageDialog(this,”您输入的不符合要求");
}}
public void delete(){
int n=0;
try{
Class。
forName(DBDriver);//加载驱动器表达式
}catch(ClassNotFoundException e1){
e1.printStackTrace();}
String id=jf1。
getText();
String name=jf2。
getText();
String tel=jf3。
getText();
String loc=jf4.getText();
String riqi=jf5。
getText();
String price=jf6.getText();
String type=jf7。
getText();
String zt=jf8。
getText();
if(!id。
equals(””)||!name.equals("")||!tel。
equals("")||!loc。
equals(”")||!riqi。
equals(””)||!price。
equals(””)||!type。
equals(””)||!zt。
equals("”))
try{
con=DriverManager。
getConnection(connectionStr,"”,”");//建立数据库连接
String sql2="delete from house where id=?";
stmt1=con。
prepareStatement(sql2);
stmt1.setString(1,id);
stmt1.execute();
stmt1。
close();
con.close();
n=1;
}catch (SQLException e1){
// TODO Auto—generated catch block
e1。
printStackTrace();}
if(n==1){
JOptionPane.showMessageDialog(this, ”信息已经成功删除");}
if(n==0){
JOptionPane。
showMessageDialog(this,"对不起,您输入的信息有误,未成功删除。
”);}}
public void search(){
int n=0;
try{
Class.forName(DBDriver);//加载驱动器表达式
}catch(ClassNotFoundException e1){
e1.printStackTrace();}
String id=jf1。
getText();
String name=jf2。
getText();
String tel=jf3。
getText();
String loc=jf4.getText();
String riqi=jf5。
getText();
String price=jf6.getText();
String type=jf7.getText();
String zt=jf8.getText(); if(!id。
equals(””)||!name。
equals(”")||!tel。
equals(””)||!loc。
equals("")||!riqi.equals("”)||!price.equals(”")||!type。
equals(”")||!zt。
equals(”")) try{
con=DriverManager。
getConnection(connectionStr,"”,””);//建立数据库连接
Statement stmt=con.createStatement();
String sql="Select*fr om house where id=”;
sql=sql+"'"+id+”'";
rs=stmt.executeQuery(sql);
while(rs.next()){
String id1=rs.getString("id");
String name1=rs。
getString("name");
String tel1=rs.getString("tel”);
String loc1=rs.getString(”loc");
String riqi1=rs。
getString(”riqi");
String price1=rs.getString("price”);
String type1=rs。
getString("type");
String zt1=rs。
getString(”zt”);
String str=”房屋编号-----"+id1+"\n客户姓名——-——”+name1+”\n联系方式——---"+tel1
+"\n坐落位置—--——"+loc1+”\n建造日期———-—”+riqi1+”\n价格-—--—----"+price1+"\n户型-——--"+type1+”\n房屋状态—-—---———"+zt1;
result.append(str);
result.append("\n”);
}
JOptionPane.showMessageDialog(this,"成功查询到所需信息”);
stmt.close();
con。
close();
n=1;
}catch (SQLException e1) {
// TODO Auto-generated catch block
e1。
printStackTrace();}
if(n==0){
JOptionPane.showMessageDialog(this, "对不起,您所查询的信息不存在”);}} public static void main(String args[]){
new Admin1();}
public void actionPerformed(ActionEvent e) {
if(e。
getSource()==jb1){
insert();}
if(e。
getSource()==jb2){
xiugai();}
if(e。
getSource()==jb3){
delete();}
if(e.getSource()==jb4){
search(); } }}
RegisterException
package gaolei;
public class RegisterException extends RuntimeException{
public RegisterException() {
super("用于登录异常的情况,例如密码两次输入不一致等情况”);
}}
User
package gaolei;
public class User extends JFrame implements ActionListener{
JLabel jl1,jl2;
JTextField jf1,jf2;
JPanel jp1,jp2,jp3;
JButton jb;
String DBDriver=”sun.jdbc.odbc.JdbcOdbcDriver”;
String connecti onStr=”jdbc:odbc:NewUser";
Statement stmt=null,s1=null;
Connection con=null;
int number=0;
User(){
number=0;
setTitle(”普通用户登陆");
setLayout(new FlowLayout());
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jl1=new JLabel(”请输入账户ID:”);
jp1.add(jl1);
jf1=new JTextField(20);
jp1.add(jf1);
add(jp1);
jl2=new JLabel(”请输入密码: ”);
jp2.add(jl2);
jf2=new JTextField(20);
jp2。
add(jf2);
add(jp2);
jb=new JButton(”登陆”);
jp3.add(jb);
add(jp3);
jb。
addActionListener(this);
jf1。
addActionListener(this);
jf2.addActionListener(this);
setSize(350,200);
setLocation(300, 200);
setVisible(true);
validate();}
public void Selects(){
int m=0;
try{
Class。
forName(DBDriver);//加载驱动器
}catch(ClassNotFoundException e1){
e1。
printStackTrace();}
String id=jf1.getText();
String password=jf2。
getText();
try{
con=DriverManager.getConnection(connectionStr,””,””);
Statement stmt=con.createStatement();
ResultSet rs=null;
if(!id。
equals("”)&&!password.equals(”")){
String selectsExpression1="select * from user where id=”;
selectsExpression1=selectsExpression1+”'”+id+”'";
rs=stmt.executeQuery(selectsExpression1);
while(rs.next()){
String password1=rs.getString("password");
if(password1.equals(password)){
new User1();
m=1;
}}
if(m==0){
JOptionPane。
showMessageDialog(this,"没有该用户或者密码错误");} }else{JOptionPane。
showMessageDialog(this, "请输入完整信息!”);}
stmt。
close();
con.close();
}catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb){
Selects();
}}}
User1
package gaolei;
public class User1 extends JFrame implements ActionListener{
JFrame f;
JLabel jl,j2,j3,j4,j5,j6;
JTextField jf1,jf2,jf3,jf4,jf5,jf6;
JButton jb3,jb4,jb5,jb6,jb7,jb8;
JPanel jp1;
int id;
int m=0;
JTextArea result;
String DBDriver="sun。
jdbc。
odbc。
JdbcOdbcDriver”;
String connectionStr="jdbc:odbc:HouseInfo1”;
Statement stmt=null,s1=null;
Connection con=null;
ResultSet rs=null;
PreparedStatement stmt1=null,stmt2=null,stmt3=null,stmt4=null; public User1(){
f = new JFrame("房源信息一览”);
jp1=new JPanel();
jp1.setLayout(new GridLayout(6, 2));
jl=new JLabel(”坐落位置:”);
j2=new JLabel(”建造年月:”);
j3=new JLabel(”价格:”);
j4=new JLabel("户型:");
j5=new JLabel("状态:");
jf1=new JTextField(10);
jf2=new JTextField(10);
jf3=new JTextField(10);
jf4=new JTextField(10);
jf5=new JTextField(10);
jb3=new JButton(”输出全部文件");
jb4=new JButton("查询");
jp1.add(jl);
jp1.add(jf1);
jp1.add(j2);
jp1.add(jf2);
jp1。
add(j3);
jp1。
add(jf3);
jp1.add(j4);
jp1。
add(jf4);
jp1.add(j5);
jp1.add(jf5);
jp1.add(jb3);
jp1。
add(jb4);
jb3。
addActionListener(this);
jb4。
addActionListener(this);
jf3.addActionListener(this);
jf4.addActionListener(this);
f.add(BorderLayout。
NORTH, jp1);
result = new JTextArea(60, 100);
result.setEditable(false);
JScrollPane jScrollPane=new JScrollPane(result);
f。
add(BorderLayout。
CENTER,jScrollPane);
f.setSize(500,600);
f.setLocation(600,80);
f。
setVisible(true);
f。
validate();}
public void search(){
int n=0;
try{
Class。
forName(DBDriver);//加载驱动器表达式
}catch(ClassNotFoundException e1){
e1。
printStackTrace();}
String loc=jf1。
getText();
String riqi=jf2.getText();
String price=jf3。
getText();
String type=jf4.getText();
String zt=jf5.getText();
if(!loc。
equals("")||!riqi.equals("")||!price.equals("")||!type.equals("")||!zt.equals(”")) try{
con=DriverManager.getConnection(conn ectionStr,”","”);//建立数据库连接
Statement stmt=con。
createStatement();
String sql="Select*from house where zt=";
sql=sql+”'”+zt+”'";
rs=stmt.executeQuery(sql);
while(rs.next()){
String id1=rs.getString(”id”);
String name1=rs.getString("nam e”);
String tel1=rs。
getString(”tel”);
String loc1=rs.getString(”loc”);
String riqi1=rs。
getString("riqi”);
String price1=rs。
getString(”price”);
String type1=rs。
getString("type");
String zt1=rs。
getString("zt");
String str="房屋编号-———-"+id1+”\n客户姓名--———"+name1+”\n联系方式-———-"+tel1
+"\n坐落位置-—-——”+loc1+"\n建造日期-—-—-"+riqi1+"\n价格-——-—----”+price1+”\n户型——————--—”+type1+”\n房屋状态—--——-—--"+zt1;
result.append(str);
result.append(”\n");}
JOptionPane.showMessageDialog(this, ”成功查询到所需信息”);
stmt。
close();
con。
close();
n=1;
}catch (SQLException e1){
// TODO Auto—generated catch block
e1.printStackTrace();}
if(n==0){
JOptionPane。
showMessageDialog(this,"对不起,您所查询的信息不存在”);
}}
public void last() throws IOException{
ResultSet rs=null;
try{
Class.forName(DBDriver);//加载驱动器
}catch(ClassNotFoundException e1){
e1。
printStackTrace();}
try{
con=DriverManager.getConnection(connectionStr,"”,"”);
Statement stmt=con。
createStatement();
String sqlExpression1=”S elect *from house”;
rs=stmt。
executeQuery(sqlExpression1);
FileWriter fw=new FileWriter("F:\\Java information\\h\\数据信息.txt”);
BufferedWriter bw=new BufferedWriter(fw);
while(rs。
next()){
String id=rs。
getString("id");
String name=rs。
getString(”name”);
String tel=rs.getString("tel”);
String loc=rs.getString(”loc”);
String riqi=rs.getString("riqi”);
String price=rs.getString(”price");
String resultStr2="房屋编号—-—-—”+id+”\n客户姓名-————”+name+”\n联系方式-—--—"+tel
+"\n坐落位置-——-—"+loc+”\n建造日期-—--—"+riqi+"\n价格—-—--—--—”+price;
bw。
newLine();
bw。
write(resultStr2); }
bw。
flush();
bw.close();
JOptionPane。
showInputDialog(this, "客户信息已成功保存在文件E:/gaoleiTxt。
txt里”);
stmt.close();
con.close();
}catch (SQLException e1) {
// TODO Auto—generated catch block
e1.printStackTrace();}}
public static void main(String args[]){
new User1();}
public void actionPerformed(ActionEvent e){
if(e。
getSource()==jb3){
try {
last();
} catch (IOException e1){
// TODO Auto—generated catch block
e1.printStackTrace(); } }
if(e。
getSource()==jb4){
search(); }}}
ZhuCe
package gaolei;
public class ZhuCe extends JFrame implements ActionListener{ JFrame f;
JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
JLabel jl1,jl2,jl3,jl4,jl5,jl6;
JTextField jf1,jf2,jf3,jf4,jf5;
JButton jb,jb1,jb2;
String id,password,passwordnum,personid,tel;
String DBDriver=”sun。
jdbc.odbc.JdbcOdbcDriver";
String connectionStr=”jdbc:odbc:NewUser";
Statement stmt=null,s1=null;
Connection con=null;
ZhuCe() {
JFrame f=new JFrame();
setTitle(”--新用户注册—-”);
setLayout(new FlowLayout());
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp5=new JPanel();
jp6=new JPanel();
jp7=new JPanel();
jl1=new JLabel("请输入用户名");
jf1=new JTextField(15);
jp1。
add(jl1);
jp1.add(jf1);
add(jp1);
jl2=new JLabel("请输入密码");
jf2=new JTextField(15);
jp2。
add(jl2);
jp2。
add(jf2);
add(jp2);
jl3=new JLabel("请确认密码”);
jf3=new JTextField(15);
jp3。
add(jl3);
jp3.add(jf3);
add(jp3);
jl4=new JLabel(”请输入身份证号码”);
jf4=new JTextField(15);
jp4。
add(jl4);
jp4.add(jf4);
add(jp4);
jl5=new JLabel(”请输入联系方式");
jf5=new JTextField(15);
jp5。
add(jl5);
jp5。
add(jf5);
add(jp5);
jl6=new JLabel(”请再次检查所填信息,确保真实准确!”);
jp7。
add(jl6);
add(jp7);
jb=new JButton("确定”);
jp6。
add(jb);
jb1=new JButton("返回主界面");
jp6。
add(jb1);
add(jp6);
jf1.addActionListener(this);
jf2。
addActionListener(this);
jf3。
addActionListener(this);
jf4。
addActionListener(this);
jf5.addActionListener(this);
jb。
addActionListener(this);
jb1。
addActionListener(this);
setSize(400,400);
setLocation(300, 200);
setVisible(true);
validate();
public void Add(){
ResultSet rs=null;
try{
Class.forName(DBDriver);//加载驱动器
}catch(ClassNotFoundException e1){
e1.printStackTrace();}
int a=0;
try {
con=DriverManager。
getConnection(connectionStr,””,"”);
String sqlExpression1=”insert into user (id,password,passwordnum,personid,tel)values (?,?,?,?,?)”;
PreparedStatement pstmt1=con。
prepareStatement(sqlExpression1);
String id=jf1.getText();
String password=jf2.getText();
String passwordnum =jf3。
getText();
String personid=jf4。
getText();
String tel=jf5.getText();
if(password.equals(passwordnum)){
if(!id。
equals("")&&(!password.equals(””))&&(!passwordnum.equals("”))){
pstmt1。
setString(1, id);
pstmt1。
setString(2,password);
pstmt1.setString(3, passwordnum);
pstmt1。
setString(4,personid);
pstmt1.setString(5,tel);
JOptionPane.showMessageDialog(this,”恭喜,注册成功!您的登陆账号是——"+id);
}else{
JOptionPane。
showMessageDialog(this,"您输入的不符合要求!”);}
}else{
JOptionPane。
showMessageDialog(this,"两次密码不一致!");
throw new RegisterException();}
jf1。
setText("”);
jf2.setText(”");
jf3.setText("");
jf4.setText(”");
jf5。
setText(””);
pstmt1.execute();
pstmt1.close();
con。
close();
}catch (SQLException e1){
// TODO Auto—generated catch block
e1.printStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb){
Add();
}
if(e。
getSource()==jb1){
new BuildingSystem();
}
jf1.setText(””);
jf2.setText("");
jf3.setText(”");
jf4。
setText(”");
jf5。
setText("");}}
六、系统测试及操作界面
图6-1【系统主界面】
图6—2【管理员登录界面】
图6—3【输入管理员id与密码】
图6—4【填写房源基本信息】
图6-5【录入成功】
图6-6【修改价格】
图6-7【成功修改】
图6-8【查询成功】
图6—9 【查询结果显示】
图6-10 【如不存在,提示窗口】
图6—11 【删除信息】
图6—12【新用户注册界面】
图6-13 【填写用户注册信息】
图6-14【注册成功,发放账号】
图6-15【如密码不一致】
图6-16 【普通用户登录界面】
图6-17【查询信息】
图6-18【提示成功查询】
图6-19【将数据保存为文件】
图6—20【数据信息】
图6-21【系统简介】
结论
本次java程序设计是上大学以来第一次完成这么大的一个程序,从开始到结束感触颇多。
由一开始的不知如何下手,到最后独立完成整个程序。
每天都在进步,每天都在成长。
在此期间,遇到大大小小各种问题无数个,有问过老师,自己查阅过资料,百度过经验,还有自己各种琢磨思考.其实,自己想想的话,就是因为这些错误与不会,才会让我进步。
弄完之后想要把自己的界面更加好看一些,自己去网上搜索了插入图片的方法,又去网上看了看真正的操作系统是什么样的,虽然比不上人家,但是自己其实也在一点一滴进步着,从刚开始做的时候什么也不懂,跑去问别人,到做完后有很多人前来问我,给人家讲解的时候,进步显而易见。
这次课程设计让我更加清楚的知道了:
空指针异常是因为没有定义对象就直接使用造成的错误;
图形界面设计可以按实际情况选择分布方式;
数据库里的表不能用表内的关键字做定义,不然这个错误系统也检测不出来;
对于时期还有货币等数字问题,是十分容易报错的,所以统一设置成文本比较方便;
在查询,修改的时候不能一起定义多条语句;
当然还有各种各样丢人的小错误,也使我认识到了编程的缜密性。
也许一个字母,一个空格,一个标点都会让程序员愁上几天。
我们应该在敲代码的时候养成细心的好习惯。
总之,这次程序设计真的让我收获很多!
参考文献
1、RFC 2616 — Hypertext Transfer Protocol -- HTTP/1。
1
2、RFC 1866 - Hypertext Markup Language — 2。
0
3、RFC 2854 —The ’text/html' Media Type
4、《Java实例入门》刘勇,中国青年出版社, 2002-01—01
5、《Java程序设计与案例》刘宝林;高等教育出版社
6、Java TCP/IP Socket编程(原书第2版)机械工业,(美)卡尔弗特,周恒民译。