movingpanel.java

来自「用java模拟的电梯程序,可以选择有几层楼,一共有几个人在哪几层等电梯,可以不断」· Java 代码 · 共 85 行

JAVA
85
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?