在窗体中,java显示图片怎么做
展开全部
下面是一个JAVA显示图片的例子,请参考:
package com.tarena.java;
import t.Image;
import .File;
import .IOException;
import ageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* 加载显示图象,需要JDK1.5或以上
*/
public class showtu extends JFrame {
public showtu(String bmpFile) {
Image image = null;
try {
image = ad(new File(bmpFile));
} catch (IOException ex) {
}
JLabel label = new JLabel(new ImageIcon(image));
add(label);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
public static void main(String[] args){
final String fileName = "F:\\456备用\\亮个相.JPG"; //换成你要显示的图片
vokeLater(new Runnable(){
public void run(){
new showtu(fileName).setVisible(true);
}
});
}
}
package com.tarena.java;
import t.Image;
import .File;
import .IOException;
import ageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* 加载显示图象,需要JDK1.5或以上
*/
public class showtu extends JFrame {
public showtu(String bmpFile) {
Image image = null;
try {
image = ad(new File(bmpFile));
} catch (IOException ex) {
}
JLabel label = new JLabel(new ImageIcon(image));
add(label);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
public static void main(String[] args){
final String fileName = "F:\\456备用\\亮个相.JPG"; //换成你要显示的图片
vokeLater(new Runnable(){
public void run(){
new showtu(fileName).setVisible(true);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询