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

📄 pilotgui.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
			thrustSlider.setPaintLabels( true );			thrustSlider.addChangeListener( new ThrustListener() );			setLayout( new GridLayout( 1, 1 ) );			add( thrustSlider );		}		public void setThrust( double thrustTemp )		{			thrust = thrustTemp;		}		public double getThrust()		{			return thrust;		}		public class ThrustListener implements ChangeListener		{			public void stateChanged( ChangeEvent ce )			{				if( fuel.getFuel() > 0 )				{					speed.setSpeed( thrustSlider.getValue() * THRUST_RATIO );				}			}		}	}	public class Altitude extends JPanel	{		private double altitude;		//private JLabel altitudeLabel;		private Gauge altitudeGauge;		public Altitude()		{			this( 0.0 );		}		public Altitude( double altitudeTemp )		{			altitude = altitudeTemp;			//altitudeLabel = new JLabel( Double.toString( altitudeTemp ) );			altitudeGauge = new Gauge( "Altitude", 50, 0, 50, Math.PI / 4, 1.5 * Math.PI, 30, 20, 0.0 );			setLayout( new GridLayout( 1, 1 ) );			add( altitudeGauge );			//add( altitudeLabel );		}		public void setAltitude( double altitudeTemp )		{			altitude = altitudeTemp;			//altitudeLabel.setText( Double.toString( altitudeTemp ) );		}		public double getAltitude()		{			return altitude;		}	}	public class Yoke extends JPanel	{		private final String IMAGE_PATH = "resources/textures/";		private double pitchDelta;		private double rollDelta;		private BufferedImage yokeImage;		private int x;		private int y;		private int width;		private int height;		public Yoke()		{		    this( 0.0, 0.0 );		}		public Yoke( double pitchDeltaTemp, double rollDeltaTemp )		{			pitchDelta = pitchDeltaTemp;			rollDelta = rollDeltaTemp;			setBackground( Color.WHITE );			addMouseMotionListener( new YokeMotionListener() );			Image image = getToolkit().getImage( IMAGE_PATH + "yoke.gif" );			MediaTracker mt = new MediaTracker( this );			mt.addImage( image, 1 );			try			{				mt.waitForAll();			}			catch( Exception e )			{				System.out.println( "Exception while loading image." );			}			width = image.getWidth( this );			height = image.getHeight( this );			if( width == -1 )			{				System.out.println( "no gif file" );				System.exit( 0 );			}			yokeImage = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );			Graphics2D big = yokeImage.createGraphics();			big.drawImage( image, 0, 0, this );		}		public void setPitchDelta( double pitchDeltaTemp )		{			pitchDelta = pitchDeltaTemp;			//this is temporary			attitudeIndicator.setPitch( pitchDelta );		}		public double getPitchDelta()		{			return pitchDelta;		}		public void setRollDelta( double rollDeltaTemp )		{			rollDelta = rollDeltaTemp;			//this is temporary			attitudeIndicator.setRoll( rollDelta );		}		public double getRollDelta()		{			return rollDelta;		}		public void paintComponent( Graphics g )		{			super.paintComponent( g );			Graphics2D g2D = (Graphics2D) g;			int[] polygonX = { x, x + width, getWidth() / 2 + width / 2, getWidth()  / 2 - width / 2 };			int[] polygonY = { y + height / 2, y + height / 2, getHeight(), getHeight() };			g.fillPolygon( polygonX, polygonY, 4 );			g2D.drawImage( yokeImage, x, y, this );		}		public class YokeMotionListener extends MouseMotionAdapter		{			public void mouseDragged( MouseEvent me )			{				int mouseX = me.getX();				int mouseY = me.getY();				int panelX = yoke.getWidth();				int panelY = yoke.getHeight();				if( mouseX >= ( width / 2 ) && mouseY >= ( height / 2 ) && mouseX <= ( panelX - width / 2 ) && mouseY <= ( panelY - height / 2 ) )				{					x = mouseX - width / 2;					y = mouseY - height / 2;					setRollDelta( mouseX - panelX / 2 );					setPitchDelta( mouseY - panelY / 2 );					repaint();				}			}			//put this somewhere else			public void mouseMoved( MouseEvent me )			{				int centerX = yoke.getWidth() / 2;				int centerY = yoke.getHeight() / 2;				int imageCenterX = x + width / 2;				int imageCenterY = y + width / 2;				if( imageCenterX == centerX && imageCenterY == centerY )				{					return;				}				if( imageCenterX > centerX )				{					x--;				}				else if( imageCenterX < centerX )				{					x++;				}				if( imageCenterY > centerY )				{					y--;				}				else if( imageCenterY < centerY )				{					y++;				}				setRollDelta( imageCenterX - centerX );				setPitchDelta( imageCenterY - centerY );				repaint();			}		}	}		public class RadioWindow extends JPanel	{		private JComboBox messageOptions;		private JButton chooseMessage;				public RadioWindow()		{			setLayout( new GridLayout( 2, 1 ) );			messageOptions = new JComboBox();			chooseMessage = new JButton( "Send" );			chooseMessage.addActionListener( new MessageListener() );			add( messageOptions );			add( chooseMessage );		}				public void changeOptions( String[] options )		{			messageOptions.removeAllItems();			for( int i = 0; i < options.length; i++ )			{				messageOptions.addItem( options[i] );			}		}		public class MessageListener implements ActionListener		{			public void actionPerformed( ActionEvent ae )			{				if( messageOptions.getSelectedItem().equals( "Prepare For Landing" ) )				{					messageWindow.addMessage( "Prepare For Landing" );					pilotAgent.msgPrepareForLanding();				}				else if( messageOptions.getSelectedItem().equals( "Request To Land" ) )				{					messageWindow.addMessage( "Request To Land" );					pilotAgent.msgRequestToLand();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Clearance To Land" ) )				{					messageWindow.addMessage( "Confirm Clearance To Land" );					pilotAgent.msgConfirmClearanceToLand();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Landing Path" ) )				{					messageWindow.addMessage( "Confirm Landing Path" );					pilotAgent.msgConfirmLandingPath();				}				else if( messageOptions.getSelectedItem().equals( "Leaving Runway" ) )				{					messageWindow.addMessage( "Leaving Runway" );					pilotAgent.msgLeavingRunway();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Taxi Landing Path" ) )				{					messageWindow.addMessage( "Confirm Taxi Landing Path" );					pilotAgent.msgConfirmTaxiLandingPath();				}				else if( messageOptions.getSelectedItem().equals( "Requesting Clearance" ) )				{					messageWindow.addMessage( "Requesting Clearance" );					pilotAgent.msgRequestingClearance();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Clearance Granted" ) )				{					messageWindow.addMessage( "Confirm Clearance Granted" );					pilotAgent.msgConfirmClearanceGranted();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Weather" ) )				{					messageWindow.addMessage( "Confirm Weather" );					pilotAgent.msgConfirmWeather();				}				else if( messageOptions.getSelectedItem().equals( "Prepare For Departure" ) )				{					messageWindow.addMessage( "Prepare For Departure" );					pilotAgent.msgPrepareForDeparture();				}				else if( messageOptions.getSelectedItem().equals( "Request Push Back" ) )				{					messageWindow.addMessage( "Request Push Back" );					pilotAgent.msgRequestPushBack();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Push Back" ) )				{					messageWindow.addMessage( "Confirm Push Back" );					pilotAgent.msgConfirmPushBack();				}				else if( messageOptions.getSelectedItem().equals( "Ready For Taxi" ) )				{					messageWindow.addMessage( "Ready For Taxi" );					pilotAgent.msgReadyForTaxi();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Taxi Takeoff Path" ) )				{					messageWindow.addMessage( "Confirm Taxi Takeoff Path" );					pilotAgent.msgConfirmTaxiTakeoffPath();				}				else if( messageOptions.getSelectedItem().equals( "Ready For Takeoff" ) )				{					messageWindow.addMessage( "Ready For Takeoff" );					pilotAgent.msgReadyForTakeoff();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Position And Hold" ) )				{					messageWindow.addMessage( "Confirm Position And Hold" );					pilotAgent.msgConfirmPositionAndHold();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Cleared For Takeoff" ) )				{					messageWindow.addMessage( "Confirm Cleared For Takeoff" );					pilotAgent.msgConfirmClearedForTakeoff();				}				else if( messageOptions.getSelectedItem().equals( "Confirm Departure Control" ) )				{					messageWindow.addMessage( "Confirm Departure Control" );					pilotAgent.msgConfirmDepartureControl();				}				else if( messageOptions.getSelectedItem().equals( "Pilot Unavailable" ) )				{					messageWindow.addMessage( "Pilot Unavailable" );					pilotAgent.pilotUnavailable();				}				else if( messageOptions.getSelectedItem().equals( "Pilot Is Back" ) )				{					messageWindow.addMessage( "Pilot Is Back" );					pilotAgent.pilotIsBack();				}				else if( messageOptions.getSelectedItem().equals( "Not Ready To Request Landing" ) )				{					messageWindow.addMessage( "Not Ready To Request Landing" );					pilotAgent.notReadyToRequestLanding();				}				else if( messageOptions.getSelectedItem().equals( "Request To Land" ) )				{					messageWindow.addMessage( "Request To Land" );					pilotAgent.requestToLand();				}				else if( messageOptions.getSelectedItem().equals( "Prepare For Arrival" ) )				{					messageWindow.addMessage( "Prepare For Arrival" );					pilotAgent.prepareForArrival();				}				else if( messageOptions.getSelectedItem().equals( "Not Ready To Push Back" ) )				{					messageWindow.addMessage( "Not Ready To Push Back" );					pilotAgent.notReadyToPushBack();				}				else if( messageOptions.getSelectedItem().equals( "Request Push Back" ) )				{					messageWindow.addMessage( "Request Push Back" );					pilotAgent.requestPushBack();				}				else if( messageOptions.getSelectedItem().equals( "Prepare For Departure" ) )				{					messageWindow.addMessage( "Prepare For Departure" );					pilotAgent.prepareForDeparture();				}				else if( messageOptions.getSelectedItem().equals( "Emergency Landing" ) )				{					messageWindow.addMessage( "Emergency Landing" );					pilotAgent.emergencyLanding();				}				else if( messageOptions.getSelectedItem().equals( "Clearance For Emergency Landing" ) )				{					messageWindow.addMessage( "Clearance For Emergency Landing" );					pilotAgent.clearanceForEmergencyLanding();				}				messageOptions.removeItem( messageOptions.getSelectedItem() );			}		}	}	public class MessageWindow extends JPanel	{		private JTextArea messageWindow;		public MessageWindow()		{			messageWindow = new JTextArea();						setLayout( new GridLayout( 1, 1 ) );			JScrollPane sp = new JScrollPane( messageWindow, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );			add( sp );		}		public void addMessage( String message )		{			messageWindow.append( message );			}	}	public void update( Runway runway, Gate gate, String approach, String destination, List<Runway> path, LocalControlHelperGUI localController, Runway lastPath, List<Taxiway> taxiInstructions, Strip arrival, Weather report, GroundControlHelperGUI groundController, List<Waypoint> procedure, Runway takeoffRunway, TRACON departureControl )	{		runwayLabel.setText( runway.toString() );		gateLabel.setText( gate.toString() );		approachLabel.setText( approach );		//path		localControllerLabel.setText( localController.toString() );		lastPathLabel.setText( lastPath.toString() );		//taxiInstructions		arrivalLabel.setText( arrival.toString() );		destinationLabel.setText( destination.toString() );		reportLabel.setText( report.toString() );		groundControllerLabel.setText( groundController.toString() );		//procedure		takeoffRunwayLabel.setText( takeoffRunway.toString() );		departureControlLabel.setText( departureControl.toString() );	}}

⌨️ 快捷键说明

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