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

📄 atcsystem.java

📁 一个飞机调度员模拟训练程序,可以添加跑道数量,控制飞机飞行的速度.默认的密码可以在AtcSystem类里面修改,其中内置了三个用户名.这套系统是我和几个国外同学合力开发的,希望对大家有帮助
💻 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 ATCSystem implements ActionListener
{
    private static ATCSystem singleton;
    private User currentUser;

    private JButton ok;
    private JButton cancel;
    
    private JButton clear;
    
    private JButton left;
    private JButton right;
    private JButton queue;
    private JButton land;
    private JButton pause;
    private JButton menu;
    
    private JPasswordField password;
    private JComboBox username;
    
    private JFrame frame;
    
    
    

    private SpringLayout layout = new SpringLayout();
    
    public ATCSystem() 
    {
        singleton = this;
        
        load();
        
        frame = new JFrame();
    // MAKE THIS PRIVATE LATER
        
        frame.setSize(800,600);
        
        Container content = frame.getContentPane();        
        content.setLayout(layout);
        
        
        ok = new JButton("OK");
        content.add(ok);

        clear = new JButton("Clear");
        content.add(clear);
        
        cancel = new JButton("Exit");
        content.add(cancel);
              
        JLabel userLabel = new JLabel("User:");
        content.add(userLabel);
        
        Level level1 = new Level("Level One", "A First Level", 1, 2, 10);
        
        Level level2 = new Level("Level Two", "A Second Level", 2, 1.2F, 10);
        
        ArrayList<Result> test1 = new ArrayList<Result>();
        test1.add(new Result(level1, 4000, 3));
        
        ArrayList<Result> test2 = new ArrayList<Result>();
        test2.add(new Result(level1, 2500, 3));
        test2.add(new Result(level2, 6000, 4));
        User user1 = new User("bob", "pass", true, test1);

        User user2 = new User("fred", "pass2", false, test2);

        User user3 = new User("joe", "pass3", false, new ArrayList<Result>());


        
        username = new JComboBox();
        content.add(username);
        
         for (User u : User.users)
        {
            username.addItem(u);
        }
              
        JLabel passLabel = new JLabel("Password:");
        content.add(passLabel);
        password = new JPasswordField(5);
        content.add(password);
        
        ImageIcon pic = new ImageIcon("login.jpg");  //image used in the software is available in the public domain
        JLabel loginLabel = new JLabel("");
        loginLabel.setIcon(pic);
        content.add(loginLabel);
        
        JLabel welcomeLabel = new JLabel("Welcome: Please Log In");
        welcomeLabel.setFont(new Font(null,Font.BOLD,32));
        content.add(welcomeLabel);
        
        ok.addActionListener(this);
        clear.addActionListener(this);
        cancel.addActionListener(this);
        
        layout.putConstraint(SpringLayout.WEST, loginLabel, 200, SpringLayout.WEST, content);
        layout.putConstraint(SpringLayout.NORTH, loginLabel, 15, SpringLayout.NORTH, content);
        
        layout.putConstraint(SpringLayout.WEST, welcomeLabel, 215, SpringLayout.WEST, content);
        layout.putConstraint(SpringLayout.NORTH, welcomeLabel, 15, SpringLayout.SOUTH, loginLabel);
        
        layout.putConstraint(SpringLayout.WEST, username, 380, SpringLayout.WEST, content);
        layout.putConstraint(SpringLayout.NORTH, username, 30, SpringLayout.SOUTH, welcomeLabel);
        
        layout.putConstraint(SpringLayout.EAST, userLabel, -5, SpringLayout.WEST, username);
        layout.putConstraint(SpringLayout.NORTH, userLabel, 0, SpringLayout.NORTH, username);
        
        layout.putConstraint(SpringLayout.NORTH, password, 20, SpringLayout.SOUTH, username);
        layout.putConstraint(SpringLayout.WEST, password, 0, SpringLayout.WEST, username);
        
        layout.putConstraint(SpringLayout.EAST, passLabel, -5, SpringLayout.WEST, password);
        layout.putConstraint(SpringLayout.NORTH, passLabel, 0, SpringLayout.NORTH, password);
        
        
        

        
        
       
        

        layout.putConstraint(SpringLayout.NORTH, cancel, 500, SpringLayout.NORTH, content);
        layout.putConstraint(SpringLayout.EAST, cancel, -50, SpringLayout.EAST, content);
        
        layout.putConstraint(SpringLayout.EAST, clear, -20, SpringLayout.WEST, cancel);
        layout.putConstraint(SpringLayout.NORTH, clear, 0, SpringLayout.NORTH, cancel);
        
        layout.putConstraint(SpringLayout.EAST, ok, -20, SpringLayout.WEST, clear);
        layout.putConstraint(SpringLayout.NORTH, ok, 0, SpringLayout.NORTH, clear);
        
        
        
        
        
        
        
        frame.setTitle("Log in");
        
        frame.setLocationRelativeTo(null);       
        makeVisible();
    }

    public void update()
            {
                username.removeAllItems();
                         for (User u : User.users)
        {
            username.addItem(u);
        }
            }
    
    public void makeVisible()
    {
        frame.setVisible(true);
        frame.setResizable(false);         
    }
    
    public static void show()
    {
        if (!(singleton == null)) { singleton.makeVisible(); singleton.update();} else { singleton = new ATCSystem(); }
    }
    
    // Do something if a button is pressed
    public void actionPerformed(ActionEvent event) {
 
        if (event.getSource().equals(ok)) 
        { 
            if (  ((User) username.getSelectedItem()).checkPassword(String.valueOf(password.getPassword()))  )
            {
                currentUser = (User) username.getSelectedItem(); 
                if(currentUser.isAdmin()) { AdmMenu.show(); frame.setVisible(false);}//adminOptions();frame.setVisible(false); }
                else { UserOptions u = new UserOptions(); frame.setVisible(false);  }
            }
           else 
           {
             JOptionPane.showMessageDialog(frame, "Incorrect password", "Password incorrect", JOptionPane.ERROR_MESSAGE);
             password.setText("");
            }
        }
        if (event.getSource().equals(clear)) { password.setText(""); }
        if (event.getSource().equals(cancel)) { System.exit(0);frame.setVisible(false); }
        


    }
 
    
    public static User getCurrentUser()
    {
           return singleton.currentUser;
    }
    
    
    public void sim()
    {
        frame = new JFrame();
        JPanel mainPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        JPanel simPanel = new JPanel();
        
        frame.setContentPane(mainPanel);
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
        simPanel.setLayout(new BoxLayout(simPanel, BoxLayout.PAGE_AXIS));
        
        left = new JButton("Turn Left");
        right = new JButton("Turn Right");
        queue = new JButton("Queue");
        land = new JButton("Take Off/Land");
        pause = new JButton("Run/Pause");
        menu = new JButton("Menu");
        
        buttonPanel.add(left);
        buttonPanel.add(right);
        buttonPanel.add(queue);
        buttonPanel.add(land);
        buttonPanel.add(pause);
        buttonPanel.add(menu);
        
        left.addActionListener(this);
        right.addActionListener(this);
        queue.addActionListener(this);
        land.addActionListener(this);
        pause.addActionListener(this);
        menu.addActionListener(this);
        
        mainPanel.add(simPanel);
        mainPanel.add(buttonPanel);
        
        frame.setTitle("Level Selection");
        frame.pack();
        frame.setVisible(true);
    }
   
    public static void main(String[] arguments)
    {
        ATCSystem.show();
    }
    
    public void load()
     {
        String [] users = new String [1000];
        String [] levels = new String [100];
        File file = new File("H:\\");
        if (!file.exists())
        {
            System.out.println("User directory does not exist - create one!!!");
        }
        else
        {
          
            users   = file.list(new UserFilter());
            levels  = file.list(new LevelFilter());
        }
       
     
            
            for (int j = 0; j < users.length; j++)
            {
                
                String temp = users[j];
                int ln = temp.length();
                users[j] = (temp.substring(0, (ln - 4))).toLowerCase();
                ReadSequentialFile ATCRead = new ReadSequentialFile(users[j]);
                ATCRead.openFile();
                ATCRead.readATCRecords();
                ATCRead.closeFile();
                
            }
            
            for (int k = 0; k < levels.length; k++)
            {
                
                String tempLevel = levels[k];
                int lv = tempLevel.length();
                levels[k] = (tempLevel.substring(0, (lv - 4))).toLowerCase();
                ReadLevelSequentialFile ATCLevelRead = new ReadLevelSequentialFile(levels[k]);
                ATCLevelRead.openFile();
                ATCLevelRead.readATCRecords();
                ATCLevelRead.closeFile();
                
            }
       
            
            
    } 
   

    
    

}
    
    

⌨️ 快捷键说明

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