📄 agentcontrollergui.java.svn-base
字号:
package gui;import agents.*;import interfaces.*;import java.util.*;import javax.swing.*;import world.Airport;import world.Boeing777;import java.awt.*;import java.awt.event.*;public class AgentControllerGUI extends JPanel implements ActionListener{ JPanel testPanel; JPanel tabPane1, pilotsList, co_pilotsList, groundCList, localCList, clearanceDList, infoPanel; JLabel agents1, agents2, agents3, agents4, agents5, optionsLabel; JScrollPane scroll1, scroll2, scroll3, scroll4, scroll5; JCheckBox killPilot, killCoPilot, reincarnatePilot; PilotAgent selectedPilot; CoPilotAgent selectedCoPilot; StartGuiNoRMI gui; Airport airport; public AgentControllerGUI(StartGuiNoRMI gui){ this.gui = gui; this.airport = gui.airport; testPanel = new JPanel(); testPanel.setLayout(new GridLayout(1,1)); createAgentsTab(); } //***Creates the Agents tab. Will utilize outside methods to make the agents and display their data** public void createAgentsTab(){ JPanel pilotControl, co_pilotControl,groundCControl , localCControl, clearanceDControl; scroll1 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll2 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll3 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll4 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll4 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll5 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); pilotsList = new JPanel(); pilotsList.setLayout(new BoxLayout(pilotsList, BoxLayout.Y_AXIS)); co_pilotsList = new JPanel(); co_pilotsList.setLayout(new BoxLayout(co_pilotsList, BoxLayout.Y_AXIS)); groundCList = new JPanel(); groundCList.setLayout(new BoxLayout(groundCList, BoxLayout.Y_AXIS)); localCList = new JPanel(); localCList.setLayout(new BoxLayout(localCList, BoxLayout.Y_AXIS)); clearanceDList = new JPanel(); clearanceDList.setLayout(new BoxLayout(clearanceDList, BoxLayout.Y_AXIS)); scroll1.add(pilotsList); scroll2.add(co_pilotsList); scroll3.add(groundCList); scroll4.add(localCList); scroll5.add(clearanceDList); agents1 = new JLabel("Pilots"); agents2 = new JLabel("Co-Pilots"); agents3 = new JLabel("Ground C."); agents4 = new JLabel("Local C."); agents5 = new JLabel("Clearance D."); pilotControl = new JPanel(); co_pilotControl = new JPanel(); groundCControl = new JPanel(); localCControl = new JPanel(); clearanceDControl = new JPanel(); infoPanel = new JPanel(); infoPanel.setLayout(new GridLayout(2, 1)); killPilot = new JCheckBox("Kill Pilot"); killPilot.addActionListener(this); reincarnatePilot = new JCheckBox("Reincarnate Pilot"); reincarnatePilot.addActionListener(this); killCoPilot = new JCheckBox("Kill CoPilot"); killCoPilot.addActionListener(this); tabPane1 = new JPanel(); tabPane1.setLayout(new GridLayout(1,5)); tabPane1.add(pilotControl); tabPane1.add(co_pilotControl); tabPane1.add(groundCControl); tabPane1.add(localCControl); tabPane1.add(clearanceDControl); tabPane1.add(infoPanel); pilotControl.setLayout(new BoxLayout(pilotControl, BoxLayout.Y_AXIS)); pilotControl.add(agents1); pilotControl.add(scroll1); co_pilotControl.setLayout(new BoxLayout(co_pilotControl, BoxLayout.Y_AXIS)); co_pilotControl.add(agents2); co_pilotControl.add(scroll2); groundCControl.setLayout(new BoxLayout(groundCControl, BoxLayout.Y_AXIS)); groundCControl.add(agents3); groundCControl.add(scroll3); localCControl.setLayout(new BoxLayout(localCControl, BoxLayout.Y_AXIS)); localCControl.add(agents4); localCControl.add(scroll4); clearanceDControl.setLayout(new BoxLayout(clearanceDControl, BoxLayout.Y_AXIS)); clearanceDControl.add(agents5); clearanceDControl.add(scroll5); infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS)); testPanel.add(tabPane1); setLayout(new GridLayout(1,1)); add(testPanel); } public void actionPerformed(ActionEvent e) { JButton thisButton; for (int i = 0; i < pilotsList.getComponents().length; i++) { thisButton = (JButton) pilotsList.getComponents()[i]; if (e.getSource() == thisButton) { infoPanel.removeAll(); selectedPilot = (PilotAgent) gui.getPilotAgents().get(i); infoPanel.add(new JLabel(((PilotAgent) gui.getPilotAgents().get(i)).getName() + " Options")); infoPanel.add(killPilot); infoPanel.add(reincarnatePilot); infoPanel.revalidate(); return; } } for (int i = 0; i < gui.getCoPilotAgents().size(); i++){ thisButton = (JButton) co_pilotsList.getComponents()[i]; if (e.getSource() == thisButton){ infoPanel.removeAll(); selectedCoPilot = (CoPilotAgent) gui.getCoPilotAgents().get(i); infoPanel.add(new JLabel(((CoPilotAgent) gui.getCoPilotAgents().get(i)).getName() + " Options")); // infoPanel.add(killCoPilot); infoPanel.revalidate(); return; } } if(e.getSource() == killPilot) { if(killPilot.isSelected()) { selectedPilot.plane.promoteCoPilot(); } else { // selectedPilot.setResponsive(); } } else if(e.getSource() == reincarnatePilot) { if(reincarnatePilot.isSelected()) { selectedPilot.plane.pilotsBack(selectedPilot); } } // TODO taylor change this back //***makes new Pilot agent*** /* if(e.getSource() == killPilot) { if(killPilot.isSelected()) { selectedPilot.setUnresponsive(); } else { selectedPilot.setResponsive(); } } else if(e.getSource() == killCoPilot) { if(killCoPilot.isSelected()) { selectedCoPilot.setUnresponsive(); } else { selectedCoPilot.setResponsive(); } } */ } public void addGroundControl(String name) { groundCList.add(new JLabel(name)); scroll3.setViewportView(groundCList); } public void addLocalControl(String name) { localCList.add(new JLabel(name)); scroll4.setViewportView(localCList); } public void addClearanceDelivery(String name) { clearanceDList.add(new JLabel(name)); scroll5.setViewportView(clearanceDList); } public void addPilot(String name) { JButton newPilotButton = new JButton(name); newPilotButton.addActionListener(this); pilotsList.add(newPilotButton); scroll1.setViewportView(pilotsList); } public void addCoPilot(String name) { JButton newCoPilotButton = new JButton(name); newCoPilotButton.addActionListener(this); co_pilotsList.add(newCoPilotButton); scroll2.setViewportView(co_pilotsList); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -