Advertisement
salsadontcare

Java GIF not working

Apr 8th, 2023
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import javax.imageio.*;
  5. import java.io.*;
  6. import java.util.Objects;
  7.  
  8.  
  9. public class CheckersGame extends JPanel implements MouseListener, MouseMotionListener {
  10.  
  11.  
  12.     Image title;
  13.  
  14.  
  15.  
  16.     // This is where I create the gif variable
  17.     Image birds;
  18.  
  19.  
  20.  
  21.     int screen = 1;
  22.  
  23.     public CheckersGame(){
  24.  
  25.  
  26.         addMouseListener(this);
  27.         addMouseMotionListener(this);
  28.  
  29.  
  30.         try{
  31.             title = ImageIO.read(Objects.requireNonNull(getClass().getResource("resources/images/TitleScreenRocks.jpg")));
  32.  
  33.  
  34.  
  35.             // This is where I import the gif
  36.             birds = Toolkit.getDefaultToolkit().getImage(("resources/images/BirdsGif.gif"));
  37.  
  38.  
  39.  
  40.         }
  41.         catch (IOException e){
  42.             System.out.print("Image not found.");
  43.         }
  44.  
  45.  
  46.     }
  47.  
  48.     public void paint(Graphics g){
  49.         if (screen == 1){
  50.             startScreen(g);
  51.         }
  52.     }
  53.  
  54.     public void startScreen(Graphics g){
  55.         g.drawImage(title,0,0,null);
  56.  
  57.  
  58.  
  59.         // This is where I draw the gif
  60.         g.drawImage(birds, 400, 400, null);
  61.  
  62.  
  63.  
  64.     }
  65.  
  66.  
  67.     @Override
  68.     public void mouseClicked(MouseEvent e) {}
  69.  
  70.     @Override
  71.     public void mousePressed(MouseEvent e) {}
  72.  
  73.     @Override
  74.     public void mouseReleased(MouseEvent e) {}
  75.  
  76.     @Override
  77.     public void mouseEntered(MouseEvent e) {}
  78.  
  79.     @Override
  80.     public void mouseExited(MouseEvent e) {}
  81.  
  82.     @Override
  83.     public void mouseDragged(MouseEvent e) {}
  84.  
  85.     @Override
  86.     public void mouseMoved(MouseEvent e) {}
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement