$
$$Money$$
Hallo,
ich habe folgendes Problem ich habe ein Applet, zu beginn werden 4 Bilder geladen die dann auch angezeigt werden sollen. Leider werden sie nicht angezeigt...
Applet Code:
und hier noch das applet auf dem Server...
http://
www.gostelithomas.bplaced.net/carcrash/start.html
Wäre sehr für eure Hilfe dankbar...
MfG
ich habe folgendes Problem ich habe ein Applet, zu beginn werden 4 Bilder geladen die dann auch angezeigt werden sollen. Leider werden sie nicht angezeigt...
Applet Code:
Java:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.util.EventObject.*;
public class carcrash_applet extends Applet {
Bildleinwand Leinwand;
Image b_street;
Image b_car;
Image b_police;
Image b_over;
JLabel label1;
Random generator = new Random();
double police_speed = 2.0;
double police_speed2 = 2.0;
double police_speed3 = 2.0;
int police_xpos;
int police_ypos;
int police_xpos2;
int police_ypos2;
int police_xpos3;
int police_ypos3;
int car_xpos = 225;
int car_ypos = 222;
int street_xpos = 0;
int street_ypos = 0;
int points = 0;
polizei t = new polizei();
polizei2 t2 = new polizei2();
polizei3 t3 = new polizei3();
boolean flag = true;
boolean flag2 = true;
public carcrash_applet() {
setLayout(null);
Leinwand = new Bildleinwand();
Leinwand.setBounds(0,0,480,272);
JButton button1 = new JButton("Neues Spiel");
button1.setBounds(480,100,120,25);
button1.setFocusable(false);
JButton button2 = new JButton("Pause");
button2.setBounds(480,130,120,25);
button2.setFocusable(false);
JButton button3 = new JButton("Fortsetzen");
button3.setBounds(480,160,120,25);
button3.setFocusable(false);
label1 = new JLabel("Punkte: "+points);
label1.setBounds(480,100,10,25);
add(button1);
add(button2);
add(button3);
add(Leinwand);
add(label1);
button1.addActionListener(new ActionLauscher());
button2.addActionListener(new ActionLauscher());
button3.addActionListener(new ActionLauscher());
Leinwand.repaint();
}
public void init() {
//Wird beim Laden des Applets aufgerufen
Image b_street = getImage(getCodeBase(),"img/street.png");
Image b_car = getImage(getCodeBase(),"img/car.png");
Image b_police = getImage(getCodeBase(),"img/police.png");
Image b_over = getImage(getCodeBase(),"img/over.png");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(b_street,0);
tracker.addImage(b_car,1);
tracker.addImage(b_police,2);
tracker.addImage(b_over,3);
try{
tracker.waitForID(0);
tracker.waitForID(1);
tracker.waitForID(2);
tracker.waitForID(3);
} catch(InterruptedException e){}
while(true){
police_xpos = generator.nextInt(190);
if(police_xpos < 105){
continue;
}
break;
}
while(true){
police_xpos2 = generator.nextInt(275);
if(police_xpos2 < 190){
continue;
}
break;
}
while(true){
police_xpos3 = generator.nextInt(350);
if(police_xpos3 < 275){
continue;
}
break;
}
while(true){
police_ypos = generator.nextInt(300);
if(police_ypos < 60){
continue;
}
police_ypos = police_ypos/-1;
break;
}
while(true){
police_ypos2 = generator.nextInt(300);
if(police_ypos2 < 60){
continue;
}
police_ypos2 = police_ypos2/-1;
break;
}
while(true){
police_ypos3 = generator.nextInt(300);
if(police_ypos3 < 60){
continue;
}
police_ypos3 = police_ypos3/-1;
break;
}
}
public void start() {
//Wird beim Start des Applets aufgerufen
t.start();
t2.start();
t3.start();
move();
}
public void stop() {
//Wird beim Beenden des Applets aufgerufen
}
public void destroy() {
//Lädt das Applet aus dem RAM
}
class Bildleinwand extends JPanel {
public void paint(Graphics g) {
super.paint(g);
g.drawImage(b_street,street_xpos,street_ypos,480,272, this);
g.drawImage(b_car,car_xpos,car_ypos,25,50, this);
g.drawImage(b_police,police_xpos,police_ypos,26,50,this);
g.drawImage(b_police,police_xpos2,police_ypos2,26,50,this);
g.drawImage(b_police,police_xpos3,police_ypos3,26,50,this);
Rectangle r1 = new Rectangle(26, 50);
Rectangle r2 = new Rectangle(26, 50);
Rectangle r3 = new Rectangle(26, 50);
r1.translate(police_xpos, police_ypos);
r2.translate(police_xpos2, police_ypos2);
r3.translate(police_xpos3, police_ypos3);
Rectangle r4 = new Rectangle(25, 50);
r4.translate(car_xpos, car_ypos);
if (r1.intersects(r4)){
flag2 = false;
g.drawImage(b_over,0,0,480,272,this);
}
if (r2.intersects(r4)){
flag2 = false;
g.drawImage(b_over,0,0,480,272,this);
}
if (r3.intersects(r4)){
flag2 = false;
g.drawImage(b_over,0,0,480,272,this);
}
}
}
public void neu() {
while(true){
police_xpos = generator.nextInt(190);
if(police_xpos < 105){
continue;
}
break;
}
while(true){
police_xpos2 = generator.nextInt(275);
if(police_xpos2 < 190){
continue;
}
break;
}
while(true){
police_xpos3 = generator.nextInt(350);
if(police_xpos3 < 275){
continue;
}
break;
}
while(true){
police_ypos = generator.nextInt(300);
if(police_ypos < 60){
continue;
}
police_ypos = police_ypos/-1;
break;
}
while(true){
police_ypos2 = generator.nextInt(300);
if(police_ypos2 < 60){
continue;
}
police_ypos2 = police_ypos2/-1;
break;
}
while(true){
police_ypos3 = generator.nextInt(300);
if(police_ypos3 < 60){
continue;
}
police_ypos3 = police_ypos3/-1;
break;
}
car_xpos = 225;
car_ypos = 222;
police_speed = 2.1;
police_speed2 = 2.1;
police_speed3 = 2.1;
points = 0;
flag = true;
flag2 = true;
polizei t = new polizei();
polizei2 t2 = new polizei2();
polizei3 t3 = new polizei3();
Leinwand.repaint();
}
class ActionLauscher implements ActionListener {
public void actionPerformed(ActionEvent e) {
String label;
label = e.getActionCommand();
if(label.equals("Neues Spiel")){
neu();
}
if(label.equals("Pause")){
flag = false;
}
if(label.equals("Fortsetzen")){
flag = true;
}
}
}
class polizei extends Thread{
public void run(){
while (police_ypos < 320) {
if(flag && flag2){
police_ypos += police_speed;
if(police_ypos >=320){
while(true){
police_ypos = generator.nextInt(300);
if(police_ypos < 60){
continue;
}
police_ypos = police_ypos/-1;
break;
}
while(true){
police_xpos = generator.nextInt(190);
if(police_xpos <105){
continue;
}
break;
}
police_speed += 0.12;
points++;
label1.setText("Punkte: "+points);
}
Leinwand.repaint();
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
interrupt();
}
}}
}
}
class polizei2 extends Thread{
public void run(){
while (police_ypos2 < 320) {
if(flag && flag2){
police_ypos2 += police_speed2;
if(police_ypos2 >=320){
while(true){
police_ypos2 = generator.nextInt(300);
if(police_ypos2 < 60){
continue;
}
police_ypos2 = police_ypos2/-1;
break;
}
while(true){
police_xpos2 = generator.nextInt(275);
if(police_xpos2 <190){
continue;
}
break;
}
police_speed2 += 0.12;
points++;
label1.setText("Punkte: "+points);
}
Leinwand.repaint();
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
interrupt();
}
}}
}
}
class polizei3 extends Thread{
public void run(){
while (police_ypos3 < 320) {
if(flag && flag2){
police_ypos3 += police_speed3;
if(police_ypos3 >=320){
while(true){
police_ypos3 = generator.nextInt(300);
if(police_ypos3 < 60){
continue;
}
police_ypos3 = police_ypos3/-1;
break;
}
while(true){
police_xpos3 = generator.nextInt(350);
if(police_xpos3 <275){
continue;
}
break;
}
police_speed3 += 0.12;
points++;
label1.setText("Punkte: "+points);
}
Leinwand.repaint();
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
interrupt();
}
}}
}
}
//Ende Polizeiauto bewegen
//Steuerung Fahrzeug
public void move(){
this.addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e) {
if(flag && flag2){
if(e.getKeyCode() == 39){
car_xpos += 9;
Leinwand.repaint();
if(car_xpos > 350) {
car_xpos = 349;
}
}
if(e.getKeyCode() == 37){
car_xpos -= 9;
Leinwand.repaint();
if(car_xpos < 105) {
car_xpos = 106;
}
}
if(e.getKeyCode() == 38){
car_ypos -= 9;
Leinwand.repaint();
if(car_ypos < 1) {
car_ypos = 1;
}
}
if(e.getKeyCode() == 40){
car_ypos += 9;
Leinwand.repaint();
if(car_ypos > 222) {
car_ypos = 223;
}
}
}
}
});
}
//Ende Fahrzeug Steuerung
}
und hier noch das applet auf dem Server...
http://
www.gostelithomas.bplaced.net/carcrash/start.html
Wäre sehr für eure Hilfe dankbar...
MfG