Java如何更改JFrame图像图标?
本示例演示如何使用该方法更改JFrame图像图标setIconImage()。
package org.nhooo.example.swing;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
public class FrameIconExample extends JFrame {
public static void main(String[] args) {
FrameIconExample frame = new FrameIconExample();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Set the window size and its title
frame.setSize(new Dimension(250, 250));
frame.setTitle("Frame Icon Example");
// Read the image that will be used as the application icon.
// Using "/" in front of the image file name will locate the
// image at the root folder of our application. If you don't
// use a "/" then the image file should be on the same folder
// with your class file.
try {
URL resource = frame.getClass().getResource("/logo.png");
BufferedImage image = ImageIO.read(resource);
frame.setIconImage(image);
} catch (IOException e) {
e.printStackTrace();
}
// Display the form
frame.setVisible(true);
}
}
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短