📄 mylabel.java
字号:
import java.awt.*;
public class MyLabel extends Label{
ImageIcon icon=new ImageIcon();
int x=0,y=0;
Graphics g;
public MyLabel(){
this.g=getGraphics();
}
public void setIcon(ImageIcon ic){
super.setIcon(ic);
this.icon=ic;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if(icon!=null){
//System.out.println("paint");
//g.drawImage(icon.getImage(),this.x,this.y,icon.getIconWidth()+this.x,icon.getIconHeight()+this.y,this);
}
}
public void run(){
for(int i=0;i<50;i++){
this.x=10;
if(this.getGraphics()==null) System.out.println("wrong");
System.out.println(icon.getIconWidth());
System.out.println(icon.getIconHeight());
g.drawImage(icon.getImage(),this.x,this.y,icon.getIconWidth(),icon.getIconHeight(),this);
repaint();
//System.out.println("run:");
this.x=0;
g.drawImage(icon.getImage(),this.x,this.y,this);
repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -