📄 groundcontrolgui.java.svn-base
字号:
package gui;
/**
* Class: GroundControlGUI
*
* @author Niels-David Yogi
* v1.0
*/
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.*;
import world.Runway;
import world.Gate;
import world.Taxiway;
public class GroundControlGUI extends JPanel {
// Instance Variables
private final String ARRIVAL = "Arrivals";
private final String DEPARTURE = "Departures";
//private final String PATH = "C:/Users/flummox/Documents/CSCI105/myFAA/src/";
//private final String PATH = "src/gui/";
private final String PATH = "resources/textures/";
public JPanel pComboBox,
pCards,
pDepartures,
pArrivals,
pAnimation;
public String[] comboBoxItems = {ARRIVAL,DEPARTURE};
public JComboBox cb;
public GridBagConstraints c;
public ImageIcon[] iConfirmation;
// JComponents Required for Departure Pane
public JLabel lStatus,
lTaxiReady,
lTaxiReadyImage,
lPush,
lPushImage,
lTaxiPath,
lTaxiPathImage,
lCallNum,
lGateNum,
lRunway,
lTaxiway;
public JTextField tfGateNum;
public JComboBox cbCallNum,
cbRunway,
cbTaxiway;
public JTextArea taTaxiway;
public JScrollPane sScrollPane;
public JButton bPush,
bTaxiway,
bTaxiwaySubmit;
// JComponents Required for Arrival Pane
public JLabel lStatusArriv,
lPath,
lPathImage,
lCallNumArriv,
lRunwayArriv,
lGateNumArriv,
lTaxiwayArriv;
public JTextField tfRunwayArriv,
tfGateNumArriv;
public JButton bTaxiwayArriv,
bTaxiwaySubmitArriv;
public JComboBox cbCallNumArriv,
cbTaxiwayArriv;
public JTextArea taTaxiwayArriv;
public JScrollPane sScrollPaneArriv;
/**
* Default Constructor
*/
public GroundControlGUI()
{
initialize();
}
/**
* Initializes all JComponents
* Builds the panel
* @return void
*/
private void initialize()
{
// Setup the comboBox or Switching mechanism
pComboBox = new JPanel(); //use FlowLayout
cb = new JComboBox(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(new Options());
pComboBox.add(cb);
// Initialize Images
iConfirmation = new ImageIcon[2];
iConfirmation[0] = new ImageIcon(PATH + "buttons/no.gif", "no");
iConfirmation[1] = new ImageIcon(PATH + "buttons/yes.gif", "yes");
//iConfirmation[0] = new ImageIcon(PATH + "images/no.gif", "no");
//iConfirmation[1] = new ImageIcon(PATH + "images/yes.gif", "yes");
/*
* Creating the Animation Panel
* v0.0
*/
pAnimation = new JPanel();
pAnimation.setPreferredSize(new Dimension(400,150));
/*
* Creating the Arrival Panel
* v1.0
*/
pArrivals = new JPanel();
pArrivals.setLayout(new GridBagLayout());
c = new GridBagConstraints();
arrivalsInstantiate();
arrivalsBuild();
/*
* Creating the Departure Panel
* v1.0
*/
pDepartures = new JPanel();
pDepartures.setLayout(new GridBagLayout());
c = new GridBagConstraints();
departuresInstantiate();
departuresBuild();
//Create the panel that contains the "cards".
pCards = new JPanel(new CardLayout());
pCards.add(pArrivals, ARRIVAL);
pCards.add(pDepartures, DEPARTURE);
// Create BasePanel
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(pComboBox, this);
add(pAnimation, this);
add(pCards, this);
}
/**
* Helper method to initialize all the JComponents related to Arrivals
*
* @return void
*/
private void arrivalsInstantiate()
{
// Initialize JLabels
lStatusArriv = new JLabel("Status:");
lPath = new JLabel("Confrim Path: ");
lPathImage = new JLabel(iConfirmation[0]);
lCallNumArriv = new JLabel("Call #: ");
lRunwayArriv = new JLabel("Runway: ");
lGateNumArriv = new JLabel("Gate #: ");
lTaxiwayArriv = new JLabel("Taxiway:");
// Initialize JTextFields
tfRunwayArriv = new JTextField();
tfGateNumArriv = new JTextField();
tfRunwayArriv.setPreferredSize(new Dimension(100, 20));
tfGateNumArriv.setPreferredSize(new Dimension(100, 20));
// Initialize JComboBox
cbTaxiwayArriv = new JComboBox();
cbCallNumArriv = new JComboBox();
cbTaxiwayArriv.setPreferredSize(new Dimension(150, 20));
cbCallNumArriv.setPreferredSize(new Dimension(100, 20));
// Initialize JTextArea
taTaxiwayArriv= new JTextArea();
sScrollPaneArriv = new JScrollPane(taTaxiwayArriv);
sScrollPaneArriv.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sScrollPaneArriv.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
taTaxiwayArriv.setPreferredSize(new Dimension(400, 150));
taTaxiwayArriv.setEditable(false);
// Initialize JButtons
bTaxiwayArriv = new JButton("Add");
bTaxiwaySubmitArriv = new JButton("Submit Taxiway(s)");
}
/**
* Helper method to build all the JComponents related to Arrivals
*
* @return void
*/
private void arrivalsBuild()
{
// Row 0
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
// Row 1
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
pArrivals.add(lStatusArriv, c);
// Row 2
c.gridx = 0;
c.gridy = 2;
c.ipadx = 5;
c.ipady = 5;
pArrivals.add(lPath, c);
c.gridx = 1;
c.gridy = 2;
pArrivals.add(lPathImage, c);
// Row 3
c.gridx = 0;
c.gridy = 3;
pArrivals.add(lCallNumArriv, c);
c.gridx = 1;
c.gridy = 3;
pArrivals.add(cbCallNumArriv, c);
c.gridx = 2;
c.gridy = 3;
pArrivals.add(lRunwayArriv, c);
c.gridx = 3;
c.gridy = 3;
pArrivals.add(tfRunwayArriv, c);
c.gridx = 4;
c.gridy = 3;
pArrivals.add(lGateNumArriv, c);
c.gridx = 5;
c.gridy = 3;
pArrivals.add(tfGateNumArriv, c);
// Row 4
c.gridx = 0;
c.gridy = 4;
pArrivals.add(lTaxiwayArriv, c);
c.gridx = 1;
c.gridy = 4;
c.gridwidth = 2;
pArrivals.add(cbTaxiwayArriv, c);
c.gridx = 3;
c.gridy = 4;
c.gridwidth = 1;
pArrivals.add(bTaxiwayArriv, c);
// Row 5
c.gridx = 0;
c.gridy = 5;
c.gridheight = 8;
c.gridwidth = 5;
pArrivals.add(sScrollPaneArriv, c);
// Row 6
c.gridx = 0;
c.gridy = 13;
c.gridwidth = 2;
c.gridheight = 1;
pArrivals.add(bTaxiwaySubmitArriv, c);
}
/**
* Helper method to initialize all the JComponents related to Departure
*
* @return void
*/
private void departuresInstantiate()
{
// Initialize JLabels
lStatus = new JLabel("Status:");
lTaxiReady = new JLabel("Ready for Taxi: ");
lTaxiReadyImage = new JLabel(iConfirmation[0]);
lPush = new JLabel("Pushback Confirmation: ");
lPushImage = new JLabel(iConfirmation[0]);
lTaxiPath = new JLabel("Taxiway Confirmation: ");
lTaxiPathImage = new JLabel(iConfirmation[0]);
lCallNum = new JLabel("Call #: ");
lGateNum = new JLabel("Gate #: ");
lRunway = new JLabel("Runway: ");
lTaxiway = new JLabel("Taxiway(s): ");
// Initialize JTextFields
tfGateNum = new JTextField();
tfGateNum.setPreferredSize(new Dimension(100, 20));
// Initialize JComboBoxs
cbCallNum = new JComboBox();
cbRunway = new JComboBox();
cbTaxiway = new JComboBox();
cbCallNum.setPreferredSize(new Dimension(100, 20));
cbRunway.setPreferredSize(new Dimension(150, 20));
cbTaxiway.setPreferredSize(new Dimension(150, 20));
// Initialize JTextArea
taTaxiway = new JTextArea();
sScrollPane = new JScrollPane(taTaxiway);
sScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
sScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
taTaxiway.setPreferredSize(new Dimension(400, 150));
taTaxiway.setEditable(false);
// Initialize JButton
bPush = new JButton("Give Pushback");
bTaxiway = new JButton("Add");
bTaxiwaySubmit = new JButton("Submit Taxiways");
}
/**
* Helper method to build all the JComponents related to Departure
*
* @return void
*/
private void departuresBuild()
{
// Row 0
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
// Row 1
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
pDepartures.add(lStatus, c);
// Row 2
c.gridx = 0;
c.gridy = 2;
c.ipadx = 5;
c.ipady = 5;
pDepartures.add(lTaxiReady, c);
c.gridx = 1;
c.gridy = 2;
pDepartures.add(lTaxiReadyImage, c);
c.gridx = 2;
c.gridy = 2;
pDepartures.add(lPush, c);
c.gridx = 3;
c.gridy = 2;
pDepartures.add(lPushImage, c);
c.gridx = 4;
c.gridy = 2;
pDepartures.add(lTaxiPath, c);
c.gridx = 5;
c.gridy = 2;
pDepartures.add(lTaxiPathImage, c);
// Row 3
c.gridx = 0;
c.gridy = 3;
pDepartures.add(lCallNum, c);
c.gridx = 1;
c.gridy = 3;
c.gridwidth = 2;
pDepartures.add(cbCallNum, c);
c.gridx = 3;
c.gridy = 3;
c.gridwidth = 1;
pDepartures.add(lGateNum, c);
c.gridx = 4;
c.gridy = 3;
c.gridwidth = 2;
pDepartures.add(tfGateNum, c);
// Row 4
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 1;
pDepartures.add(lRunway, c);
c.gridx = 1;
c.gridy = 4;
c.gridwidth = 2;
pDepartures.add(cbRunway, c);
c.gridx = 3;
c.gridy = 4;
pDepartures.add(bPush, c);
// Row 5
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 1;
pDepartures.add(lTaxiway, c);
c.gridx = 1;
c.gridy = 5;
c.gridwidth = 2;
pDepartures.add(cbTaxiway, c);
c.gridx = 3;
c.gridy = 5;
pDepartures.add(bTaxiway, c);
// Row 6
c.gridx = 0;
c.gridy = 6;
c.gridheight = 8;
c.gridwidth = 6;
pDepartures.add(sScrollPane, c);
// Row 7
c.gridx = 0;
c.gridy = 14;
c.gridwidth = 2;
c.gridheight = 1;
pDepartures.add(bTaxiwaySubmit, c);
}
class Options implements ItemListener
{
//@Override
public void itemStateChanged(ItemEvent evt) {
// TODO Auto-generated method stub
CardLayout cl = (CardLayout)(pCards.getLayout());
cl.show(pCards, (String)evt.getItem());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -