文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

怎么用java实现一个简单的房屋管理程序

2023-06-03 03:38

关注

这篇文章主要介绍了怎么用java实现一个简单的房屋管理程序,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。


public class ApplicationInfo {
 
  private String name = null;
  private String age = null;
  private String length_service = null;
  private String head_name = null;
  private String post = null;
  private String population = null ;
  private String grade = null;
  private String apply_type = null;
 
  public ApplicationInfo(){
  }
 
 
 
  public void setAllAttribute(String result[]){
  name = result[0];
  age = result[1];
  length_service = result[2];
  head_name = result[3];
  post = result[4];
  population = result[5];
  grade = result[6];
  apply_type = result[7];
  }

 
 
  public String getApplyType(){
  return apply_type;
  }
 
  public String getName(){
  return name;
  }
  public String getAge(){
  return age;
  }
 
  public String getLengthService(){
  return length_service;
  }
 
  public String getPost(){
  return post;
  }
 
  public String getHeadName(){
  return head_name;
  }
 
  public String getPopulation(){
  return population;
  }
 
  public String getGrade(){
  return grade;
  }
 }
////////////////////////////////////////////////////////


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

public class BarChartInfo  extends JPanel {
 
  private static final int SCALE = 2;
  private static final int CHARTCOUNT = 3;
  private static final int BARSPACING  = 20;
  private static final String  CHARTTITEL = "HouseNumberGraphics";
  private static final Font CURRENTFONT= new Font("Courier",Font.BOLD,12);
  private static FontMetrics  cfm ;
 
  private static int MAXLABELWIDTH  = 0;
  private static int BARWIDTH  = 0;
  private static int MAX = 0;
 
  private int values[];
  private  Color colors[];
  private  String  labels[];

  public BarChartInfo (int valueInfo[]){
 
  cfm = getFontMetrics(CURRENTFONT);
 
  values = new int[CHARTCOUNT];
 colors = new Color[CHARTCOUNT];
 labels = new String[CHARTCOUNT];
 
 colors[0] = Color.red;
  colors[1] = Color.green;
 colors[2] = Color.blue;
 
  for (int i=0;i<CHARTCOUNT; i++){
  values[i] = valueInfo[i];
  if (values[i]> MAX) {
 MAX = values[i];
  }
  labels[0] = "RemainHouseNumber:";
  labels[1] = "DistributeHouseNumber:";
  labels[2] = "AllHouseNumber:";
 
 
  MAXLABELWIDTH = Math.max(cfm.stringWidth(labels[i]),
  MAXLABELWIDTH);
 }
 
  BARWIDTH = CURRENTFONT.getSize();
 setSize(Math.max((MAX*SCALE),
  cfm.stringWidth(CHARTTITEL))+MAXLABELWIDTH+5,
  (CHARTCOUNT*(BARWIDTH+BARSPACING))+CURRENTFONT.getSize()+10);
 
  }

  public void update(Graphics g){
  g.clearRect(0,0,getWidth(),getHeight());
  paintComponent(g);
  }

 
  public void paintComponent(Graphics g){
  super.paintComponent(g);
  Graphics2D g2D = (Graphics2D)g;
  g2D.setFont(CURRENTFONT);
 
  g2D.setColor(Color.black);
 
  int i,cx,cy;
  i = cfm.stringWidth(CHARTTITEL);
  for (i = 0;i < CHARTCOUNT ; i++) {
    cy = ((BARWIDTH + BARSPACING) * i) + BARSPACING;
  cx = MAXLABELWIDTH + 1;
  cx += Math.max((getWidth()-(MAXLABELWIDTH + 1 +(MAX*SCALE)))/2,0);
  g2D.setColor(Color.black); 
  g2D.drawString(labels[i],cx -MAXLABELWIDTH-1,
  cy + cfm.getAscent());
  g2D.fillRect(cx+3,cy+5,(values[i]*SCALE),BARWIDTH);
  g2D.setColor(colors[i]);
  g2D.fillRect(cx,cy,(values[i]*SCALE),BARWIDTH);
  g2D.drawString(""+values[i],cx+(values[i]*SCALE)+3,
  cy + cfm.getAscent());
  }
  }
 }

///////////////////////////////////////////

import java.io.*;

public class CreateApplyQueueFile extends Thread {
 private boolean isOver;
 private StringBuffer buffer;
 
 public CreateApplyQueueFile(StringBuffer buffer){
  isOver = false;
  this.buffer = buffer;
 }
 
