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

📄 localcontrolgui.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
字号:
package gui;
/**
 * Class: LocalControlGUI
 * 
 * @author Niels-David Yogi
 * v1.0
 */
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import javax.swing.*;

import world.*;

public class LocalControlGUI 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 = "resources/textures/";
	public JPanel pComboBox,
	               pCards,
	               pArrivals,
	               pDepartures,
	               pAnimation;
	private String[] comboBoxItems = {ARRIVAL,DEPARTURE};
    public JComboBox cb;
	public GridBagConstraints c;
	public ImageIcon[] iConfirmation;
		
	// JComponents Required for Arrival Pane
	public JLabel lStatusArriv,
				   lLandArriv,
				   lLandImageArriv,
				   lPathArriv,
				   lPathImageArriv,
				   lCallNumArriv,
				   lRunwayArriv,
				   lGateNumArriv,
				   lTaxiwayArriv;
	public JTextField tfRunwayArriv,
					   tfGateNumArriv;
	public JButton bRunwayClearArriv,
					bTaxiwayArriv,
					bTaxiwaySubmitArriv;
	public JComboBox cbCallNumArriv,
	                  cbTaxiwayArriv;
	public JTextArea taTaxiwayArriv;
	public JScrollPane sScrollPane;
	
	// JComponents Required for Departure Pane
	public JLabel lStatusDep,
				   lReadyDep,
				   lReadyImageDep,
				   lHoldDep,
				   lHoldImageDep,
				   lConfirmDep,
				   lConfirmImageDep,
				   lConfirm2Dep,
				   lConfirm2ImageDep,
				   lCallNumDep,
				   lRunwayDep,
				   lRunway2Dep;
	public JTextField tfRunwayDep;
	public JButton bHoldDep,
					bClearedDep,
					bContactDep;
	public JComboBox cbCallNumDep,
	                  cbRunwayDep;
	
	StartGuiNoRMI gui;
	Airport airport;
	
	/**
	 * Default Constructor
	 */	
	public LocalControlGUI()
	{
		initialize();
	}
	
	/**
	 * Initializes all JComponents
	 * Builds the panel
	 * @return void
	 */	
	private void initialize()
	{
		// Setup the comboBox or Switching mechanism
		pComboBox = new JPanel();
        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");
		
		/*
         * 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 BorderLayout());
        add(pComboBox, BorderLayout.PAGE_START);
        add(pCards, BorderLayout.CENTER);*/
        
        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:");
		lLandArriv      = new JLabel("Clearance to Land: ");
		lLandImageArriv = new JLabel(iConfirmation[0]);
	    lPathArriv      = new JLabel("Confirm Landing Path: ");
	    lPathImageArriv = 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 JButtons
	    bRunwayClearArriv = new JButton("Runway Clear?");
		bTaxiwayArriv  = new JButton("Add");
		bTaxiwaySubmitArriv = new JButton("Submit Taxiway(s)");
		
		// Initialize JComboBox
		cbCallNumArriv = new JComboBox();
		cbTaxiwayArriv  = new JComboBox();
		cbCallNumArriv.setPreferredSize(new Dimension(100, 20));
		cbTaxiwayArriv.setPreferredSize(new Dimension(150, 20));
		
		// Initialize JTextArea
		taTaxiwayArriv = new JTextArea();
		sScrollPane = new JScrollPane(taTaxiwayArriv);
		sScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		sScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		taTaxiwayArriv.setPreferredSize(new Dimension(400, 150));
		taTaxiwayArriv.setEditable(false);
	}
	
	/**
	 * Helper method to build all the JComponents related to Arrivals
	 * 
	 * @return void
	 */	
	private void arrivalsBuild()
    {
        // Row 1
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.WEST;
		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(lLandArriv, c);
		c.gridx = 1;
		c.gridy = 2;
		pArrivals.add(lLandImageArriv, c);
		c.gridx = 2;
		c.gridy = 2;
		pArrivals.add(lPathArriv, c);
		c.gridx = 3;
		c.gridy = 2;
		pArrivals.add(lPathImageArriv, c);
		
		// Row 3
		c.gridx = 0;
		c.gridy = 3;
		pArrivals.add(lCallNumArriv, c);
		c.gridx = 1;
		c.gridy = 3;
		c.gridwidth = 2;
		pArrivals.add(cbCallNumArriv, c);
		c.gridx = 3;
		c.gridy = 3;
		c.gridwidth = 1;
		pArrivals.add(lRunwayArriv, c);
		c.gridx = 4;
		c.gridy = 3;
		c.gridwidth = 2;
		pArrivals.add(tfRunwayArriv, c);
		c.gridx = 6;
		c.gridy = 3;
		c.gridwidth = 1;
		pArrivals.add(lGateNumArriv, c);
		c.gridx = 7;
		c.gridy = 3;
		c.gridwidth = 2;
		pArrivals.add(tfGateNumArriv, c);
		
		// Row 4
		c.gridx = 0;
		c.gridy = 4;
		pArrivals.add(bRunwayClearArriv, c);
		
		// Row 5
		c.gridx = 0;
		c.gridy = 5;
		c.gridwidth = 1;
		pArrivals.add(lTaxiwayArriv, c);
		c.gridx = 1;
		c.gridy = 5;
		c.gridwidth = 2;
		pArrivals.add(cbTaxiwayArriv, c);
		c.gridx = 3;
		c.gridy = 5;
		c.gridwidth = 1;
		pArrivals.add(bTaxiwayArriv, c);
		
		// Row 6
		c.gridx = 0;
		c.gridy = 6;
		c.gridheight = 8;
		c.gridwidth = 6;
		pArrivals.add(sScrollPane, c);
		//pArrivals.add(taTaxiwayArriv, c);
		
		// Row 7
		c.gridx = 0;
		c.gridy = 14;
		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
		lStatusDep        = new JLabel("Status:");
	    lReadyDep         = new JLabel("Ready for Take-Off: ");
	    lReadyImageDep    = new JLabel(iConfirmation[0]); 
	    lHoldDep          = new JLabel("Position and Hold: ");
	    lHoldImageDep     = new JLabel(iConfirmation[0]);
	    lConfirmDep       = new JLabel("Confirm for Take-Off: ");
	    lConfirmImageDep  = new JLabel(iConfirmation[0]);
	    lConfirm2Dep      = new JLabel("Confirm Departure Control: ");
	    lConfirm2ImageDep = new JLabel(iConfirmation[0]);
	    lCallNumDep       = new JLabel("Call #: ");
	    lRunwayDep        = new JLabel("Current Runway: ");
	    lRunway2Dep       = new JLabel("Runway: ");
	    
	    // Initialize JTextFields
	    tfRunwayDep  = new JTextField();
	    
	    // Initialize JButtons
	    bHoldDep    = new JButton("Confirm Positions and Hold");
	    bClearedDep = new JButton("Cleared?");
	    bContactDep = new JButton("Confirm Departure");
	     
	    // Initialize JComboBox
	    cbCallNumDep = new JComboBox();
	    cbRunwayDep = new JComboBox();	   
	    cbCallNumDep.setPreferredSize(new Dimension(100, 20));
	    cbRunwayDep.setPreferredSize(new Dimension(150, 20));
	}
	
	/**
	 * Helper method to build all the JComponents related to Departure
	 * 
	 * @return void
	 */	
	private void departuresBuild()
	{
		// Row 1
		c.fill = GridBagConstraints.HORIZONTAL;
		c.anchor = GridBagConstraints.WEST;
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 1;
		pDepartures.add(lStatusDep, c);
		
		// Row 2
		c.gridx = 0;
		c.gridy = 2;
		c.ipadx = 5;
		c.ipady = 5;
		pDepartures.add(lReadyDep, c);
		c.gridx = 1;
		c.gridy = 2;
		pDepartures.add(lReadyImageDep, c);
		c.gridx = 2;
		c.gridy = 2;
		pDepartures.add(lHoldDep, c);
		c.gridx = 3;
		c.gridy = 2;
		pDepartures.add(lHoldImageDep, c);
		c.gridx = 4;
		c.gridy = 2;
		pDepartures.add(lConfirmDep, c);
		c.gridx = 5;
		c.gridy = 2;
	    pDepartures.add(lConfirmImageDep, c);
		c.gridx = 6;
		c.gridy = 2;
		/*
		pDepartures.add(lConfirm2Dep, c);
		c.gridx = 7;
		c.gridy = 2;
		pDepartures.add(lConfirm2ImageDep, c);
		*/
		// Row 3
		c.gridx = 0;
		c.gridy = 3;
		pDepartures.add(lCallNumDep, c);
		c.gridx = 1;
		c.gridy = 3;
		c.gridwidth = 2;
		pDepartures.add(cbCallNumDep, c);
		c.gridx = 4;
		c.gridy = 3;
		c.gridwidth = 1;
		pDepartures.add(lRunwayDep, c);
		c.gridx = 5;
		c.gridy = 3;
		c.gridwidth = 2;
		pDepartures.add(tfRunwayDep, c);
		
		// Row 4
		c.fill = GridBagConstraints.NONE;
		c.gridx = 0;
		c.gridy = 4;
		
		c.gridwidth = 3;
		pDepartures.add(bHoldDep, c);
		
		// Row 5
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 5;
		c.gridwidth = 1;
		pDepartures.add(lRunway2Dep, c);
		c.gridx = 1;
		c.gridy = 5;
		c.gridwidth = 2;
		pDepartures.add(cbRunwayDep, c);
		c.fill = GridBagConstraints.NONE;
		c.gridx = 4;
		c.gridy = 5;
		pDepartures.add(bClearedDep, c);
		
		// Row 6
		c.fill = GridBagConstraints.HORIZONTAL;
		c.anchor = GridBagConstraints.WEST;
		c.gridx = 0;
		c.gridy = 6;
		c.gridwidth = 2;
		pDepartures.add(bContactDep, 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 + -