icondemo.java

来自「金旭亮的java教案」· Java 代码 · 共 35 行

JAVA
35
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class IconDemo {

    static JFrame jframe = new JFrame("Example");

    public static void setupjframe() {
        jframe.setSize(200,200);
        jframe.setVisible(true);
        jframe.getContentPane().setLayout( new FlowLayout() );

        WindowListener l = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        };
        jframe.addWindowListener(l);
    }

    public static void main(String[] args) {
        setupjframe();

	// alternatively, load the image from a file Toolkit 
	//Toolkit t = MyFrame.getToolkit(); 
	// Image FrameIcon = t.getImage(filename); 
 
        // this has to be an image that the OS
        // accepts as a suitable size for an icon
        ImageIcon ii = new ImageIcon("star.gif");
	jframe.setIconImage( ii.getImage() ); 
    }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?