本人是个菜鸟,正在做毕业设计项目,想把自已的项目搞得漂亮,但是对API又不太熟悉,请各位能给我支几招,怎么样做能达到意想不到的效果,或者说是特效,让人看了之后耳目一新的感觉,谢谢!

解决方案 »

  1.   

    public class Frame1 extends Frame {
        public Frame1() {
            try {
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    private void jbInit() throws Exception {
            Image img = Toolkit.getDefaultToolkit().createImage("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Blue hills.jpg");
            this.setIconImage(img);
            this.setVisible(true);
        }    public static void main(String[] args) {
            Frame1 frame1 = new Frame1();
        }
    }
      

  2.   

    谢谢你的回答,我在做项目时,还发现一个问题,就是往JLabel里插图片时,图片过大,只显示图片的一部分,要怎么样做调整呢?
      

  3.   

    学习 谢谢liujun999999(减肥中...)
      

  4.   

    用以下代码修改图片的大小,我算是服务到家了:private static String dir = "";
    private static String newDir = "";

    public static void zoomIconInDir(int width,int height){
    File dirFile = new File(dir);
    if(dirFile.exists() && dirFile.isDirectory()){
    File [] children = dirFile.listFiles();
    for(int i = 0; i<children.length; i++){
    zoomIcon(children[i].getName(),width,height);
    }
    }
    }
    public static Icon zoomIcon(String iconPath,int width,int height){
    File file = new File(dir+"\\"+iconPath);
    BufferedImage bi = null;
    try {
    bi = ImageIO.read(file);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    if(bi==null)return null;

    double wRatio = width/new Integer(bi.getWidth()).doubleValue();
    double hRatio = height/new Integer(bi.getHeight()).doubleValue();
    System.out.print(iconPath+" : ");
    System.out.println(wRatio+" "+hRatio);

    Image Itemp  =  bi.getScaledInstance (width,height,bi.SCALE_SMOOTH);
    AffineTransformOp op  =  new AffineTransformOp(AffineTransform.getScaleInstance(wRatio, hRatio), null);
    Itemp = op.filter(bi,null); 
        
    try{
        ImageIO.write((BufferedImage)Itemp,  "png" , new File(newDir+"\\"+iconPath));
    }catch  (Exception ex){
        System.out.println( " ######## here error :  "   +  ex);
    }
    return new ImageIcon(Itemp);
    }
    public static void main(String[] args){
             dir = "********";
             newDir = "*************";
    MethordSet.zoomIconInDir(24, 24);
    }//我想不用解释了吧,功能应该很明显才对。