如何为应用程序中将存在的所有框架设置图标?
我不想使用frame.setIconImage(0);frame1.setIconImage(1);etc.
每次我创建框架时。

最好的祝福,
马雷克

最佳答案

制作一个扩展jframe的类。

public class customFrame extends JFrame{

    public customFrame() {
        try {
            this.setIconImage(ImageIO.read(new File("C:\\Users\\Madhawa.se\\Desktop\\gtg.PNG")));
        } catch (IOException ex) {
            Logger.getLogger(customFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


}


现在,当您创建jframe时,将扩展class [frame]而不是jframe。

喜欢跟着;

public class frame1 extends customFrame{
    public static void main(String[] args) {
        new frame1().setVisible(true);

    }
}


下一帧,依此类推。

public class frame2 extends customFrame{
    public static void main(String[] args) {
        new frame2().setVisible(true);

    }
}


而且您还可以制作如下的帧

public static void main(String[] args) {
    customFrame frame1 = new customFrame();
    frame1.setTitle("title");
    frame1.add(new JLabel(""));
    frame1.setVisible(true);
}

关于java - .setIconImage();到所有帧而不是一一,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26411898/

10-14 05:08