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

📄 modulegui.java

📁 This example shows how to create a second window and also how to read and write from/to a text file
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 * This class is the main GUI for the ModuleClkass Application.
 * 
 * @author Ian Bradley 
 * @version 10/04/2007
 */
public class ModuleGUI extends JFrame implements ActionListener
{
	private ModuleFile module;
    
     private JPanel textOutput;
     private JScrollPane scroller;

    private JButton quitButton = new JButton("quit");
    private JButton newButton = new JButton("new");
    private JButton deleteButton = new JButton("delete");
    private JButton allButton = new JButton("list all");   
    private JButton findButton = new JButton("find");
    private JTextArea output = new JTextArea(30,30);

	/**
	 * Constructor for objects of class ModuleGUI
	 */
	public ModuleGUI(String moduleName)
	{
		super(moduleName);
        module = new ModuleFile(moduleName);
        makeFrame();
        showFrame();
	}

	   /**
     * basic setup for the frame
     */
    private void showFrame()
   {   
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
     setSize(500,350);
     setVisible(true);
   }
   
    /**
     * set up for this frame
     * 
     */
    private void makeFrame()
    {
        JPanel buttonPanel = new JPanel();
               
        buttonPanel.setLayout(new GridLayout(5,1,10,5));
        buttonPanel.setBorder(BorderFactory.createEtchedBorder());
        
        buttonPanel.add(allButton);
        buttonPanel.add(newButton);
        buttonPanel.add(deleteButton);
        buttonPanel.add(findButton);
        buttonPanel.add(quitButton);
        
        textOutput = new JPanel();
        textOutput.setLayout(new BorderLayout());
        textOutput.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        
        output.setEditable(false);
        scroller = new JScrollPane(output);     
        textOutput.add(scroller);
        
        add(buttonPanel,BorderLayout.WEST);
        add(textOutput,BorderLayout.CENTER);
        
        allButton.addActionListener(this);
        findButton.addActionListener(this);
        newButton.addActionListener(this);
        deleteButton.addActionListener(this);
        quitButton.addActionListener(this);
        
    }
   
    public void actionPerformed( ActionEvent ae)
    {
        String item = ae.getActionCommand(); 

        if (item.equals("list all"))
        {
            output.setText(module.getAllStudents());
        }
        else
        if (item.equals("find"))
        {
            String name = JOptionPane.showInputDialog(this,"Enter Student's Name",
                       "Student Search",JOptionPane.QUESTION_MESSAGE);   
            output.setText( module.searchByName(name));
        }
        else
        if (item.equals("new"))
        {
            
            newButton.setEnabled(false);
            deleteButton.setEnabled(false);    
            findButton.setEnabled(false);
            AddNewStudentGUI bookingForm = new AddNewStudentGUI(this);         
        }
        else
        if (item.equals("delete"))
        {
            newButton.setEnabled(false);
            deleteButton.setEnabled(false);
            String roomNumber = JOptionPane.showInputDialog ( this,
		      "Enter Student's Name",
		      "Delete a Student", 
                  JOptionPane.QUESTION_MESSAGE);
            output.setText( module.deleteFromModule( roomNumber ));
            newButton.setEnabled(true);
            deleteButton.setEnabled(true);
           
        }
        else
        if (item.equals("quit"))
        {
            module.saveModuleList();
            System.exit(0);
        }     
    }
    
   public void addNewStudent(String name,String id)
   {      
       resetButtons();
       output.setText(module.addStudent(name,id));
   }
   
   public void resetButtons()
   {
       newButton.setEnabled(true);
       deleteButton.setEnabled(true);    
       findButton.setEnabled(true);
    }
       
}

⌨️ 快捷键说明

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