java怎么画不上去图片
/**Tochangethistemplate,chooseTools|Templates*andopenthetemplateintheeditor.*/package...
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package mainGame;import java.awt.Graphics;import java.awt.Image;import java.awt.Toolkit;import javax.swing.JFrame;/** * * @author Administrator */public class draw1 extends JFrame{ Image a; public draw1(){ Toolkit toolkit=this.getToolkit(); toolkit.getImage("Circle_black.png"); toolkit.prepareImage(a, 200, 200, this); } public void paint(Graphics g) { g.drawImage(a, 200, 200, 50, 50, this); } public static void main(String[] args) { draw1 f=new draw1(); f.setSize(300, 200); f.setVisible(true); }}
展开
展开全部
我看了你的程序,只要
一、把toolkit.getImage("Circle_black.png");改成a=toolkit.getImage("Circle_black.png");
二、把g.drawImage(a, 200, 200, 50, 50, this);改成g.drawImage(a, 0, 0, 200, 200, this);
就行了。完整的程序如下:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package mainGame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
/** * * @author Administrator */
public class draw1 extends JFrame{
Image a;
public draw1(){
Toolkit toolkit=this.getToolkit();
a=toolkit.getImage("Circle_black.png");
toolkit.prepareImage(a, 200, 200, this);
}
public void paint(Graphics g) {
g.drawImage(a, 0, 0, 200, 200, this);
}
public static void main(String[] args) {
draw1 f=new draw1();
f.setSize(300, 200);
f.setVisible(true);
}
}
一、把toolkit.getImage("Circle_black.png");改成a=toolkit.getImage("Circle_black.png");
二、把g.drawImage(a, 200, 200, 50, 50, this);改成g.drawImage(a, 0, 0, 200, 200, this);
就行了。完整的程序如下:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package mainGame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
/** * * @author Administrator */
public class draw1 extends JFrame{
Image a;
public draw1(){
Toolkit toolkit=this.getToolkit();
a=toolkit.getImage("Circle_black.png");
toolkit.prepareImage(a, 200, 200, this);
}
public void paint(Graphics g) {
g.drawImage(a, 0, 0, 200, 200, this);
}
public static void main(String[] args) {
draw1 f=new draw1();
f.setSize(300, 200);
f.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询