Hallo zusammen
ich bin neu hier und hoffe nicht das ich oberflächliche Fehler gemacht habe
ich habe derzeit ein Program geschrieben wo ich ein Oval auf der X und Y Achse bewegen lassen möchte. Dazu habe ich mir einen Quellcode als Hilfe genommen allerdings ohne die Grafiken.
Als ich die Steuerung schreiben wolte trat der fehler auf das die neija Methode/Klasse... als Falsch makiert wird ebenso die Methode repaint() was anscheinend keine Variable sei.Ich hoffe das mir einer helfen kann.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Spiel.Main.main(Main.java:48)
Hilfe.txt
Main.txt
majesty
ich bin neu hier und hoffe nicht das ich oberflächliche Fehler gemacht habe
ich habe derzeit ein Program geschrieben wo ich ein Oval auf der X und Y Achse bewegen lassen möchte. Dazu habe ich mir einen Quellcode als Hilfe genommen allerdings ohne die Grafiken.
Als ich die Steuerung schreiben wolte trat der fehler auf das die neija Methode/Klasse... als Falsch makiert wird ebenso die Methode repaint() was anscheinend keine Variable sei.Ich hoffe das mir einer helfen kann.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Spiel.Main.main(Main.java:48)
Hilfe.txt
Java:
package jadahb1.de.game;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
public class gui extends JPanel implements ActionListener {
Timer time;
Image img;
int key;
int nx,nx2;
int figur_y = 235;
//neu
Block block1;
int coin_score;
//
int X_Bild;
int lauf;
int anzahl = 0;
int anzahl2= 0;
Image img2;
int left = 75;
public gui() {
nx = 0;
nx2 = 690;
key = 0;
lauf = 0;
setFocusable(true);
ImageIcon u = new ImageIcon((getClass().getResource("background.jpg")));
img = u.getImage();
ImageIcon s = new ImageIcon((getClass().getResource("char.png")));
img2 = s.getImage();
addKeyListener(new AL());
//neu
//149 y hoch Springen - Höhe
block1 = new Block(250,110,50,50, Color.YELLOW);
//
Sprung sprung = new Sprung();
time = new Timer(5,this);
time.start();
}
public void actionPerformed(ActionEvent e) {
bewegen();
figur_y = Sprung.sprungposition;
repaint();
}
public void paint(Graphics g){
super.paint(g);
Graphics2D f2 =(Graphics2D)g;
if (getXBild() == 510+ (anzahl *2350)) {
anzahl += 1;
nx = 0;
}
if (getXBild() == 1690+(anzahl2*2350)) {
anzahl2 += 1;
nx2 = 0;
}
if (getXBild() >= 510){
f2.drawImage(img,685-nx,0,null);
}
f2.drawImage(img,685-nx2,0,null);
f2.drawImage(img2,left,figur_y,null);
//neu
f2.setColor(block1.getFarbe());
f2.fillRect(block1.getX_Block()-getXBild(), block1.getY_Block(), block1.getWidth(), block1.getHeight());
//+ 74 -12 --> GIMP
block1.Kollisionsabfrage(block1.getX_Block()-getXBild(), block1.getY_Block()+ block1.getHeight(),left+ (74-12),figur_y);
if(block1.Coin() == true) {
coin_score = 1;
}
f2.drawString("Score :" + coin_score, 10, 15);
//
}
private int getXBild() {
return X_Bild;
}
public void bewegen() {
if (lauf != -2) {
if (left + lauf <= 75) {
left += lauf;
} else {
X_Bild += lauf;
nx += lauf;
nx2 += lauf;
}
} else {
if (left + lauf > 0) {
left += lauf;
}
}
}
private class AL extends KeyAdapter {
public AL() {
}
public void keyPressed(KeyEvent e) {
key = e.getKeyCode();
if(key == KeyEvent.VK_LEFT) {
lauf = -2;
//Richtung geändert
}
if(key == KeyEvent.VK_RIGHT) {
lauf = 2;
}
if(key == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
if(key == KeyEvent.VK_SPACE) {
if(Sprung.fertig == true)
Sprung();
}
}
public void keyReleased(KeyEvent e) {
key = e.getKeyCode();
if(key == KeyEvent.VK_LEFT || key == KeyEvent.VK_RIGHT) {
lauf = 0;
}
}
public void Sprung() {
Sprung SprungAnimation = new Sprung();
SprungAnimation.start();
}
}
}
Main.txt
Java:
package Spiel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import jadahb1.de.game.Sprung;
public class Main extends BasicGame implements ActionListener {
int X = 0;
int Y = 0;
int Key = 0;
int X_Bild;
int Y_Bild;
public void init(GameContainer gc) throws SlickException {
}
public void update(GameContainer gc, int arg1) throws SlickException {
}
public void render(GameContainer gc, Graphics g) throws SlickException {
g.fillOval(10 ,10 ,300 ,300);
g.setColor(Color.blue);
}
public Main(String title) {
super(title);
}
public static void main(String [] args){
try {
AppGameContainer app = new AppGameContainer(new Main("Titel"));
app.setDisplayMode(600, 600, false);
app.setTargetFrameRate(60);
app.setVSync(true);
app.start();
} catch(SlickException e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
Bewegen();
repaint();
}
private int getXBild() {
return X_Bild;
}
private int getYBild() {
return Y_Bild;
}
public void Bewegen {
if (X != -2) {
} else {
X_Bild += X;
}
}
private class AL extends KeyAdapter {
public AL() {
}
public void keyPressed(KeyEvent e) {
Key = e.getKeyCode();
if(Key == KeyEvent.VK_LEFT) {
X = -2;
}
if(Key == KeyEvent.VK_RIGHT) {
X = 2;
}
if(Key == KeyEvent.VK_LEFT) {
Y = -2;
}
if(Key == KeyEvent.VK_RIGHT) {
Y = 2;
}
}
public void keyReleased(KeyEvent e) {
Key = e.getKeyCode();
if(Key == KeyEvent.VK_LEFT || Key == KeyEvent.VK_RIGHT ||Key == KeyEvent.VK_UP || Key == KeyEvent.VK_DOWN) {
X = 0;
Y = 0;
}
}
}
}
majesty
Anhänge
Zuletzt bearbeitet von einem Moderator: