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

📄 movingpanel.java

📁 JAVA 多线程不可多得的好例子
💻 JAVA
字号:
// MovingPanel.java
// JPanel subclass with on-screen moving capabilities
package com.deitel.jhtp5.elevator.view;

// Java core packages
import java.awt.*;
import java.awt.geom.*;
import java.util.*;

// Java extension packages
import 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 + -