📄 imagepanel.java
字号:
/*
*作者:梅玲
*日期:2007-3-1
*/
package newer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ImagePanel extends JPanel
implements ComponentListener
{
private String patch;
public ImagePanel()
{
jbInt();
}
public ImagePanel(String patch)
{
this.patch = patch;
jbInt();
}
private void jbInt()
{
this.addComponentListener(this);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
ImageIcon imgBackground = new ImageIcon(patch);
Image image = imgBackground.getImage();
g.drawImage(image,0,0,this.getWidth(),this.getHeight(),this);
}
public void setBackground(String patch)
{
this.patch = patch;
super.repaint();
this.repaint();
}
public void setBackground()
{
super.repaint();
this.repaint();
}
// 组件变得不可见时调用。
public void componentHidden(ComponentEvent e)
{
setBackground();
}
// 组件位置更改时调用。
public void componentMoved(ComponentEvent e)
{
setBackground();
}
//组件大小更改时调用。
public void componentResized(ComponentEvent e)
{
setBackground();
}
// 组件变得可见时调用。
public void componentShown(ComponentEvent e)
{
setBackground();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -