📄 unwrappedimagepanel.java
字号:
package IrisRecog;
/**
* ImagePanel.java
*
* Extends the functionality of the JPanel swing component to be able to draw
* centered images in the panel. This class overrides the paintComponent method
* and handles its own drawing.
*
* @owner Michael Huffman
* @author Team 6: A. Bare, I. Chaugule,M. Huffman, M. Pearson, C. Schell
* @version 0.0.1
*
* CSC 480 Section 2
* Fall 2005
* 10/8/05
*
* Edit History:
* 10/8/05 - created
* 10/9/05 - documented and commented
*/
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class UnwrappedImagePanel extends JPanel
{
private Image img;
/**
* Creates an image panel with lowered bevel and white background.
*/
public UnwrappedImagePanel()
{
this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
this.setBackground(Constants.CLR_DEFAULT_BACKGROUND);
img = null;
}
public void setImage(Image i)
{
img = i;
this.repaint();
}
public void paintComponent(Graphics g)
{
//Clear the contents of the panel
g.clearRect(0, 0, this.getWidth(), this.getHeight());
//If the image of the panel has been set
if(img!=null)
{
ImageIcon scaledImage; //the image icon used to scale
double scaleFactor; //the percentage amount of scaling exhbited to fit in the panel
int yOffset; //the amount the image is shifted down to be centered vertically
scaledImage = new ImageIcon(img.getScaledInstance(this.getWidth(), -1, Image.SCALE_DEFAULT));
//Calculate the distance the image needs to be shifted down
yOffset = (this.getHeight() / 2) - (scaledImage.getIconHeight() / 2);
//Calculate the amount that the image is scaled
scaleFactor = (this.getWidth() * 1.0) / img.getWidth(null);
//Scale the image and paint it using the graphics object of this panel component
scaledImage.paintIcon(this, g, 0, yOffset);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -