java吧 关注:1,238,616贴子:12,709,015
  • 0回复贴,共1

新手求教,我这段代码哪里出错了,为什么画不出图象?

只看楼主收藏回复

package xiti;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Demo_3 extends JFrame{
ImagePanel jp=null;
public Demo_3(){
jp=new ImagePanel();
this.add(jp);
jp.setBackground(Color.gray);
this.setLocation(400, 10);
this.setSize(400, 600);
this.setVisible(true);
//this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Demo_3();
}
}
class ImagePanel extends JPanel{
Image ig1=null;
Image ig2=null;
public ImagePanel(){
ig1=Toolkit.getDefaultToolkit().getImage("yuxianjin/src/xiti/03.JPG");
//ig2=Toolkit.getDefaultToolkit().getImage("src/xiti/04.JPG");
}
public void paint(Graphics g){
super.paint(g);
g.drawImage(ig1, 400, 10,this);
}
}


IP属地:浙江1楼2015-11-02 08:27回复