求助:java ImageIcon 加入图片不能显示的问题
importjavax.swing.*;importjava.awt.*;publicclassPrintDemo{publicstaticvoidmain(String...
import javax.swing.*;
import java.awt.*;
public class PrintDemo{
public static void main(String[] args){
PaintFrame frm = new PaintFrame();
frm.setVisible(true);
}
}
class PaintFrame extends JFrame{
PaintFrame(){
setBounds(200,300,540,450);
PaintPanel p = new PaintPanel();
add(p);
}
class PaintPanel extends JPanel{
public void paintComponet(Graphics g){
Image image = new ImageIcon("C:\\Users\\Administrator\\Desktop\\3.jpg").getImage();
g.drawImage(image, 10, 20, this);
}
}
} 展开
import java.awt.*;
public class PrintDemo{
public static void main(String[] args){
PaintFrame frm = new PaintFrame();
frm.setVisible(true);
}
}
class PaintFrame extends JFrame{
PaintFrame(){
setBounds(200,300,540,450);
PaintPanel p = new PaintPanel();
add(p);
}
class PaintPanel extends JPanel{
public void paintComponet(Graphics g){
Image image = new ImageIcon("C:\\Users\\Administrator\\Desktop\\3.jpg").getImage();
g.drawImage(image, 10, 20, this);
}
}
} 展开
2个回答
2016-09-03
展开全部
image要先加载好 。。。。。。。。。。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询