å 为å®çåçæ¯å¾çæ¯è¦çå¨æé®ä¸ï¼æ以å½å¾ççé¢ç§¯å°äºæé®çé¢ç§¯æ¶ï¼æé®çå
¶ä½é¨åå°±ä¼è¢«æ¾ç¤ºåºæ¥ãæåäºæ®µä»£ç æ¥ä¿®å¤è¿ä¸ªé®é¢ï¼å¾çæ好ä¸è¦æéæèæ¯çï¼å¦åå¾ççéæé¨åä¼è¢«æ¾ç¤ºæå¦ä¸å¾å¾çè¦çä¸å°çå°æ¹ï¼ã
代ç 使ç¨æ¹æ³æ¯
all a=new all(å¾çå°åï¼æé®ç宽度ï¼æé®çé«åº¦);
JButton jb=new JButton(a.back());
ä½ ä¹å¯ä»¥å§è¿æ®µä»£ç æå
æjarï¼ä»¥åéè¦ä½¿ç¨å°±ç´æ¥importå°±è¡äºã
class all {//allå¯ä»¥æ¹æå«çï¼ä½å¼ç¨æ¶æ³¨æ就好äºã
private int width,height;
private Image image=null;
private ImageIcon result=null;
public all(String path,int width,int height) {
result=new ImageIcon(path);
image=result.getImage();
this.width=width;
this.height=height;
design();
}
public void design(){
BufferedImage bi=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d=bi.createGraphics();
g2d.drawImage(image, 0, 0, width, height, null);
image=bi.getScaledInstance(width, height, Image.SCALE_SMOOTH);
result.setImage(image);
}
public ImageIcon back(){
return result;
}
}