java - When i run my jar-file in my html-code it won't work because of a RuntimeException -
i made jar-file of 3 classes make game. did this:
made manifest.mf file with: "mainclass: spel (two enters)" in. compiled java-files class-files.
and entered command in cmd:
jar cfm spel.jar manifest.mf spel.class spel$1.class spel$speltimertask.class
the jar-file created , when dubble click on it, works perfectly. when make html-code , try execute java applet runtimeexception, know why?
<html> <body> <applet archive="spel.jar" code="spel.class" width="600" height="400"></applet> </body> </html>
this de code of java-file:
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); } }
Comments
Post a Comment