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

📄 imagepanel.java

📁 用java模拟的电梯程序,可以选择有几层楼,一共有几个人在哪几层等电梯,可以不断的增加等电梯的人数,并看电梯如何以设定的方式运行.
💻 JAVA
字号:
// ImagePanel.java// JPanel subclass for positioning and displaying ImageIconpackage com.Anance.elevator.view;// Java core packagesimport java.awt.*;import java.awt.geom.*;import java.util.*;// Java extension packagesimport javax.swing.*;public class ImagePanel extends JPanel {   // identifier   private int ID;   // on-screen position   private Point2D.Double position;   // imageIcon to paint on screen   private ImageIcon imageIcon;   // stores all ImagePanel children   private Set panelChildren;   // constructor initializes position and image   public ImagePanel( int identifier, String imageName )   {      super( null ); // specify null layout      setOpaque( false ); // make transparent      // set unique identifier      ID = identifier;      // set location      position = new Point2D.Double( 0, 0 );      setLocation( 0, 0 );      // create ImageIcon with given imageName      imageIcon = new ImageIcon(         getClass().getResource( imageName ) );      Image image = imageIcon.getImage();      setSize(          image.getWidth( this ), image.getHeight( this ) );      // create Set to store Panel children      panelChildren = new HashSet();   } // end ImagePanel constructor   // paint Panel to screen   public void paintComponent( Graphics g )   {      super.paintComponent( g );      // if image is ready, paint it to screen      imageIcon.paintIcon( this, g, 0, 0 );   }   // add ImagePanel child to ImagePanel   public void add( ImagePanel panel )   {      panelChildren.add( panel );      super.add( panel );   }   // add ImagePanel child to ImagePanel at given index   public void add( ImagePanel panel, int index )   {      panelChildren.add( panel );      super.add( panel, index );   }   // remove ImagePanel child from ImagePanel   public void remove( ImagePanel panel )   {      panelChildren.remove( panel );      super.remove( panel );   }   // sets current ImageIcon to be displayed   public void setIcon( ImageIcon icon )   {      imageIcon = icon;   }   // set on-screen position   public void setPosition( double x, double y )   {      position.setLocation( x, y );      setLocation( ( int ) x,  ( int ) y );   }   // return ImagePanel identifier   public int getID()   {      return ID;   }   // get position of ImagePanel   public Point2D.Double getPosition()   {      return position;   }   // get imageIcon   public ImageIcon getImageIcon()   {      return imageIcon;   }   // get Set of ImagePanel children   public Set getChildren()   {      return panelChildren;   }}

⌨️ 快捷键说明

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