?? imagepanel.java
字號:
// ImagePanel.java
// JPanel subclass for positioning and displaying ImageIcon
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 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 + -