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

📄 statuspanel.java

📁 A part public bus simulation system, mainly about map design, java file, groupwork, helpful to the b
💻 JAVA
字号:

package GUI;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

import tools.Tools.*;

//StatusPanel Class
public class StatusPanel extends JPanel{
	
    //Integer variable to indicate Tool in use/selected
    private int selectedTool;

    //Definition of constant integers representing each editable Tool
    //private static final int ROAD = 3;
    private static final int BUS_ROUTE = 18;

    private String propValue;	//Current value of the editable property
	
    private CmeGUI frame;
    
    //GridBagLayout Component used for layout
    GridBagConstraints gridBagConstraints;
    
    //JComponents for the StatusPanel
    private JLabel propertyLabel;	//Label for the panel
    private JLabel objectName;		//Label to indicate type of Object selected
    private JLabel propertyName;	//Label to indicate property of the Object
    private JTextField editProperty;    //Display of current property value
    private JSeparator separator1;	//Separates property fields & status display
    private JTextArea status;		//Displays status messages from system
    private JTextArea mousePos;		//Displays current mouse position
    private JPanel empty;		//Empty panel to aid layout organisation
    
    //##################### CONSTRUCTOR #####################
    public StatusPanel(CmeGUI parent){
    	super();
    	frame = parent;
    	
    empty = new JPanel();
    propertyLabel = new JLabel();
    objectName = new JLabel();
    propertyName = new JLabel();
    editProperty = new JTextField();
    separator1 = new JSeparator();
    status = new JTextArea();
    mousePos = new JTextArea();
    
    //Property Panel Layout and Size Specifications
    setLayout(new GridBagLayout());
    setPreferredSize(new Dimension(600, 72));
                
    //Property Label Specifications
    propertyLabel.setText("  Property of");	//Used to label Property Panel
        
    //Adding Property Label to Property Panel 
    gridBagConstraints = new GridBagConstraints();       
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    //gridBagConstraints.gridwidth = 2;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    add(propertyLabel, gridBagConstraints);

	//Object Name Layout and Size Specifications
    objectName.setMaximumSize(new Dimension(200, 20));
    objectName.setMinimumSize(new Dimension(200, 20));
    objectName.setPreferredSize(new Dimension(200, 20));
     
    //Adding Object Name to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 1;
    add(objectName, gridBagConstraints);

	//Property Name Layout and Size Specifications
    propertyName.setMaximumSize(new Dimension(100, 20));
    propertyName.setMinimumSize(new Dimension(100, 20));
    propertyName.setPreferredSize(new Dimension(100, 20));
        
    //Adding Property Name to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    add(propertyName, gridBagConstraints);

	//Edit Property Layout and Size Specifications
    editProperty.setMaximumSize(new Dimension(200, 20));
    editProperty.setMinimumSize(new Dimension(200, 20));
    editProperty.setPreferredSize(new Dimension(200, 20));
    editProperty.setEditable(false);
    editProperty.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            propertyInputChanged(evt);
        }
    });
        
    //Adding Edit Property to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    add(editProperty, gridBagConstraints);
        
    //Adding Separator to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    add(separator1, gridBagConstraints);

	//Mouse Position Display Layout and Size Specifications
    mousePos.setBackground(new Color(204, 204, 204));
    mousePos.setMinimumSize(new Dimension(150, 30));
    mousePos.setMaximumSize(new Dimension(150, 30));
    mousePos.setPreferredSize(new Dimension(150, 30));
    mousePos.setEditable(false);
        
    //Adding Status Display to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    add(mousePos, gridBagConstraints);
	
	//Status Display Layout and Size Specifications
    status.setBackground(new Color(204, 204, 204));
    status.setMinimumSize(new Dimension(438, 30));
    status.setMaximumSize(new Dimension(438, 30));
    status.setPreferredSize(new Dimension(1000, 30));
    status.setEditable(false);
        
    //Adding Status Display to Property Panel
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    add(status, gridBagConstraints);

	//Empty Panel Layout and Size Specifications
	empty.setBorder(new EmptyBorder(0,0,0,0));
		
	//Adding Empty Panel to Property Panel
	gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    add(empty, gridBagConstraints);   
        
    }//End of Constructor
    
    //##################### METHOD DEFINITIONS #####################
     
    //##################### EDIT PROPERTY METHODS ##################### 
    
    //setPropertyValue()
    //To get the current value of the editable property for display
    public void setPropertyValue(String currentValue)
    { 
    	propValue = currentValue;
    	editProperty.setText(propValue);
    }
    
    //setSelected()
    //Indicates which Object mode the system is in and displays the Object 
    //attributes accordingly, allows editing of the editProperty field if Object 
    //has an editable attribute
    public void setSelected(int select){
    	
    	switch(select)
    	{

    /*		case ROAD:{ 	//Display current Object attributes and allow
    							//modification
    							editProperty.setEditable(true);
    						  	editProperty.setText(propValue);
    							objectName.setText("Road");
    							propertyName.setText("  Road Name");
    						}
    			break; */
    		
    			
    		case BUS_ROUTE:	{ 	//Display current Object attributes and allow
    							//modification
    							editProperty.setEditable(true);
    						  	editProperty.setText(propValue);
    							objectName.setText("Bus Route");
    							propertyName.setText("  Route Number");
    							
    						}
    			break;
    		default:{	//Display nothing and disallow editing in text field
    					editProperty.setEditable(false);
    					editProperty.setText(" ");
    					objectName.setText(" ");
    					propertyName.setText(" ");
    					   
    				}
    			break;
    	}
    }
    
    //propertyInputChanged()
    //Detects that the editProperty field has been changed and assigns the new
    //of the property to file
    private void propertyInputChanged(ActionEvent evt) {
 //   	frame.setSelectedValue(editProperty.getText());
    }//End of propertyInputChanged()
    
    //##################### SYSTEM DISPLAY METHODS #####################
      
    //setStatus()
    //Changes the system output message displayed in the Status Display
    public void setStatus(String string) {
    	status.setText(string);
    }//End of setStatus()

	//setCoordinates()
	//Changes the mouse position coordinates displayed in the Status Display
	public void setCoordinates(Point pt) {
		mousePos.setText("Current Location: (" + (int)pt.getX() + "," + 
							(int)pt.getY() + ")");
	}//End of setCoordinates()
   
}//End of StatusPanel Class

⌨️ 快捷键说明

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