myimage.java
来自「郑州市公交线路管理查询系统」· Java 代码 · 共 36 行
JAVA
36 行
package com.ljz.gongJiaoSearch;
import javax.swing.*;
import java.net.*;
import java.awt.*;
import java.io.Serializable;
public class MyImage extends JPanel implements Serializable{
private Image img;
private String imgName;
private boolean stretched;
private int x;
private int y;
public MyImage(String name){
this.setImgName(name);
}
public static Image creatImage(String imgName,Object obj){
URL url=obj.getClass().getResource(imgName);
return new ImageIcon(url).getImage();
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
if(img!=null)
g.drawImage(img,0,0,this.getWidth(),this.getHeight(),this);
}
public void setImgName(String s){
this.imgName=s;
img=this.creatImage(s,this);
repaint();
}
public void repaint(Graphics g){
super.paintComponent(g);
if(img!=null)
g.drawImage(img,0,0,this.getWidth(),this.getHeight(),this);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?