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

📄 liftcage.java

📁 模拟电梯运行的情况。该模拟软件能根据用户的要求同时生成N部电梯和M各楼层。能满足不同楼层对电梯的请求。
💻 JAVA
字号:
package a;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class LiftCage extends JPanel{
     
	int numOfFloor,heightOfFloor,floor=1,relativeHeight=0,currentHeight;
	
	int movement=0,widthUpBound,widthLowBound=1;
	
	 public LiftCage(int numOfFloor){
	    	this.numOfFloor=numOfFloor;
	    	//setBackground(Color.orange);
	    	
	 }         
	    
     protected void paintComponent(Graphics g){
 	   super.paintComponent(g);
 	 
 	   
 	   widthUpBound=getWidth()/2-10;
 	   
 	   
 	   int YPoint=getHeight()*(numOfFloor- floor)/numOfFloor+relativeHeight;
 	   heightOfFloor=getHeight()/numOfFloor;
 	   currentHeight=(floor-1)*heightOfFloor-relativeHeight;
 	  // g.setColor(Color.magenta);
 	  // g.draw3DRect(1,1,getWidth()-2,getHeight()-2,true);
 	   g.setColor(Color.lightGray);
 	   g.fillRect(3,YPoint,getWidth()-2,heightOfFloor-1);
 	   
 	   
 	   g.setColor(Color.blue);
	   g.fillRect(3,YPoint,getWidth()/2-3-movement,heightOfFloor);
	   g.fillRect(getWidth()/2+3+movement,YPoint,getWidth()/2-5-movement,heightOfFloor);
	   
	   g.setColor(Color.magenta);
 	   g.draw3DRect(1,1,getWidth()-2,getHeight()-2,true);
    }
     
     
 
     //电梯向上运行时画图 
    void moveUp(){
       relativeHeight--; 	 
       repaint();
    }

      
    //电梯向下运行时画图 
    void moveDown(){
      	relativeHeight++;
     	repaint();
    }
    
    void closeGate(){
		 movement--;
		 repaint();
	 }
	 
	 void openGate(){
		 //outTimer.stop();
		 movement++;
		 repaint();
	 }
}    
 

 

⌨️ 快捷键说明

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