⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prison.java

📁 可视界面监狱管理系统 添加更改删除狱警囚犯 增加减少囚犯服刑年限 显示狱警工作年限 增加减少狱警工资 ASSIGN狱警囚犯到不同囚室
💻 JAVA
字号:
//Xiaohui Zhang
//W20010258
//Kaiyi Wang 
//W20010226
//Shuo Wang
//20015029

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


public class Prison extends JFrame implements ActionListener
{
        JMenuBar bar;
        JMenu operation;
        JMenuItem exit;
        JRadioButtonMenuItem help,about;

        JTextField nameInput,birthInput,enterInput,sentenceInput,idInput,section,cell,year;

        Container cont;

        JButton nextPrisoner,nextWarden,youngest,oldest,searchPrisoner,changeWarden,changePrisoner,searchWarden,release;

        JPanel inputPanel,controlPanel;

        JTextArea displayArea;
        JScrollPane scroller;

		Prisoner[] cells = new Prisoner[250];
		Warden[] wardens = new Warden[15];

		int countP = 0;
		int countW = 0;

        public Prison()
        {
			cont=getContentPane();
			cont.setLayout(new FlowLayout());
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

			Font font=new Font("TIMES NEW ROME",Font.PLAIN,14);
			Font font2=new Font("Arial BLACK",Font.PLAIN,16);

       		bar=new JMenuBar();
        	operation=new JMenu("Operation");

        	help =new JRadioButtonMenuItem("Help");
       		help.addItemListener(new radiohandler());

        	about =new JRadioButtonMenuItem("About");
       		about.addItemListener(new radiohandler());

       		exit=new JMenuItem("Exit");
        	exit.addActionListener(this);




        	JPanel inputPanel=new JPanel();
        	inputPanel.setLayout(new GridLayout(8,2,5,6));

        	JPanel controlPanel=new JPanel();
        	controlPanel.setLayout(new GridLayout(9,1,5,6));




			JLabel text1 = new JLabel("Name:");
			text1.setFont(font2);
			inputPanel.add(text1);

         	nameInput=new JTextField(18);
          	nameInput.setFont(font);
           	inputPanel.add(nameInput);

			JLabel text2 = new JLabel("Birth:");
			text2.setFont(font2);
			inputPanel.add(text2);

         	birthInput=new JTextField(4);
          	birthInput.setFont(font);
           	inputPanel.add(birthInput);

			JLabel text3 = new JLabel("Date of enter:");
			text3.setFont(font2);
			inputPanel.add(text3);

         	enterInput=new JTextField(4);
          	enterInput.setFont(font);
           	inputPanel.add(enterInput);

			JLabel text4 = new JLabel("Sentence/Wage:");
			text4.setFont(font2);
			inputPanel.add(text4);

         	sentenceInput=new JTextField(6);
          	sentenceInput.setFont(font);
           	inputPanel.add(sentenceInput);

			JLabel text5 = new JLabel("ID:");
			text5.setFont(font2);
			inputPanel.add(text5);

         	idInput=new JTextField(8);
          	idInput.setFont(font);
           	inputPanel.add(idInput);

			JLabel text6 = new JLabel("Section:");
			text6.setFont(font2);
			inputPanel.add(text6);

         	section=new JTextField(8);
          	section.setFont(font);
           	inputPanel.add(section);

			JLabel text7 = new JLabel("Cell:");
			text7.setFont(font2);
			inputPanel.add(text7);

         	cell=new JTextField(8);
          	cell.setFont(font);
           	inputPanel.add(cell);


    		nextWarden = new JButton("Warden");
           	nextWarden.addActionListener(this);
           	inputPanel.add(nextWarden);

    		nextPrisoner = new JButton("Prisoner");
           	nextPrisoner.addActionListener(this);
			inputPanel.add(nextPrisoner);





			JLabel text8 = new JLabel("Control Panel");
			text8.setFont(new Font("Arial BLACK",Font.PLAIN,20));
			controlPanel.add(text8);

    		youngest = new JButton("Youngest");
           	youngest.addActionListener(this);
           	controlPanel.add(youngest);

    		oldest = new JButton("Oldest");
           	oldest.addActionListener(this);
           	controlPanel.add(oldest);

    		searchPrisoner = new JButton("SearchPrisoner");
           	searchPrisoner.addActionListener(this);
           	controlPanel.add(searchPrisoner);

    		searchWarden = new JButton("SearchWarden");
           	searchWarden.addActionListener(this);
           	controlPanel.add(searchWarden);

    		changePrisoner = new JButton("ChangePrisoner");
           	changePrisoner.addActionListener(this);
           	controlPanel.add(changePrisoner);

    		changeWarden = new JButton("ChangeWarden");
           	changeWarden.addActionListener(this);
           	controlPanel.add(changeWarden);

         	year=new JTextField("Enter the current year",8);
          	year.setFont(new Font("TIMES NEW ROME",Font.PLAIN,12));
           	controlPanel.add(year);

    		release = new JButton("Release");
           	release.addActionListener(this);
           	controlPanel.add(release);






         	operation.add(help);
			operation.add(about);
           	operation.add(exit);

			bar.add(operation);
          	setJMenuBar(bar);

          	cont.add(inputPanel);
          	cont.add(controlPanel);





			displayArea = new JTextArea("Release list:                           ", 4, 42);
			displayArea.setFont(new Font("TIMES NEW ROME",Font.BOLD,16));

			cont.add(displayArea);


            scroller = new JScrollPane(displayArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

			cont.add(scroller);

				nameInput.setText("None");
				birthInput.setText("0");
				sentenceInput.setText("0");
				idInput.setText("0");
				enterInput.setText("0");
				section.setText("0");
				cell.setText("0");
        }



		public class radiohandler implements ItemListener
		{

			public void itemStateChanged(ItemEvent ie)
  			{
        		AbstractButton button=(AbstractButton)ie.getItem();
      			String label=button.getText();
        		{
              		if(label.equals("Help"))
	            	{
						new Help();
						validate();
          			}

          			else if(label.equals("About"))
					{
						JOptionPane.showMessageDialog(null, "Fox River Prison Management System2000", "About...", JOptionPane.PLAIN_MESSAGE);
						validate();
          			}
        		}
        	}
        }



		public void actionPerformed(ActionEvent event)
		{
        	String butttonInput=event.getActionCommand();

        	String nameTem = nameInput.getText();
        	int birthTem = Integer.valueOf(birthInput.getText()).intValue();
        	int sentenceWageTem = Integer.valueOf(sentenceInput.getText()).intValue();
        	int idTem = Integer.valueOf(idInput.getText()).intValue();
        	int dateEnterTem = Integer.valueOf(enterInput.getText()).intValue();
        	int cellTem = Integer.valueOf(cell.getText()).intValue();
        	int sectionTem = Integer.valueOf(section.getText()).intValue();

        	if(butttonInput.equals("Exit"))
        	{
                System.exit(0);
        	}

        	else if(butttonInput.equals("Prisoner"))
        	{
				if(countP < 250)
				{
					cells[countP]= new Prisoner(nameTem,birthTem,sentenceWageTem,idTem,dateEnterTem);
					countP++;
				}

				else if(countP >= 250)
				{
					JOptionPane.showMessageDialog(null, "Sorry, there is no more cell.", "Alart!", JOptionPane.PLAIN_MESSAGE);
				}

				nameInput.setText("None");
				birthInput.setText("0");
				sentenceInput.setText("0");
				idInput.setText("0");
				enterInput.setText("0");
				section.setText("0");
				cell.setText(""+(countP+1));
			}

			else if(butttonInput.equals("SearchPrisoner"))
			{

				int p = 0;

				while(!((cells[p].nameP).equals(nameTem)) && (p < 250))
				{
					p++;
				}

				if((cells[p].nameP).equals(nameTem))
				{
					nameInput.setText(cells[p].nameP);
					birthInput.setText(String.valueOf(cells[p].birth));
					sentenceInput.setText(String.valueOf(cells[p].sentence));
					idInput.setText(String.valueOf(cells[p].id));
					enterInput.setText(String.valueOf(cells[p].dateEnter));

					int cel = 0;
					int sec = 0;

					while(p > cel && sec < 10)
					{
						cel = cel + 20;
						sec++;
					}

					while(p > cel && sec < 15)
					{
						cel = cel +10;
						sec++;
					}

					if(sec == 0)
					{
						sec = sec + 1;
					}

					section.setText(String.valueOf(sec));
					cell.setText(String.valueOf(p+1));
				}

				else
				{
					JOptionPane.showMessageDialog(null, "Sorry, the prisoner is not in this prison.", "No result.", JOptionPane.PLAIN_MESSAGE);
				}
			}

        	else if(butttonInput.equals("Warden"))
        	{
				if(countW < 15)
				{
					wardens[countW]= new Warden(nameTem,birthTem,sentenceWageTem,idTem,dateEnterTem);
					countW++;
				}

				else if(countW >= 15)
				{
					JOptionPane.showMessageDialog(null, "Sorry, we do not need any more warden.", "Alart!", JOptionPane.PLAIN_MESSAGE);
				}

				nameInput.setText("None");
				birthInput.setText("0");
				sentenceInput.setText("0");
				idInput.setText("0");
				enterInput.setText("0");
				section.setText(""+(countW+1));
				cell.setText("0");
			}



			else if(butttonInput.equals("SearchWarden"))
			{

				int w = 0;

				while(!((wardens[w].nameW).equals(nameTem)) && (w < 15))
				{
					w++;
				}

				if((wardens[w].nameW).equals(nameTem))
				{
					nameInput.setText(wardens[w].nameW);
					birthInput.setText(String.valueOf(wardens[w].birth));
					sentenceInput.setText(String.valueOf(wardens[w].wage));
					idInput.setText(String.valueOf(wardens[w].id));
					enterInput.setText(String.valueOf(wardens[w].dateEnter));

					section.setText(String.valueOf(w+1));
					cell.setText(String.valueOf(w+1));
				}

				else
				{
					JOptionPane.showMessageDialog(null, "Sorry, the warden is not in this prison.", "No result.", JOptionPane.PLAIN_MESSAGE);
				}
			}


			else if(butttonInput.equals("ChangePrisoner"))
			{
				int cellChange = Integer.valueOf(cell.getText()).intValue() - 1;

				if(cellChange < 250)
				{
					cells[cellChange].nameP = nameInput.getText();
					cells[cellChange].birth = Integer.valueOf(birthInput.getText()).intValue();
					cells[cellChange].sentence = Integer.valueOf(sentenceInput.getText()).intValue();
					cells[cellChange].id = Integer.valueOf(idInput.getText()).intValue();
					cells[cellChange].dateEnter = Integer.valueOf(enterInput.getText()).intValue();
				}

				nameInput.setText("None");
				birthInput.setText("0");
				sentenceInput.setText("0");
				idInput.setText("0");
				enterInput.setText("0");
				section.setText("0");
				cell.setText(""+(countP+1));
			}

			else if(butttonInput.equals("ChangeWarden"))
			{
				int sectionChange = Integer.valueOf(section.getText()).intValue() - 1;

				if(sectionChange < 15)
				{
					wardens[sectionChange].nameW = nameInput.getText();
					wardens[sectionChange].birth = Integer.valueOf(birthInput.getText()).intValue();
					wardens[sectionChange].wage = Integer.valueOf(sentenceInput.getText()).intValue();
					wardens[sectionChange].id = Integer.valueOf(idInput.getText()).intValue();
					wardens[sectionChange].dateEnter = Integer.valueOf(enterInput.getText()).intValue();
				}

				nameInput.setText("None");
				birthInput.setText("0");
				sentenceInput.setText("0");
				idInput.setText("0");
				enterInput.setText("0");
				section.setText(""+(countW+1));
				cell.setText("0");
			}

			else if(butttonInput.equals("Youngest"))
			{
				int fuck = 0;
				int youngest = 0;

				for(int i = 0;i < countP;i++)
				{
					if(fuck < cells[i].birth && cells[i].birth != 0)
					{
						fuck = cells[i].birth;
					}
				}

				while(cells[youngest].birth != fuck)
				{
					youngest++;
				}

				nameInput.setText(cells[youngest].nameP);
				birthInput.setText(""+fuck);
				birthInput.setText(String.valueOf(cells[youngest].birth));
				sentenceInput.setText(String.valueOf(cells[youngest].sentence));
				idInput.setText(String.valueOf(cells[youngest].id));
				enterInput.setText(String.valueOf(cells[youngest].dateEnter));

				int cel2 = 0;
				int sec2 = 0;

				while(youngest > cel2 && sec2 < 10)
			    {
					cel2 = cel2 + 20;
					sec2++;
				}

				while(youngest > cel2 && sec2 < 15)
				{
					cel2 = cel2 +10;
					sec2++;
				}

				if(sec2 == 0)
				{
					sec2 = sec2 + 1;
				}

				section.setText(String.valueOf(sec2));
				cell.setText(String.valueOf(youngest+1));
			}


			else if(butttonInput.equals("Oldest"))
			{
				int fuck2 = 99999999;
				int oldest = 0;

				for(int i = 0;i < countP;i++)
				{
					if(fuck2 > cells[i].birth && cells[i].birth != 0)
					{
						fuck2 = cells[i].birth;
					}
				}

				while(cells[oldest].birth != fuck2)
				{
					oldest++;
				}

				nameInput.setText(cells[oldest].nameP);
				birthInput.setText(""+fuck2);
				birthInput.setText(String.valueOf(cells[oldest].birth));
				sentenceInput.setText(String.valueOf(cells[oldest].sentence));
				idInput.setText(String.valueOf(cells[oldest].id));
				enterInput.setText(String.valueOf(cells[oldest].dateEnter));

				int cel3 = 0;
				int sec3 = 0;

				while(oldest > cel3 && sec3 < 10)
			    {
					cel3 = cel3 + 20;
					sec3++;
				}

				while(oldest > cel3 && sec3 < 15)
				{
					cel3 = cel3 +10;
					sec3++;
				}

				if(sec3 == 0)
				{
					sec3 = sec3 + 1;
				}

				section.setText(String.valueOf(sec3));
				cell.setText(String.valueOf(oldest+1));
			}

			else if(butttonInput.equals("Release"))
			{
				int yearTem = Integer.valueOf(year.getText()).intValue();

				for(int i = 0;i < countP;i++)
				{
					if( yearTem - cells[i].dateEnter - yearTem < cells[i].sentence)
					{
						displayArea.append("Freeman : "+"  "+cells[i].nameP+"               ");

						cells[i].nameP = "None";
						cells[i].birth = 0;
						cells[i].sentence = 0;
						cells[i].id = 0;
						cells[i].dateEnter = 0;
					}
				}
			}
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -