Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use java to implement a simple housing management program

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use java to achieve a simple housing management program, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

/ *

Application form for household housing

, /

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 () {

}

/ *

Use an array to save the user's application information.

, /

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]

}

/ *

Get all kinds of application information from users

Including name, age, length of service, position, professional title, family population, etc.

information.

, /

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

}

}

/ / /

/ *

Used to show vacant rooms

Housing

Statistics on the total number of houses.

It's rough.

, /

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 iTuno witi 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 (0re0jue 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; iTunes +) {

Cy = (BARWIDTH + BARSPACING) * I) + BARSPACING

Cx = MAXLABELWIDTH + 1

Cx + = Math.max ((getWidth ()-(MAXLABELWIDTH + 1 + (MAX*SCALE) / 2jing0)

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 ()

}

}

}

/ / /

/ *

Write the user's application information into the room distribution file.

A month later, the information is read out by the system, and then the rooms are divided.

, /

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

}

}

/ /

/ *

To split the room.

, /

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 ()

}

/ *

Read out the applicant's information from the room allocation file and add it to the vector for use in the room allocation.

, /

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 iTunes 0

While (stk.hasMoreElements ()) {

Result [I] = stk.nextToken ("*")

ITunes +

}

ApplyInfo.setAllAttribute (result)

ApplyVector.addElement (applyInfo)

}

Reader.close ()

}

Catch (Exception e) {e.printStackTrace ();}

}

/ *

After the allocation of rooms, update the allocation documents to be empty files.

Prepare the next batch of rooms for use.

, /

Private synchronized void DeleteApplyQueueFile () {

Try {

FileOutputStream fos = new FileOutputStream ("house.tmp")

Fos.close ()

}

Catch (Exception e) {e.printStackTrace ();}

}

/ *

Randomly read out the applicant grade from the vector, connect to the database, and make related queries and updates.

, /

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 ()

}

/ *

Get a vacancy rating. Vacancy grade assumption and applicant's age, length of service, position, etc.

It's about. The functional relationship is not given here, it can be set to 3, 5, etc.

, /

Private synchronized int getVacantHouseInfo (String houseGrade) {

Int value =-1

Try {

PreparedStatement Stmt = connection.prepareStatement (

"select * FROM vacancy file WHERE House rating = +

HouseGrade + ")

ResultSet result = Stmt.executeQuery ()

ResultSetMetaData metadata = result.getMetaData ()

String houseInfo [] = new String [5]

While (result.next ()) {

For (int iTunes 1)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report