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

📄 movingpanel.java

📁 用java模拟的电梯程序,可以选择有几层楼,一共有几个人在哪几层等电梯,可以不断的增加等电梯的人数,并看电梯如何以设定的方式运行.
💻 JAVA
字号:
// MovingPanel.java// JPanel subclass with on-screen moving capabilitiespackage com.Anance.elevator.view;// Java core packagesimport java.awt.*;import java.awt.geom.*;import java.util.*;// Java extension packagesimport javax.swing.*;public class MovingPanel extends ImagePanel {   // should MovingPanel change position?   private boolean moving;   // number of pixels MovingPanel moves in both x and y values   // per animationDelay milliseconds   private double xVelocity;   private double yVelocity;   // constructor initializes position, velocity and image   public MovingPanel( int identifier, String imageName )   {      super( identifier, imageName );      // set MovingPanel velocity      xVelocity = 0;      yVelocity = 0;   } // end MovingPanel constructor   // update MovingPanel position and animation frame   public void animate()   {      // update position according to MovingPanel velocity      if ( isMoving() ) {         double oldXPosition = getPosition().getX();         double oldYPosition = getPosition().getY();         setPosition( oldXPosition + xVelocity,            oldYPosition + yVelocity );      }      // update all children of MovingPanel      Iterator iterator = getChildren().iterator();      while ( iterator.hasNext() ) {         MovingPanel panel = ( MovingPanel ) iterator.next();         panel.animate();      }   } // end method animate   // is MovingPanel moving on screen?   public boolean isMoving()   {      return moving;   }   // set MovingPanel to move on screen   public void setMoving( boolean move )   {      moving = move;   }   // set MovingPanel x and y velocity   public void setVelocity( double x, double y )   {      xVelocity = x;      yVelocity = y;   }   // return MovingPanel x velocity   public double getXVelocity()   {      return xVelocity;   }   // return MovingPanel y velocity   public double getYVelocity()   {      return yVelocity;   }}

⌨️ 快捷键说明

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