永发信息网

java 中Exception in thread "AWT-EventQueue-0" 大神们帮个忙,自学到绘图,出现的问题

答案:1  悬赏:0  手机版
解决时间 2021-02-07 10:27
  • 提问者网友:愿为果
  • 2021-02-07 01:14
package demon;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class fengzhuang extends JFrame {
mypanel mp=null;

public static void main(String[] args ){
fengzhuang n=new fengzhuang();
}
public fengzhuang(){
mp=new mypanel(92,90);
this.add(mp);
this.setSize(500, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

class mypanel extends JPanel{
hero hero=null;
public mypanel(int x,int y){
hero = new hero (x,y);
}
public void paint(Graphics g){
super.paint(g);

this.drawtank(hero.getX(), hero.getY(), g, 0, 1);
}
//
public void drawtank(int x,int y,Graphics g,int direct,int type){
type=1;
switch(type){
// 0 怪物
case 0:
g.setColor(Color.orange);
//头
g.fill3DRect(x, y, 15, 17, true);
//脸
g.setColor(Color.black);
g.fill3DRect(x+5, y+4, 3, 3, true);
g.fill3DRect(x+11, y+4, 3, 3, true);
g.drawLine(x+7, y+12, x+15, y+12);
// g.fill3DRect(x, y, width, height, true);
g.setColor(Color.pink);
//身子
g.fill3DRect(x-3, y+17, 21, 19, true);
g.setColor(Color.orange);
//右胳膊
g.fill3DRect(x+18, y+20, 6, 6, true);
//左胳膊
g.fill3DRect(x-3, y+20, 6, 6, true);
//两只脚
g.fill3DRect(x+1, y+36, 5, 15, true);
g.fill3DRect(x+9, y+36, 5, 15, true);
break;
case 1:
// 1 怪物
g.setColor(Color.cyan);
Image im=Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/1st.jpg"));
g.drawImage(im, 90, 90, 256,267, this);
break;
case 2:
break;
}
}
}

class tank{
int x=0;
public int getX(){
return x;
}
public void setX(){
this.x=x;
}
int y=0;
public int getY(){
return x;
}
public void setY(){
this.y=y;
}
public tank(int x,int y){
this.x=x;
this.y=y;
}
}

class hero extends tank{
public hero(int x,int y){
super(x,y);
}
}
最佳答案
  • 五星知识达人网友:过活
  • 2021-02-07 01:38
试试
Panel.class.getResource(
---->
this.getClass().getResource(

tank中的逻辑错误,就自己修改
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