 public void run(){
  try {
  PrintWriter out= new PrintWriter(
  new BufferedWriter(
  new FileWriter("house.tmp",true)),true);
  out.println(buffer);
  out.close();
  }
  catch(Exception e){e.printStackTrace();}
  isOver = true;
 }
 
 public boolean isOver(){
  return isOver;
 }
 
}

/////////////////////////////////////

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;

public class DistributeHouse extends Thread {
 private Vector houseInfoVector ;
 private Vector applyVector ;
 private Connection connection;
 private StringBuffer resultBuffer;
 private JTextArea textArea;
 
 public DistributeHouse(Connection connection,JTextArea textArea){
  resultBuffer = new StringBuffer();
  houseInfoVector = new Vector();
  applyVector = new Vector();
  this.connection = connection;
  this.textArea = textArea;
 }
 
 public void run(){
  LoadApplyQueueFile();
  distributeHouse();
 }
 
 
 
 private synchronized void LoadApplyQueueFile(){
  try { BufferedReader reader = new BufferedReader(
  new FileReader("house.tmp"));
  String s = null;
  while((s = reader.readLine())!=null){
  ApplicationInfo applyInfo = new ApplicationInfo();
  StringTokenizer stk = new StringTokenizer(s);
  String result[] = new String[8];
  int i=0;
  while(stk.hasMoreElements()){
  result[i] = stk.nextToken("*");
  i++;
  }
  applyInfo.setAllAttribute(result);
  applyVector.addElement(applyInfo);
  }
  reader.close(); 
  }
  catch(Exception e){e.printStackTrace();}
 }
 
 
 
 private synchronized void DeleteApplyQueueFile(){
  try{
  FileOutputStream fos = new FileOutputStream("house.tmp");
  fos.close();
  }
  catch(Exception e){e.printStackTrace();}
 }

 
 
 private synchronized void distributeHouse(){
  VacantHouseInfo info = null;
  while(!applyVector.isEmpty()){
  ApplicationInfo applyInfo = (ApplicationInfo)applyVector.elementAt(0);
  String grade = getGrade(applyInfo);
  int accordHouseNum = getVacantHouseInfo(grade);
  int randomIndex = (int)(accordHouseNum*Math.random());
  info = (VacantHouseInfo)houseInfoVector.elementAt(randomIndex);
  updateRentFile(info,applyInfo);
  updateLodgingHouseFile(info,applyInfo);
  updateVacantHouseFile(info);
  displayResult(info,applyInfo);
  applyVector.remove(0);
  houseInfoVector.removeAllElements();
  }
  DeleteApplyQueueFile();
  }
 
 
 
