📄 selectlevels.java
字号:
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/**
* Write a description of class System here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SelectLevels implements ActionListener
{
static SelectLevels singleton;
User currentUser;
JButton ok;
JButton cancel;
JButton logout;
JButton chooseLevel;
JButton results;
JButton clear;
JButton editLevel;
JButton viewReports;
JButton manageUsers;
JButton startLevel;
JButton left;
JButton right;
JButton queue;
JButton land;
JButton pause;
JButton menu;
JButton print;
JPasswordField password;
JComboBox username;
JComboBox levelBox;
JTextField levDescription;
JTextField levRunway;
JTextField levFreq;
JTextField levAircraft;
JFrame frame;
String[] name;
String[] runway;
String[] aircraft;
String[] frequency;
String[] description;
SpringLayout layout = new SpringLayout();
public SelectLevels()
{
singleton = this;
ArrayList<Level> l = Level.getLevels();
frame = new JFrame();
frame.setSize(800,600);
Container content = frame.getContentPane();
content.setLayout(layout);
int n = l.size();
name = new String[n];
runway = new String[n];
aircraft = new String[n];
frequency = new String[n];
description = new String[n];
for(int i = 0; i < l.size(); i++)
{
name[i] = l.get(i).name;
runway[i] = String.valueOf(l.get(i).runways);
aircraft[i] = String.valueOf(l.get(i).numberOfAircraft);
frequency[i] = String.valueOf(l.get(i).frequency);
description[i] = l.get(i).description;
}
levelBox = new JComboBox();
levDescription = new JTextField(15);
levRunway = new JTextField(15);
levFreq = new JTextField(15);
levAircraft = new JTextField(15);
JLabel desLabel = new JLabel("Description: ");
JLabel runLabel = new JLabel("Runways: ");
JLabel freqLabel = new JLabel("Aircraft Frequency: ");
JLabel levLabel = new JLabel("Levels: ");
JLabel airLabel = new JLabel("no of Aircraft: ");
JLabel title = new JLabel("Level Selection");
title.setFont(new Font(null,Font.BOLD,32));
content.add(title);
content.add(levLabel);
content.add(levelBox);
content.add(desLabel);
content.add(levDescription);
content.add(runLabel);
content.add(levRunway);
content.add(freqLabel);
content.add(levFreq);
content.add(airLabel);
content.add(levAircraft);
for (Level lev : Level.levels)
{
levelBox.addItem(lev);
}
startLevel = new JButton("Start");
menu = new JButton("menu");
content.add(startLevel);
content.add(menu);
startLevel.addActionListener(this);
menu.addActionListener(this);
levelBox.addActionListener(this);
levelBox.setSelectedIndex(0);
layout.putConstraint(SpringLayout.WEST, title, 200, SpringLayout.WEST, content);
layout.putConstraint(SpringLayout.NORTH, title, 50, SpringLayout.NORTH, content);
layout.putConstraint(SpringLayout.WEST, levelBox, 100, SpringLayout.WEST, title);
layout.putConstraint(SpringLayout.NORTH, levelBox, 10, SpringLayout.SOUTH, title);
layout.putConstraint(SpringLayout.WEST, levDescription, 0, SpringLayout.WEST, levelBox);
layout.putConstraint(SpringLayout.NORTH, levDescription, 10, SpringLayout.SOUTH, levelBox);
layout.putConstraint(SpringLayout.WEST, levRunway, 0, SpringLayout.WEST, levDescription);
layout.putConstraint(SpringLayout.NORTH, levRunway, 10, SpringLayout.SOUTH, levDescription);
layout.putConstraint(SpringLayout.WEST, levFreq, 0, SpringLayout.WEST, levRunway);
layout.putConstraint(SpringLayout.NORTH, levFreq, 10, SpringLayout.SOUTH, levRunway);
layout.putConstraint(SpringLayout.WEST, levAircraft, 0, SpringLayout.WEST, levFreq);
layout.putConstraint(SpringLayout.NORTH, levAircraft, 10, SpringLayout.SOUTH, levFreq);
layout.putConstraint(SpringLayout.EAST, levLabel, -5, SpringLayout.WEST, levelBox);
layout.putConstraint(SpringLayout.SOUTH, levLabel, 0, SpringLayout.SOUTH, levelBox);
layout.putConstraint(SpringLayout.EAST, desLabel, -5, SpringLayout.WEST, levDescription);
layout.putConstraint(SpringLayout.SOUTH, desLabel, 0, SpringLayout.SOUTH, levDescription);
layout.putConstraint(SpringLayout.EAST, runLabel, -5, SpringLayout.WEST, levRunway);
layout.putConstraint(SpringLayout.SOUTH, runLabel, 0, SpringLayout.SOUTH, levRunway);
layout.putConstraint(SpringLayout.EAST, freqLabel, -5, SpringLayout.WEST, levFreq);
layout.putConstraint(SpringLayout.SOUTH, freqLabel, 0, SpringLayout.SOUTH, levFreq);
layout.putConstraint(SpringLayout.EAST, airLabel, -5, SpringLayout.WEST, levAircraft);
layout.putConstraint(SpringLayout.SOUTH, airLabel, 0, SpringLayout.SOUTH, levAircraft);
layout.putConstraint(SpringLayout.NORTH, startLevel, 500, SpringLayout.NORTH, content);
layout.putConstraint(SpringLayout.NORTH, menu, 500, SpringLayout.NORTH, content);
layout.putConstraint(SpringLayout.EAST, menu, -50, SpringLayout.EAST, content);
layout.putConstraint(SpringLayout.EAST, startLevel, -20, SpringLayout.WEST, menu);
frame.setTitle("Level Selection");
frame.setLocationRelativeTo(null);
makeVisible();
}
public void makeVisible()
{
frame.setVisible(true);
frame.setResizable(false);
}
public static void show()
{
if (!(singleton == null)) { singleton.makeVisible(); } else { new SelectLevels(); }
}
public void actionPerformed(ActionEvent event) {
if (event.getSource().equals(startLevel)) {SimulationGUI s = new SimulationGUI((Level) levelBox.getSelectedItem());frame.setVisible(false); }
if (event.getSource().equals(menu)) {UserOptions.show();frame.setVisible(false);}
if (event.getSource().equals(levelBox)) {
levDescription.setText( ((Level)levelBox.getSelectedItem()).getDescription() );
levRunway.setText(String.valueOf( ((Level)levelBox.getSelectedItem()).getRunways() ));
levFreq.setText(String.valueOf(((Level)levelBox.getSelectedItem()).getFrequency() ) );
levAircraft.setText(String.valueOf( ((Level)levelBox.getSelectedItem()).getNumberOfAircraft() ));
}
}
//((Level)levelBox.getSelectedItem()).getDescription(),
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -