Анимация - Java (241247)

Узнай цену своей работы

Формулировка задачи:

Создал спрайтовую анимацию Класс GameScreen
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.Timer;
import javax.swing.JPanel;
import java.awt.Toolkit;
import java.awt.Image;  
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
 
public class GameScreen extends JPanel {
        private static final long serialVersionUID = 1L;
       
         private Timer timer;
        
          public Image image;
          public Image image2;
          private int x = 40;
          private int y = 60;
          private int x1 = -30;
         public int b = 0;
              public int c;
              public Graphics2D g2d;
        public GameScreen(){

        ImageIcon ii = new ImageIcon(this.getClass().getResource("images/11.jpg"));
        image = ii.getImage();
        ImageIcon ii2 = new ImageIcon(this.getClass().getResource("images/22.jpg"));
        image2 = ii2.getImage();

        timer = new Timer(100, new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        timer.start();
        }
       
        public void paint(Graphics g) {
            b++;
            long a = 1;
        super.paint(g);
            try {
                Thread.sleep(350);
            } catch (InterruptedException ex) {
                Logger.getLogger(GameScreen.class.getName()).log(Level.SEVERE, null, ex);
            }
        g2d = (Graphics2D)g;
        if (b%2 == 0)
        {
            g2d.drawImage(image, x += 35, y, this);
        }
        
        if (b%2 != 0)
        {
            g2d.drawImage(image2, (x += 35) - 70, y - 30, this);
        }
 
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }
 public void update(Graphics g) {paint(g);
 
 }
        public void run() {
                GameScreen t1 = new GameScreen();
              new Thread((Runnable) t1).start();               
        }   
}
main
import javax.swing.JFrame;
 
public class Okno {
 
    JFrame frame;
 
        public Okno(){
            frame = new JFrame("Game window");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800,600);
            frame.setResizable(false);        
            frame.add(new GameScreen());
            frame.setVisible(true);
 
           }
 
        public static void main(String [] args){
             new Okno();
 
           }
    
}
Проект запускается делает не сколько шагов (кадров) и останавливается с ошибками Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet. at GameScreen$1.actionPerformed(GameScreen.java:45) at javax.swing.Timer.fireActionPerformed(Timer.java:313) at javax.swing.Timer$DoPostEvent.run(Timer.java:245) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) at java.awt.EventQueue$3.run(EventQueue.java:696) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:719) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Подскажите как исправить?

Решение задачи: «Анимация»

textual
Листинг программы
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 3.909 из 5