如何添加一张背景图片在Frame中? 硬盘上存有一张图片,假设其路径是"F:\\image.jpg",如何把这个图片设置为背景图片背景图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.awt.*;public class Hello extends JPanel { private Image backgroundImage; public Hello() { String path = "/Users/Biao/Desktop/x.png"; backgroundImage = new ImageIcon(path).getImage(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this); } private static void createGuiAndShow() { JFrame frame = new JFrame(""); frame.getContentPane().add(new Hello()); // Set frame's close operation and location in the screen. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { createGuiAndShow(); }} 楼主这些个问题可以直接百度GOOGLE得到答案的结果比单纯在这上面问快的多的 可以使用 SwingX里的 JXPanel + ImagePainter 任务管理器被JAVA代码禁用 java 继承问题 类型不匹配:不能从 String 转换为 Enumeration 麻烦谁能解释一下,输出结果为什么是这样的? 连接MSSQL2000数据库的问题 2003年软考答案 How to make a template for sysout the multi-localVal 一个简单的java拷贝文件问题,想不明白 用Hashtable class怎么定义表上限? 求教Spring配置文件声明的这段xml代码对程序的影响 一个未排序整数数组,有正负数,,,, SOCKET短连接的问题
import java.awt.*;public class Hello extends JPanel {
private Image backgroundImage; public Hello() {
String path = "/Users/Biao/Desktop/x.png";
backgroundImage = new ImageIcon(path).getImage();
} @Override
public void paintComponent(Graphics g) {
super.paintComponent(g); g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
} private static void createGuiAndShow() {
JFrame frame = new JFrame(""); frame.getContentPane().add(new Hello()); // Set frame's close operation and location in the screen.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} public static void main(String[] args) {
createGuiAndShow();
}
}
GOOGLE得到答案的结果比单纯在这上面问
快的多的