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

📄 imagepanel.java

📁 java JTree的简单应用 供初学者参考!
💻 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 + -