 private synchronized int getVacantHouseInfo(String houseGrade){
  int value = -1;
  try{ 
  PreparedStatement Stmt = connection.prepareStatement(
  "select * FROM 空房文件 WHERE 房屋等级 = +
  houseGrade + ");
  ResultSet result = Stmt.executeQuery();
  ResultSetMetaData metadata = result.getMetaData();
  String houseInfo[] = new String[5];
  while (result.next()) {
  for(int i=1;i<=metadata.getColumnCount();i++){
  houseInfo[i-1] = result.getString(i);
  }
  VacantHouseInfo vacantHouseInfo = new VacantHouseInfo();
  vacantHouseInfo.setAllAttribute(houseInfo);
  houseInfoVector.addElement(vacantHouseInfo);
  value = houseInfoVector.size();
  }
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  return value;
  }
 
 
 private synchronized void updateLodgingHouseFile(VacantHouseInfo info,ApplicationInfo applyInfo){
  try {  PreparedStatement Stmt = connection.prepareStatement("INSERT INTO 住房文件 VALUES(?,?,?,?,?,?)");
  Stmt.setString(1,info.getHouseNumber());
  Stmt.setString(2,applyInfo.getName());
  Stmt.setString(3,info.getHouseGrade());
  Stmt.setString(4,info.getHouseRent());
  Stmt.setString(5,info.getHouseArea());
  Stmt.setString(6,info.getHouseStructure());
  Stmt.executeUpdate();
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
 }
 
 
 private synchronized void updateRentFile(VacantHouseInfo info,ApplicationInfo applyInfo){
  try {  String s = caculateRent(info);
  PreparedStatement Stmt = connection.prepareStatement("INSERT INTO 房租文件 VALUES(?,?,?,?)");
  Stmt.setString(1,info.getHouseNumber());
  Stmt.setString(2,applyInfo.getName());
  Stmt.setString(3,info.getHouseGrade());
  Stmt.setString(4,s);
  Stmt.executeUpdate();
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
 }
 
 
 private synchronized void updateVacantHouseFile(VacantHouseInfo info){
  try { Statement Stmt = connection.createStatement();
  Stmt.execute("DELETE FROM 空房文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.execute("DELETE FROM 空房文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
  }
 
 
 
 private synchronized int getInteger(String s){
  StringBuffer buffer = new StringBuffer();
  for(int i=0;i<s.length();i++){
  if((int)s.charAt(i)>=48&&(int)s.charAt(i)<=57){
  buffer.append(s.charAt(i));
  }
  }
  return Integer.parseInt(buffer.toString());
  }
 
 
 
 private synchronized String caculateRent(VacantHouseInfo info){
  int area = getInteger(info.getHouseArea()); 
  int rent = getInteger(info.getHouseRent());
  int sum = area*rent;
  Integer integer = null;
  if(sum>0)integer =new Integer(sum);
  String s = integer.toString()+"元";
  return s;
 }
 
 
 
 private synchronized String getGrade(ApplicationInfo applyInfo){
  return applyInfo.getGrade();
  }
 
 
 
 private synchronized void displayResult(VacantHouseInfo info ,ApplicationInfo applyInfo){
  String rent = caculateRent(info);
  String number = info.getHouseNumber();
  String name = applyInfo.getName();
  String grade = info.getHouseGrade();
  String perRent = info.getHouseRent();
  String area = info.getHouseArea();
  String structure = info.getHouseStructure();
 
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  resultBuffer.append("姓名 :"+name+"n");
  resultBuffer.append("分配房屋号码 :"+number+"n");
  resultBuffer.append("分配房屋等级 :"+grade+"n");
  resultBuffer.append("分配房屋面积(平方米) :"+area+"n");
  resultBuffer.append("分配房屋的结构 :"+structure+"n");
  resultBuffer.append("分配房屋房租(每平方米/元) :"+perRent+"n");
  resultBuffer.append("本月应缴房租(元) :"+rent+"n");
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  textArea.append(resultBuffer.toString());
  resultBuffer.setLength(0);
 }
 
}

///////////////////////////////////


import java.sql.*;

public class MasterHouseInfo  {
 private Connection connection;
 private int valueInfo[] = new int[3];
 
 public MasterHouseInfo(Connection connection){
 this.connection = connection;
 }
 
 public int[] execute(){
  valueInfo[0] = getVacantResultCount();
  valueInfo[1] = getHouseResultCount();
  valueInfo[2] = valueInfo[0]+valueInfo[1];
  return valueInfo;
 }
 
 private synchronized int getVacantResultCount(){
  int Count = 0 ;
  try{
  PreparedStatement Stmt = connection.prepareStatement("SELECT COUNT(*) FROM 空房文件");
  ResultSet result = Stmt.executeQuery();
  ResultSetMetaData metadata = result.getMetaData();
  while (result.next()) {
  Count = result.getInt(1);
  }
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  return Count ;
  }

 private synchronized int getHouseResultCount(){
  int Count = 0; 
  try{
  PreparedStatement Stmt = connection.prepareStatement("SELECT COUNT(*) FROM 住房文件");
  ResultSet result = Stmt.executeQuery();
  ResultSetMetaData metadata = result.getMetaData();
  while (result.next()) {
  Count = result.getInt(1);
  }
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  return Count ;
  }
 }


///////////////////////////////////////


import java.sql.*;
import javax.swing.*;

public class PrepareHouse extends Thread {
 private Connection connection;
 private String houseNumber = null;
 private JTextArea textArea;
 
 public PrepareHouse(Connection connection,String houseNumber,
  JTextArea textArea){
  this.connection = connection;
  this.houseNumber = houseNumber;
  this.textArea  = textArea;
 }
 
 public void run(){
  prepareHouse();
 }
 
 public void prepareHouse(){
  new DistributeHouse(connection,textArea).start();
  new QuiteHouse(connection,houseNumber,textArea).start();
  textArea.append("**********调房成功!************");
 }
}

/////////////////////////////////

import java.sql.*;
import javax.swing.*;

public class QueryHouseInfo extends Thread {
 private Connection connection;
 private StringBuffer resultBuffer;
 private String query ;
 private JTextArea textArea;
 private String info[];
 
 public QueryHouseInfo(Connection connection,String query,
  String info[],JTextArea textArea){
  this.query = query;
  resultBuffer = new StringBuffer();
  this.connection = connection;
  this.textArea = textArea;
  this.info = info ;
 }

 public void run(){
  if(info == null)
  queryHouseInfo(query);
  else
  queryHouseInfo();
  displayResult(resultBuffer);
 }
 
 
 private synchronized void queryHouseInfo(String tableName){
  try{
  PreparedStatement Stmt = connection.prepareStatement("SELECT * FROM "+tableName);
  ResultSet result = Stmt.executeQuery();
  ResultSetMetaData metadata = result.getMetaData();
  while (result.next()) {
  for(int i=1;i<=metadata.getColumnCount();i++){
  String label = metadata.getColumnLabel(i);
  String info = result.getString(i);
  resultBuffer.append(label+":"+info+"n");
  }
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  }
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  }


 private synchronized void queryHouseInfo(){
  try{
  PreparedStatement Stmt = connection.prepareStatement(
  "SELECT "+query+" FROM "+info[2]+" WHERE "+
  info[0]+"=+
  info[1]+");
  ResultSet result = Stmt.executeQuery();
  ResultSetMetaData metadata = result.getMetaData();
  while (result.next()) {
  for(int i=1;i<=metadata.getColumnCount();i++){
  String label = metadata.getColumnLabel(i);
  String info = result.getString(i);
  resultBuffer.append(label+":"+info+"n");
  }
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  }
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  }
 
  private synchronized String getGrade(ApplicationInfo applyInfo){
  return applyInfo.getGrade();
  }

 private synchronized void displayResult(StringBuffer tmp){
  StringBuffer buffer = new StringBuffer();
  buffer.append(tmp.toString());
  textArea.append(buffer.toString());
  resultBuffer.setLength(0);
 }
}

///////////////////////////////////////


import java.sql.*;
import java.util.*;
import javax.swing.*;

public class QuiteHouse extends Thread {
  private Connection connection;
  private String houseNumber = null;
  private StringBuffer resultBuffer;
  private JTextArea textArea;
  private String name = null;
 
  public QuiteHouse(Connection connection,String houseNumber,
  JTextArea textArea){
  this.connection = connection;
  this.houseNumber = houseNumber;
  resultBuffer = new StringBuffer();
  this.textArea = textArea;;
  }
 
  public void run(){
  VacantHouseInfo info = getQuiteHouseInfo();
  updateVacantHouseFile(info);
  updateLodgingHouseFile(info);
  updateRentFile(info);
  displayResult(info);
  }
 


  public synchronized VacantHouseInfo getQuiteHouseInfo(){
  VacantHouseInfo vacantHouseInfo = null;
  try{
  Statement Stmt = connection.createStatement();
  ResultSet result = Stmt.executeQuery("SELECT * FROM 住房文件 WHERE 房号 = +
  houseNumber+");
  ResultSetMetaData metadata = result.getMetaData();
  String houseInfo[] = new String[5];
  while (result.next()) {
  for(int i=3;i<= metadata.getColumnCount();i++){
  houseInfo[i-2] = result.getString(i);
  }
  name = result.getString(2);
  }
  houseInfo[0] = houseNumber;
  vacantHouseInfo = new VacantHouseInfo();
  vacantHouseInfo.setAllAttribute(houseInfo);
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  return vacantHouseInfo ;
 }
 
 
 private synchronized  void updateRentFile(VacantHouseInfo info){
  try { Statement Stmt = connection.createStatement();
  Stmt.execute("DELETE FROM 房租文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.execute("DELETE FROM 房租文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
  }

 
 private synchronized  void updateVacantHouseFile(VacantHouseInfo info){
  try { PreparedStatement Stmt = connection.prepareStatement("INSERT INTO 空房文件 VALUES(?,?,?,?,?)");
  Stmt.setString(1,info.getHouseNumber());
  Stmt.setString(2,info.getHouseGrade());
  Stmt.setString(3,info.getHouseRent());
  Stmt.setString(4,info.getHouseArea());
  Stmt.setString(5,info.getHouseStructure());
  Stmt.executeUpdate();
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
  }
 
 
 private synchronized void updateLodgingHouseFile(final VacantHouseInfo info){
  try{  Statement Stmt = connection.createStatement();
  Stmt.execute("DELETE FROM 住房文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.execute("DELETE FROM 住房文件 WHERE 房号 = "+"+
  info.getHouseNumber()+");
  Stmt.close();
  }
  catch (Exception e) {e.printStackTrace();}
 }
 
 
 private synchronized void displayResult(VacantHouseInfo info){
 
  String number = info.getHouseNumber();
  String grade = info.getHouseGrade();
  String perRent = info.getHouseRent();
  String area = info.getHouseArea();
  String structure = info.getHouseStructure();
 
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  resultBuffer.append("退屋者姓名:"+name+"n");
  resultBuffer.append("所退房屋号码:"+number+"n");
  resultBuffer.append("所退房屋等级:"+grade+"n");
  resultBuffer.append("所退房屋面积(平方米):"+area+"n");
  resultBuffer.append("所退房屋结构:"+structure+"n");
  resultBuffer.append("所退房屋单位面积房租(每平方米/元):"+perRent+"n");
  resultBuffer.append(name+"退屋成功!"+"n");
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  textArea.append(resultBuffer.toString());
  resultBuffer.setLength(0);
 }
}

/////////////////////////////////////////

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;

public class UpdateHouseInfoPanel extends JFrame {
 
  private JButton referButton = new JButton("提及更新信息");
  private JButton reEditButton = new JButton("重填更新信息");
  private JButton updateButton = new JButton("执行更新");
 
  private JCheckBox  grade = new JCheckBox("房屋等级");
  private JCheckBox area = new JCheckBox("房屋面积");
  private JCheckBox rent = new JCheckBox("单位面积房租");
  private JCheckBox structure = new JCheckBox("房屋结构");

  private JTextField  textfiled = new JTextField();
  private JTextField  gradeinfo = new JTextField();
  private JTextField  areainfo = new JTextField();
  private JTextField  rentinfo = new JTextField();
  private JTextField  structureinfo = new JTextField();
 
  private JTextArea textArea ;
  private JComboBox comBox = new JComboBox();
 
  private String itemText ;
  private StringBuffer buffer;
  private Connection connection;

 public UpdateHouseInfoPanel(Connection connection){
  super("管理员更改房屋信息演示");
  buffer = new StringBuffer();
  this.connection = connection;
  getContentPane().setLayout(new BorderLayout());
 getContentPane().add(createPanel(),BorderLayout.CENTER);
  setSize(500,520);
  center(this);
  pack();
  setResizable(false);
  setVisible(true);
  }
 
  public void center(Component C) {
  Dimension SS = C.getToolkit().getScreenSize();
  C.setLocation ((SS.width - 750) / 2,(SS.height - 500) / 2);
  }

 private JPanel createPanel(){
  JPanel mainPanel = new JPanel();
  mainPanel.setLayout(new GridLayout(2,0,5,5));
 
  JPanel p = new JPanel(new DialogLayout2(100,5));
  JPanel rl = new JPanel(new GridLayout(0,2,5,5));
 
  JPanel pr = new JPanel();
  pr.setLayout(new DialogLayout2(100,5));
  pr.add(new DialogSeparator("用户查询信息表"));

  JPanel panel = new JPanel(new GridLayout(0,4));
  comBox.addItem("房号");
  comBox.addItem("房屋等级");
  panel.add(new JLabel("选择更新条件:"));
  panel.add(comBox);
  panel.add(new JLabel("房号/等级:"));
  panel.add(textfiled);

  pr.add(panel);
  pr.add(new JLabel("更改房屋等级为:"));
  pr.add(gradeinfo);
  pr.add(new JLabel("更改房屋面级为:"));
  pr.add(areainfo);
  pr.add(new JLabel("更改单位房租为:"));
  pr.add(rentinfo);
  pr.add(new JLabel("更改房屋结构为:"));
  pr.add(structureinfo);

  JPanel pl = new JPanel();
  pl.setBorder(new TitledBorder(new EtchedBorder(),"选择需要查询的信息"));
 
  JPanel checkPanel = new JPanel();
  checkPanel.add(grade);
  checkPanel.add(area);
  checkPanel.add(rent);
  checkPanel.add(structure);
 
  pl.add(checkPanel);

  rl.add(pr);
  rl.add(pl);
 
  p.add(rl);
  p.add(new DialogSeparator("操作"));
  p.add(referButton);
  p.add(reEditButton);
  p.add(updateButton);
 
  textArea = new JTextArea();
  JScrollPane sp = new JScrollPane( textArea );
  mainPanel.add(p);
  mainPanel.add(sp);
 
  gradeinfo.setEditable(false);
  areainfo.setEditable(false);
  rentinfo.setEditable(false);
  structureinfo.setEditable(false);
 
  ButtonListener listener = new ButtonListener() ;
  referButton.addActionListener(listener);
  reEditButton.addActionListener(listener);
  updateButton.addActionListener(listener);
 
  CheckBoxListener checklistener = new CheckBoxListener();
  grade.addActionListener(checklistener);
  area.addActionListener(checklistener);
  rent.addActionListener(checklistener);
  structure.addActionListener(checklistener);
  comBox.addActionListener(new ComboBoxListener());
 
  return mainPanel;
  }

 private void getUpdateInfo(){
  if(grade.isSelected()){
  buffer.append("房屋等级=");
  buffer.append("+gradeinfo.getText()+"+",");
  }
  if(area.isSelected()){
  buffer.append("房屋面积=");
  buffer.append("+areainfo.getText()+"+",");
  }
  if(rent.isSelected()){
  buffer.append("单位面积房租=");
  buffer.append("+rentinfo.getText()+"+",");
  }
  if(structure.isSelected()){
  buffer.append("房屋结构=");
  buffer.append("+structureinfo.getText()+"+",");
  }
 }
 
  private void reEditApplyType(){
  gradeinfo.setText(null);
  areainfo.setText(null);
  rentinfo.setText(null);
  structureinfo.setText(null);
  textfiled.setText(null);
 
  itemText = null;
 
  gradeinfo.setEditable(false);
  areainfo.setEditable(false);
  rentinfo.setEditable(false);
  structureinfo.setEditable(false);

  grade.setSelected(false);
  area.setSelected(false);
  rent.setSelected(false);
  structure.setSelected(false);
  buffer.setLength(0);
  }

  class ButtonListener implements ActionListener {
  public void actionPerformed (ActionEvent ae) {
  object obj = ae.getsource();
  if (obj == updateButton) {
  SwingUtilities.invokeLater(new Runnable() {
  public void run() {
  buffer.deleteCharAt(buffer.length()-1) ;
  new UpdateHouseInfo(buffer.toString()).start();
  }
  });
  }
  else if (obj == referButton) {
  SwingUtilities.invokeLater(new Runnable() {
  public void run() {
  getUpdateInfo();
  }
  });
  }

  else if (obj == reEditButton){
  SwingUtilities.invokeLater(new Runnable() {
  public void run() {
  reEditApplyType();
  }
  });
  }
  }
  }

 class CheckBoxListener implements ActionListener {
  public void actionPerformed (ActionEvent ae) {
  Object obj = ae.getSource();
  if (obj == grade) {
  if(grade.isSelected())
  gradeinfo.setEditable(true);
  else
  gradeinfo.setEditable(false);
  }
  else if (obj == area){
  if(area.isSelected())
  areainfo.setEditable(true);
  else
  areainfo.setEditable(false);
  }
  else if (obj == rent){
  if(rent.isSelected())
  rentinfo.setEditable(true);
  else
  rentinfo.setEditable(false);

  }
  else if (obj == structure){
  if(structure.isSelected())
  structureinfo.setEditable(true);
  else
  structureinfo.setEditable(false);
  }
  }
  }

 class ComboBoxListener implements ActionListener {
  public void actionPerformed (ActionEvent ae) {
  itemText = comBox.getSelectedItem().toString();
  }
  }

 class UpdateHouseInfo extends Thread {
  private String query ;
 
  public UpdateHouseInfo(String query){
  this.query = query;
  }
  public void run(){
  updateHouseInfo();
  }
 
  private void updateHouseInfo(){
  StringBuffer resultBuffer = new StringBuffer();
  try{
  Statement Stmt = connection.createStatement(); 
 
  Stmt.executeUpdate("UPDATE 空房文件 SET "+query+" WHERE "+itemText+"=+
  textfiled.getText()+");
  ResultSet result = Stmt.executeQuery("SELECT * "+"FROM 空房文件 WHERE "+itemText+"=+
  textfiled.getText()+");
  ResultSetMetaData metadata = result.getMetaData();
  while (result.next()) {
  for(int i=1;i<=metadata.getColumnCount();i++){
  String label = metadata.getColumnLabel(i);
  String info = result.getString(i);
  resultBuffer.append(label+":"+info+"n");
  }
  }
  resultBuffer.append("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"+"n");
  textArea.append("更新成功!!"+"n");
  textArea.append(resultBuffer.toString());
  Stmt.close();
  }
  catch(Exception e){e.printStackTrace();}
  }
 }
}
//////////////////////////////////



public class VacantHouseInfo {
 
 private String house_number = null;
 private String house_grade = null;
 private String house_area = null;
 private String house_rent = null;
 private String house_structure = null;
 
 public VacantHouseInfo(){
 }
 
 public void setAllAttribute(String houseInfo[]){
  house_number = houseInfo[0];
  house_grade = houseInfo[1];
  house_area = houseInfo[2];
  house_rent = houseInfo[3];
  house_structure = houseInfo[4];
 }
 
 public String getHouseNumber(){
  return house_number;
 }
 
 public String getHouseGrade(){
  return house_grade;
 }
 
 public String getHouseArea(){
  return house_area;
 }
 
 public String getHouseRent(){
  return house_rent;
 }
 
 public String getHouseStructure(){
  return house_structure;
 }
}
/////////////////////

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.* ;

public class TrySql extends JFrame {
  private static Connection connection ;
 
  public TrySql() {
  initializeDemo();
  }
 
 public static void initConnection(){
  try{
  connection = getConnection();
  }
 catch(Exception e){e.printStackTrace();}
  }
 
 public void diSCOnnection(){
  try{
  connection.close();
  }
 catch(Exception e){e.printStackTrace();}
 clearMemory();
 }
 
 public void initializeDemo(){
  addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  disConnection();
  System.exit(0);
  }
  });
 
  JMenu fileMenu = new JMenu("文件");
  JMenuItem exitItem = new JMenuItem("退出");
  fileMenu.add(exitItem);
  exitItem.addActionListener(new exitMenuHandler());
 
  JMenu helpMenu = new JMenu("帮助");
  JMenuItem aboutItem = new JMenuItem("关于");
  helpMenu.add(aboutItem);
  aboutItem.addActionListener(new aboutMenuHandler());

  JMenuBar menuBar = new JMenuBar();
  menuBar.add(fileMenu);
  menuBar.add(helpMenu);
  setJMenuBar(menuBar);
 
  getContentPane().setLayout(new BorderLayout());
 
  JTabbedPane tabbedpane = new JTabbedPane();
  tabbedpane.add(new DistributeHousePanel(connection),"用户分房申请演示");
  tabbedpane.add(new QuiteHousePanel(connection),"用户退房申请演示");
  tabbedpane.add(new PrepareHousePanel(connection),"用户调房申请演示");
  tabbedpane.add(new QueryHouseInfoPanel(connection),"用户查询信息演示");
  tabbedpane.add(new MasterHouseInfoPanel(connection),"住房管理科管理演示");
 
  getContentPane().add(tabbedpane, BorderLayout.CENTER);
 
  setSize(750,560);
  setTitle("住房管理系统演示");
  setResizable(false);
  center(this);
  pack();
  setVisible(true);
 }

 
 
 
  public void center(Component C) {
  Dimension SS = C.getToolkit().getScreenSize();
  Dimension CS = C.getSize();
  C.setLocation ((SS.width - CS.width) / 2,(SS.height - CS.height) / 2);
  }

 
  public static Connection getConnection()throws SQLException { 
  try{
  Class.forName("sun.JDBC.odbc.JdbcOdbcdriver");
  }
  catch(Exception e){e.printStackTrace();}
  String url = "jdbc:odbc:住房管理系统";
  String username = "PUBLIC";
  String password = "PUBLIC";
  return
  DriverManager.getConnection(url, username, password);
  }

 public static void main(String args[]){
  initConnection();
  Locale.setDefault(Locale.US);
  new TrySql();
 
 
 }
 
 public static void clearMemory(){
  connection = null;
 }
 
 
  class exitMenuHandler implements ActionListener {
  public void actionPerformed( ActionEvent ae ) {
  disConnection();
  System.exit(0);
  }
 }
 
 
 class aboutMenuHandler implements ActionListener {
  public void actionPerformed( ActionEvent ae ) {
  new JDialog().setVisible(true);
  }
 }
}

感谢你能够认真阅读完这篇文章,希望小编分享的“怎么用java实现一个简单的房屋管理程序”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网行业资讯频道,更多相关知识等着你来学习!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