显示图片用什么控件比较好,怎么显示? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个比较麻烦,一般的话就是重写paint方法!用Jpanel,Jlabel空间的比较多!有什么不懂得可以给我发邮件,最近我刚研究的,呵呵![email protected] 看你的图片要怎么显示, 可以用JLabel, 也可以用JPanel的paintComponent把图片画在JPanel上.视情况而定. JLabel:JLabel lab_hm=new JLable();lab_hm.setOpaque(true);lab_hm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tp/3.gif")));JPanel:import java.awt.Graphics; import java.awt.Image; import java.net.MalformedURLException; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; class tt extends JPanel { private Image backgroundImage; tt() { URL url = null; try { url = new URL("http://www.yishujie.com/golo_pic/img/xinshang/picture/3837.jpg"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 从系统中加载图片 backgroundImage = new ImageIcon(url).getImage(); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (backgroundImage != null) { g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this); } } public static void main(String[] args) { JFrame f = new JFrame(); tt t = new tt(); f.add(t); f.setBounds(0, 0, 500, 400); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }我个人认为用JLabel好点 JLabel final JLabel label = new JLabel(); label.setIcon(new javax.swing.ImageIcon("Game_Back.jpg"));Game_Back.jpg放在项目文件一级目录下 JAVA的??? 研究研究~ java的从控制台接收数据的程序无法执行完毕(java核心技术上的一个程序) java读取vmg文件时遇到中文不能换行怎么解决 StringBuffer数据输出成txt文本 timertask问题 请教一个JAVA读文件目录的问题 如何将excel导入到oracle 关于SWT在MAC系统上移植的问题,急求! 请问大家,java中是怎么获得网卡地址的阿?在线等 问一个问题!!!! 怎样在一个文件中查找一个字符串? linux下jdk安装成功,但是输入“java”“javac”都显示 command not found 请老牛帮忙,雪地里狂等! 面向接口编程的好处和优点
[email protected]
视情况而定.
JLabel lab_hm=new JLable();
lab_hm.setOpaque(true);
lab_hm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tp/3.gif")));
JPanel:
import java.awt.Graphics;
import java.awt.Image;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel; class tt extends JPanel {
private Image backgroundImage; tt() {
URL url = null;
try {
url = new URL("http://www.yishujie.com/golo_pic/img/xinshang/picture/3837.jpg");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 从系统中加载图片
backgroundImage = new ImageIcon(url).getImage();
} @Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (backgroundImage != null) {
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
}
} public static void main(String[] args) {
JFrame f = new JFrame();
tt t = new tt();
f.add(t);
f.setBounds(0, 0, 500, 400);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
我个人认为用JLabel好点
final JLabel label = new JLabel();
label.setIcon(new javax.swing.ImageIcon("Game_Back.jpg"));
Game_Back.jpg放在项目文件一级目录下
研究研究~