realtormainframe.java~21~
来自「软件工程实践项目」· JAVA~21~ 代码 · 共 271 行
JAVA~21~
271 行
package homerealtysystem;
import com.borland.dbswing.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.borland.jbcl.layout.*;
import java.sql.*;
import com.borland.dx.sql.dataset.*;
import java.sql.ResultSet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.*;
import javax.swing.border.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author 刘庆
* @version 1.0
*/
public class RealtorMainFrame extends JFrame {
private JButton jButton2 = new JButton();
private QueryDataSet queryDataSet = new QueryDataSet();
private Database mydatabase = new Database();
private JPanel Search_a_house_jPanel = new JPanel();
private String[] s_QueryMode={"城市","邮编"}; //定义一数组,加载到jComboBox中
private XYLayout xYLayout1 = new XYLayout();
private JdbTable jdbTable1 = new JdbTable();
JButton jButton7 = new JButton();
JButton jButton1 = new JButton();
JTextField house_id_jtextfield = new JTextField();
JLabel jLabel2 = new JLabel();
DBbean db=new DBbean(); //实例化dbBean
ResultSet rs=null; //定义一结果集
ErrorMessage em=new ErrorMessage(); //出错处理
JScrollPane table_scroll;
TitledBorder titledBorder1;
String CurrentUser = new String();
JButton jButton10 = new JButton();
JLabel jLabel1 = new JLabel();
JButton jButton3 = new JButton();
public RealtorMainFrame(String Username) throws HeadlessException {
CurrentUser = Username;
pack();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
titledBorder1 = new TitledBorder("");
this.getContentPane().setLayout(xYLayout1);
mydatabase.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:HomeRealtySystemDB", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
queryDataSet.setReadOnly(true);
queryDataSet.setEditable(false);
queryDataSet.setEnableInsert(false);
queryDataSet.setEnableUpdate(false);
queryDataSet.setEnableDelete(false);
queryDataSet.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(mydatabase,
"SELECT 房屋信息表.\"房屋ID\",房屋信息表.\"城市\",房屋信息表.\"邮编\",房屋信息表.\"房屋描述\",房屋信息表.\"户型\",房屋信息表.\"总面积\",房屋信息表.\"售价〈每平方〉\",房屋信息表.\"所属经理人\" " +
"FROM 房屋信息表 where 所属经理人 ='" + CurrentUser + "'", null, true, Load.ALL));
jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
jdbTable1.setDataSet(queryDataSet);
jdbTable1.setEditable(false);
jButton2.setText("维护个人信息");
jButton2.addActionListener(new RealtorMainFrame_jButton2_actionAdapter(this));
jButton2.setFont(new java.awt.Font("Dialog", 0, 16));
jButton2.setToolTipText("");
Search_a_house_jPanel.setLayout(null);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setLocale(java.util.Locale.getDefault());
this.setTitle("欢迎使用");
jdbTable1.setFont(new java.awt.Font("Dialog", 0, 16));
jdbTable1.setMinimumSize(new Dimension(1000, 200));
jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
jdbTable1.setDataSet(queryDataSet);
jdbTable1.setBounds(new Rectangle(9, 16, 767, 126));
jButton7.setBounds(new Rectangle(444, 160, 173, 34));
jButton7.setFont(new java.awt.Font("Dialog", 0, 16));
jButton7.setText("删除该房产");
jButton7.addActionListener(new RealtorMainFrame_jButton7_actionAdapter(this));
xYLayout1.setWidth(807);
xYLayout1.setHeight(445);
Search_a_house_jPanel.setMaximumSize(new Dimension(33000, 33000));
jButton1.setBounds(new Rectangle(383, 258, 98, 37));
jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
jButton1.setText("退出");
jButton1.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
jButton1.addActionListener(new RealtorMainFrame_jButton1_actionAdapter(this));
house_id_jtextfield.setFont(new java.awt.Font("Dialog", 0, 16));
house_id_jtextfield.setText("");
house_id_jtextfield.setBounds(new Rectangle(253, 163, 167, 29));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel2.setText("请输入房屋编号:");
jLabel2.setBounds(new Rectangle(102, 166, 136, 28));
table_scroll = new JScrollPane(jdbTable1);
table_scroll.setBounds(new Rectangle(9, 16, 767, 126));
jButton10.setBounds(new Rectangle(249, 260, 102, 34));
jButton10.setFont(new java.awt.Font("Dialog", 0, 16));
jButton10.setMaximumSize(new Dimension(97, 31));
jButton10.setText("重新登陆");
jButton10.addActionListener(new RealtorMainFrame_jButton10_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel1.setText("我的所有房产:");
jButton3.setFont(new java.awt.Font("Dialog", 0, 16));
jButton3.setText("添加新房产");
jButton3.addActionListener(new RealtorMainFrame_jButton3_actionAdapter(this));
this.getContentPane().add(Search_a_house_jPanel, new XYConstraints(14, 128, 787, 306));
Search_a_house_jPanel.add(jdbTable1, null);
Search_a_house_jPanel.add(table_scroll,null);
this.getContentPane().add(jLabel1, new XYConstraints(37, 102, -1, 26));
this.getContentPane().add(jButton2, new XYConstraints(154, 33, 190, 42));
this.getContentPane().add(jButton3, new XYConstraints(409, 32, 188, 43));
Search_a_house_jPanel.add(jLabel2, null);
Search_a_house_jPanel.add(house_id_jtextfield, null);
Search_a_house_jPanel.add(jButton7, null);
Search_a_house_jPanel.add(jButton1, null);
Search_a_house_jPanel.add(jButton10, null);
pack();
}
void jButton1_actionPerformed(ActionEvent e) {
System.exit(0);
}
void jButton2_actionPerformed(ActionEvent e) {
GetFrmLocation gfl=new GetFrmLocation();//实例化GetFrmLocatin
RealtorInfoFrame frame=new RealtorInfoFrame(CurrentUser); //实例化下一个frame
gfl.get_location(frame); //让frame显示在屏幕中心
frame.show(); //frame的显示
this.dispose(); //本窗体的退出
}
void jButton7_actionPerformed(ActionEvent e) {
if (!em.isEmpty(house_id_jtextfield.getText())) //判断输入是否为空
{
try {
rs=db.executeQuery("select * from 房屋信息表 where 房屋信息表.\"房屋ID\"="+Long.valueOf(house_id_jtextfield.getText()));
if(!rs.next()){ //判断是否存在
JOptionPane.showMessageDialog(RealtorMainFrame.this, "数据库中没有您查询的房屋编号",
"数据库中没有您查询的房屋编号!", 1);
}
else {
db.executeQuery("delete from 房屋信息表 where 房屋信息表.\"房屋ID\"="+Long.valueOf(house_id_jtextfield.getText()));
mydatabase.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:HomeRealtySystemDB", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
queryDataSet.close();
queryDataSet.setReadOnly(true);
queryDataSet.setEditable(false);
queryDataSet.setEnableInsert(true);
queryDataSet.setEnableUpdate(true);
queryDataSet.setEnableDelete(false);
queryDataSet.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(mydatabase,
"SELECT 房屋信息表.\"房屋ID\",房屋信息表.\"城市\",房屋信息表.\"邮编\",房屋信息表.\"房屋描述\",房屋信息表.\"户型\",房屋信息表.\"总面积\",房屋信息表.\"售价〈每平方〉\",房屋信息表.\"所属经理人\" " +
"FROM 房屋信息表 where 所属经理人 ='" + CurrentUser + "'", null, true, Load.ALL));
jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
jdbTable1.setDataSet(queryDataSet);
jdbTable1.setEditable(false);
jdbTable1.setFont(new java.awt.Font("Dialog", 0, 16));
jdbTable1.setMinimumSize(new Dimension(1000, 200));
jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
jdbTable1.setDataSet(queryDataSet);
jdbTable1.setBounds(new Rectangle(9, 16, 767, 126));
// Search_a_house_jPanel.add(jdbTable1, null);
JOptionPane.showMessageDialog(null, "删除成功!");
}
}
catch (SQLException ex) { // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null) {
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
else{
JOptionPane.showMessageDialog(null, "查询不能为空,请按查询方式输入相应的查询条件");
}
}
void jButton10_actionPerformed(ActionEvent e) {
GetFrmLocation gfl=new GetFrmLocation();//实例化GetFrmLocatin
LogOn frame=new LogOn(); //实例化下一个frame
gfl.get_location(frame); //让frame显示在屏幕中心
frame.show(); //frame的显示
this.dispose(); //本窗体的退出
}
void jButton3_actionPerformed(ActionEvent e) {
GetFrmLocation gfl=new GetFrmLocation();//实例化GetFrmLocatin
AddNewHorseFrame frame=new AddNewHorseFrame(CurrentUser); //实例化下一个frame
gfl.get_location(frame); //让frame显示在屏幕中心
frame.show(); //frame的显示
this.dispose(); //本窗体的退出
}
}
class RealtorMainFrame_jButton2_actionAdapter implements java.awt.event.ActionListener {
RealtorMainFrame adaptee;
RealtorMainFrame_jButton2_actionAdapter(RealtorMainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class RealtorMainFrame_jButton7_actionAdapter implements java.awt.event.ActionListener {
RealtorMainFrame adaptee;
RealtorMainFrame_jButton7_actionAdapter(RealtorMainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton7_actionPerformed(e);
}
}
class RealtorMainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
RealtorMainFrame adaptee;
RealtorMainFrame_jButton1_actionAdapter(RealtorMainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class RealtorMainFrame_jButton10_actionAdapter implements java.awt.event.ActionListener {
RealtorMainFrame adaptee;
RealtorMainFrame_jButton10_actionAdapter(RealtorMainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton10_actionPerformed(e);
}
}
class RealtorMainFrame_jButton3_actionAdapter implements java.awt.event.ActionListener {
RealtorMainFrame adaptee;
RealtorMainFrame_jButton3_actionAdapter(RealtorMainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?