Когда я запускаю свой jar-файл в моем html-коде, он не работает из-за RuntimeException

0

Я сделал jar файл из трех классов, которые вместе создают игру. Я сделал это так:

Создал файл manifest.mf с: "MainClass: Spel (two enters)" in. Скомпилировал мои java файлы в файлы классов.

и ввел эту команду в мой cmd:

jar cfm Spel.jar manifest.mf Spel.class Spel $ 1.class Spel $ SpelTimerTask.class

Создан jar файл, и когда я нажимаю на него, он работает отлично. Но когда я делаю свой html-код таким образом и пытаюсь выполнить свой Java-апплет, я получаю исключение RuntimeException, знает ли кто-нибудь почему?

<html>
<body>
<applet archive="Spel.jar" code="Spel.class" width="600" height="400"></applet>
</body>
</html>
  • 3
    Что такое сообщение об исключении?
  • 0
    java.lang.reflect.InvocationTargetException
Показать ещё 4 комментария
Теги:
jar
runtimeexception
applet

1 ответ

0

это код моего java файла:

import java.util.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Spel extends JPanel implements KeyListener {

    public Rectangle screen, ball, block;
    public Rectangle bounds;
    public JFrame frame;
    public SpelTimerTask spelTask;
    public boolean down, right, starten = false;
    public JButton start;
    public int counter = 0;
    public JLabel score;
    public static int speed = 30;
    public static java.util.Timer spelTimer;
    public static Spel panel;

    public Spel(){
        super();
        screen = new Rectangle(0, 0, 600, 400);
        ball   = new Rectangle(0, 0, 20, 20);
        bounds = new Rectangle(0, 0, 600, 400);
        block = new Rectangle(bounds.width/2, bounds.height-50, 40, 10);
        frame = new JFrame("Super tof spel van Stan \u00a9");
        spelTask = new SpelTimerTask();
        score = new JLabel("0");
        score.hide();
        add(score);
        addKeyListener(this);
        setFocusable(true);
        start = new JButton("Start");
        start.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                starten = true;
                ball   = new Rectangle(0, 0, 20, 20);
                start.setFocusable(false);
                start.hide();
                score.show();
            }
        });
        add(start);
    }

    class SpelTimerTask extends TimerTask{
        public void run(){
            repaint();

            if(starten){
            moveBall();
            frame.repaint();
            }
        }
      }

      public void paintComponent(Graphics g){
        bounds = g.getClipBounds();
        g.clearRect(screen.x, screen.y, screen.width, screen.height);
        g.fillRect(ball.x, ball.y, ball.width, ball.height);
        g.fillRect(block.x, block.y, block.width, block.height);
      }

      public void moveBall(){
        if (right) ball.x+=3;
        else ball.x-=3;

        if (down)  ball.y+=3;
        else ball.y-=3;

        if (ball.x > (bounds.width - ball.width)) {
            right = false; 
            ball.x = bounds.width -  ball.width; 
        }

        if (ball.y >= (bounds.height - ball.height - 10) && ball.y <= (bounds.height - ball.height) && ball.x > block.x-20 && ball.x < block.x+40) { 
            down  = false; 
            ball.y = bounds.height - ball.height - 10;
            counter++;
            if(speed > 10){
                faster();
            }
            if(speed <= 10 && speed > 7 && counter % 5 == 0) {
                faster();
            }
            if(speed <= 7 && speed > 5 && counter % 10 == 0){
                faster();
            }
        }

        if (ball.y > (bounds.height - ball.height)) {
            start.show();
            score.hide();
            counter = 0;
        }

        if (ball.x <= 0) { 
            right = true; 
            ball.x = 0; 
        }

        if (ball.y <= 0){ 
            down  = true; 
            ball.y = 0; 
        }

        block.y = bounds.height-10;
        score.setText(Integer.toString(counter));
      }

      public void keyPressed(KeyEvent evt) {
          if(evt.getKeyCode() == KeyEvent.VK_LEFT && block.x > 0) {
              block.x -= 20;
          }

          if(evt.getKeyCode() == KeyEvent.VK_RIGHT && block.x < (bounds.width - block.width - 20)) {
              block.x += 20;
          }
      }

      public void keyTyped(KeyEvent evt){  }
      public void keyReleased(KeyEvent evt){ }

      public void startActionPerformed(java.awt.event.ActionEvent evt) {
            starten = true;
            speed = 10;
            panel.spelTask.cancel();
            panel.spelTask = new SpelTimerTask();
            spelTimer.schedule(panel.spelTask, 0, speed);
      }

      public void faster() {
        speed -= 1;
        panel.spelTask.cancel();
        panel.spelTask = new SpelTimerTask();
        spelTimer.schedule(panel.spelTask, 0, speed);
      }

      public static void main(String arg[]){
        spelTimer = new java.util.Timer();
        panel = new Spel();

        panel.down = true;
        panel.right = true;

        panel.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel.frame.setSize(panel.screen.width, panel.screen.height);
        panel.frame.setContentPane(panel); 
        panel.frame.setVisible(true);

        spelTimer.schedule(panel.spelTask, 0, speed);
      }
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню