前置き
オーバーライドするとイメージ画像が表示されなくなりました。エラーは出ていません。参考書道理プログラムしたはずなのですが、原因が不明なので質問することにしました。
参考ではきっちり表示されているのに、
なぜ、イメージが表示されなくなっているのでしょうか?
ご教授願えないでしょうか。
※イメージファイルの名前は何度も確認しましたが合っています
Java
1import javax.swing.*; 2import javax.imageio.*; 3import java.io.*; 4import java.awt.*; 5import java.awt.event.*; 6import java.awt.image.*; 7public class aaa extends javax.swing.JApplet{ 8static Sprite ss; 9static TUPanel m_tup; 10 11public void init(){ 12 m_tup = new TUPanel(); 13 MyPanel(); 14 getContentPane().add(m_tup); 15} 16 17 18public void MyPanel(){ 19m_tup.setBackground(Color.RED); 20//JLabel jl = new JLabel("aa"); 21//add(jl); 22try { 23File file = new File("img_money.jpg"); 24ss = new Sprite(file, 100, 100, 100, 100); 25 26}catch(IOException e){ 27e.printStackTrace(); 28} 29} 30 31public void wmKeyDown(int code){ 32ss.move(code); 33repaint(); 34} 35 36public static void wmPaint(){ 37 whatcolor(Color.ORANGE); 38 fillRect(100,100,100,100); 39 draw(ss); 40 //next71 41} 42 43public static void draw(Sprite s){ 44 m_tup.draw(s); 45} 46public static void fillRect(int x,int y, int width, int height){ 47 m_tup.fillRect(x, y, width , height); 48} 49public static void whatcolor(Color c){ 50 m_tup.whatcolor(c); 51} 52}
Java
1import javax.swing.*; 2import javax.imageio.*; 3import java.awt.*; 4import java.awt.event.*; 5import java.awt.image.*; 6 7 8public class TUPanel extends JPanel{ 9 10static Graphics m_g; 11 12protected void processKeyEvent(KeyEvent e){ 13if(e.getID() == KeyEvent.KEY_PRESSED){ 14//int code = e.getKeyCode(); 15wmKeyDown(e.getKeyCode()); 16} 17} 18 19/* 20public void wmKeyDown(int code){ 21ss.move(code); 22repaint(); 23} 24*/ 25 26protected void paintComponent(Graphics g){ 27 super.paintComponent(g); 28 requestFocusInWindow(); 29 30 m_g = g; 31 wmPaint(); 32} 33 34public void wmKeyDown(int code){ 35 36} 37 38public static void wmPaint(){ 39 40aaa.wmPaint(); 41} 42 43public static void draw(Sprite s){ 44 s.draw(m_g); 45} 46 47public static void fillRect(int x,int y, int width, int height){ 48 m_g.fillRect(x, y, width , height); 49} 50 51public static void whatcolor(Color c){ 52 m_g.setColor(c); 53} 54 55 56}
Java
1import javax.swing.*; 2import javax.imageio.*; 3import java.io.*; 4import java.awt.*; 5import java.awt.event.*; 6import java.awt.image.*; 7 8 9public class Sprite{ 10BufferedImage m_bi; 11 int x; 12 int y; 13public Sprite(BufferedImage bi){ 14m_bi = bi; 15} 16public Sprite(BufferedImage bi, int x, int y, int w, int h){ 17m_bi = bi.getSubimage(x, y, w, h); 18} 19public Sprite(File file, int x, int y, int w, int h)throws IOException{ 20BufferedImage bi = ImageIO.read(file); 21m_bi = bi.getSubimage(x, y, w, h); 22} 23 24public void draw(Graphics g){ 25g.drawImage(m_bi,x,y,null); 26} 27 28 29 30public void move(int kc){ 31if(kc == KeyEvent.VK_RIGHT){ 32 x +=32; 33} 34else if(kc == KeyEvent.VK_LEFT){ 35 x -=32; 36} 37else if(kc == KeyEvent.VK_UP){ 38 y -=32; 39} 40else if(kc == KeyEvent.VK_DOWN){ 41 y +=32; 42} 43} 44 45}
あなたの回答
tips
プレビュー