Hallo,
seit Tagen versuche ich mein Fussball Memory Game zum laufen zu bringen, ohne applet bekomme ichs zum laufen, aber nicht mit Applet (Die Studien-Arbeit soll aber mit applets sein...) :roll:
Datei: MemoryCell.java
Fehlermeldung:
---------------------------------------------------------------------------------------------------
MemoryCell.java:31: cannot find symbol
symbol : method setSize(int,int)
location: class MemoryCell
setSize(80, 80);
^
MemoryCell.java:59: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:70: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:81: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:91: cannot find symbol
symbol : method paintComponent(java.awt.Graphics)
location: class java.lang.Object
super.paintComponent(g);
^
MemoryCell.java:96: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.fillRect(0, 0, getSize().width, getSize().height);
^
MemoryCell.java:96: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.fillRect(0, 0, getSize().width, getSize().height);
^
MemoryCell.java:143: cannot find symbol
symbol : method drawImage(java.awt.Image,int,int,int,int,MemoryCell)
location: class java.awt.Graphics
g.drawImage(image, 15, 15, 50, 50, this);
^
MemoryCell.java:147: cannot find symbol
symbol : method paintComponent(java.awt.Graphics)
location: class java.lang.Object
super.paintComponent(g);
^
MemoryCell.java:153: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
^
MemoryCell.java:153: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
^
MemoryCell.java:163: cannot find symbol
symbol : method getSize()
location: class MemoryCell
cp.x = (getSize().width - w) / 2;
^
MemoryCell.java:164: cannot find symbol
symbol : method getSize()
location: class MemoryCell
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
MemoryCell.java:164: operator + cannot be applied to getSize.height,int
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
MemoryCell.java:164: operator / cannot be applied to <nulltype>,int
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
15 errors
---------------------------------------------------------------------------------------------------
Source Code: MemoryCell.java
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
Datei: Memory.java
Fehlermeldung:
---------------------------------------------------------------------------------------------------
Compiliere H:\Java\WIchtige Java Projekte\Praktikumsarbeit\Memory.java mit Java-Compiler
Memory.java:56: illegal start of expression
protected MemoryCell[] cells;
^
Memory.java:58: illegal start of expression
protected MemoryCell ersteZelle, zweiteZelle;
^
Memory.java:60: illegal start of expression
protected int nMismatched;
^
Memory.java:63: illegal start of expression
public void mousePressed(MouseEvent e)
^
5 errors
---------------------------------------------------------------------------------------------------
Source Code: Memory.java
---------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
Frage: Warum sind repaint, getsize,illegal Start of expression etc... in meiner Fehlerlog, würde sehr über rasche Hilfe freuen, danke!!!
seit Tagen versuche ich mein Fussball Memory Game zum laufen zu bringen, ohne applet bekomme ichs zum laufen, aber nicht mit Applet (Die Studien-Arbeit soll aber mit applets sein...) :roll:
Datei: MemoryCell.java
Fehlermeldung:
---------------------------------------------------------------------------------------------------
MemoryCell.java:31: cannot find symbol
symbol : method setSize(int,int)
location: class MemoryCell
setSize(80, 80);
^
MemoryCell.java:59: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:70: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:81: cannot find symbol
symbol : method repaint()
location: class MemoryCell
repaint();
^
MemoryCell.java:91: cannot find symbol
symbol : method paintComponent(java.awt.Graphics)
location: class java.lang.Object
super.paintComponent(g);
^
MemoryCell.java:96: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.fillRect(0, 0, getSize().width, getSize().height);
^
MemoryCell.java:96: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.fillRect(0, 0, getSize().width, getSize().height);
^
MemoryCell.java:143: cannot find symbol
symbol : method drawImage(java.awt.Image,int,int,int,int,MemoryCell)
location: class java.awt.Graphics
g.drawImage(image, 15, 15, 50, 50, this);
^
MemoryCell.java:147: cannot find symbol
symbol : method paintComponent(java.awt.Graphics)
location: class java.lang.Object
super.paintComponent(g);
^
MemoryCell.java:153: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
^
MemoryCell.java:153: cannot find symbol
symbol : method getSize()
location: class MemoryCell
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
^
MemoryCell.java:163: cannot find symbol
symbol : method getSize()
location: class MemoryCell
cp.x = (getSize().width - w) / 2;
^
MemoryCell.java:164: cannot find symbol
symbol : method getSize()
location: class MemoryCell
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
MemoryCell.java:164: operator + cannot be applied to getSize.height,int
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
MemoryCell.java:164: operator / cannot be applied to <nulltype>,int
cp.y = (getSize().height + h) / 2 - fm.getDescent();
^
15 errors
---------------------------------------------------------------------------------------------------
Source Code: MemoryCell.java
---------------------------------------------------------------------------------------------------
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class MemoryCell
{
public final static int NONE = -1;
public final static int RECTANGLE = 0;
public final static int OVAL = 1;
public final static int ARC = 2;
public final static int TRIANGLE = 3;
public final static int SQUIGGLE = 4;
public final static int LINES = 5;
public final static int JAVA = 6;
public final static int IMAGE = 7;
protected int symbol;
protected static Image image;
protected boolean matched;
protected boolean hidden;
protected boolean focused;
public MemoryCell(int shape)
{
super();
setSymbol(shape);
matched = false;
hidden = true;
focused = false;
image = Toolkit.getDefaultToolkit().getImage("pokal.jpg");
setSize(80, 80);
}
public void setSymbol(int shape)
{
if (shape >= -1 && shape <= 7)
{
symbol = shape;
}
else
{
symbol = NONE;
}
}
public int getSymbol()
{
return symbol;
}
public boolean matches(MemoryCell otherMemoryCell)
{
return symbol == otherMemoryCell.symbol;
}
public void setMatched(boolean m)
{
matched = m;
repaint();
}
public boolean getMatched()
{
return matched;
}
public void setHidden(boolean h)
{
hidden = h;
repaint();
}
public boolean getHidden()
{
return hidden;
}
public void setFocused(boolean f)
{
focused = f;
repaint();
}
public boolean getFocused()
{
return focused;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if (hidden)
{
g.setColor(Color.darkGray);
g.fillRect(0, 0, getSize().width, getSize().height);
g.setColor(Color.lightGray);
g.setFont(new Font("Timesroman", Font.ITALIC, 36));
Point p = centerStringPoint("?", g.getFontMetrics());
g.drawString("?", p.x, p.y);
}
else switch (symbol)
{
case RECTANGLE:
g.fillRect(15, 15, 50, 50);
break;
case OVAL:
g.fillOval(15, 15, 50, 50);
break;
case ARC:
g.fillArc(15, 15, 50, 50, 45, 270);
break;
case TRIANGLE:
g.fillPolygon(new int[] {40, 15, 65},
new int[] {15, 65, 65}, 3);
break;
case SQUIGGLE:
g.drawPolyline(new int[] {15, 25, 35, 45, 55, 65},
new int[] {15, 65, 15, 65, 15, 65}, 6);
break;
case LINES:
g.drawLine(15, 15, 65, 15);
g.drawLine(15, 25, 65, 25);
g.drawLine(15, 35, 65, 35);
g.drawLine(15, 45, 65, 45);
g.drawLine(15, 55, 65, 55);
g.drawLine(15, 65, 65, 65);
break;
case JAVA:
g.setFont(new Font("Timesroman", Font.BOLD, 24));
Point p = centerStringPoint("Java", g.getFontMetrics());
g.drawString("Java", p.x, p.y);
break;
case IMAGE:
g.drawImage(image, 15, 15, 50, 50, this);
break;
default:
super.paintComponent(g);
}
if (focused)
{
if (matched) g.setColor(Color.green);
else g.setColor(Color.red);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
}
}
private Point centerStringPoint(String s, FontMetrics fm)
{
Point cp = new Point();
int w = fm.stringWidth(s);
int h = fm.getHeight() - fm.getLeading();
cp.x = (getSize().width - w) / 2;
cp.y = (getSize().height + h) / 2 - fm.getDescent();
return cp;
}
}
Datei: Memory.java
Fehlermeldung:
---------------------------------------------------------------------------------------------------
Compiliere H:\Java\WIchtige Java Projekte\Praktikumsarbeit\Memory.java mit Java-Compiler
Memory.java:56: illegal start of expression
protected MemoryCell[] cells;
^
Memory.java:58: illegal start of expression
protected MemoryCell ersteZelle, zweiteZelle;
^
Memory.java:60: illegal start of expression
protected int nMismatched;
^
Memory.java:63: illegal start of expression
public void mousePressed(MouseEvent e)
^
5 errors
---------------------------------------------------------------------------------------------------
Source Code: Memory.java
---------------------------------------------------------------------------------------------------
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class Memory extends JApplet
{
JLabel memoryGameLB = new JLabel("<html>[b]MEMORY WM GAME 2006 - Mir send die die gwenne wellad... :-)[/b]</html>");
JLabel fehlschlagLB = new JLabel("Anzahl der Fehlschläge: 0");
protected static Image image;
protected Button neustart = new Button("neustart");
public void init ()
{
add(new MyPanelNorth(), BorderLayout.NORTH);
add(new MyPanelCenter(), BorderLayout.CENTER);
add(new MyPanelSouth(), BorderLayout.SOUTH);
neustart.addActionListener(new ActionListener());
new Memory();
//neustart ersteZelle and zweiteZelle & mismatches
randomize();
//pack();
//setResizable(false);
//setVisible(true);
}
class MyPanelNorth extends JPanel
{
public MyPanelNorth()
{
setBackground(Color.black);
memoryGameLB.setForeground(Color.white);
add(memoryGameLB);
}
}
class MyPanelSouth extends JPanel
{
public MyPanelSouth()
{
setBackground(Color.red);
//addMouseListener(new MyMouseEvent());
add(fehlschlagLB);
fehlschlagLB.setForeground(Color.white);
}
}
class MyPanelCenter extends JPanel // innere Klasse der JApplet-Klasse
{
public MyPanelCenter()//(int shape) //Konstruktor
{
super("Memory Game");
protected MemoryCell[] cells;
//ersteZelle und zweiteZelle
protected MemoryCell ersteZelle, zweiteZelle;
protected int nMismatched;
MouseListener ml = new MouseAdapter();
public void mousePressed(MouseEvent e)
{
MemoryCell clickedCell = (MemoryCell)e.getSource();
public void actionPerformed(ActionEvent e)
{
randomize();
}
if (zweiteZelle != null)
{
ersteZelle.setFocused(false);
zweiteZelle.setFocused(false);
if (!ersteZelle.matches(zweiteZelle))
{
ersteZelle.setHidden(true);
zweiteZelle.setHidden(true);
nMismatched++;
fehlschlagLB.setText("Anzahl der Fehlversche: "+ nMismatched);
}
ersteZelle = zweiteZelle = null;
}
if (clickedCell.getHidden())
{
clickedCell.setFocused(true);
clickedCell.setHidden(false);
if(ersteZelle == null)
{
ersteZelle = clickedCell;
}
else
{
zweiteZelle = clickedCell;
if (ersteZelle.matches(zweiteZelle))
{
ersteZelle.setMatched(true);
zweiteZelle.setMatched(true);
}
}
}
} // Ende Abarbeitung des Codes wenn die Maus gedrückt wurde
ersteZelle = zweiteZelle = null;
setLayout(new GridLayout(4, 0, 10, 10));
cells = new MemoryCell[16];
for (int c=0; c < cells.length; c++)
{
cells[c] = new MemoryCell(MemoryCell.NONE);
cells[c].addMouseListener(ml);
add(cells[c]);
}
};
protected void randomize()
{
//für alle möglichen Symbol Paare
int[] symbols = new int[cells.length];
int pos;
Random rand = new Random();
//reinitialize all cells
for (int c=0; c < cells.length; c++)
{
cells[c].setMatched(false);
cells[c].setHidden(true);
cells[c].setFocused(false);
cells[c].setSymbol(MemoryCell.NONE);
symbols[c] = c % 8;
}
for (int s=0; s < symbols.length; s++)
{
do
{
pos = rand.nextInt(cells.length);
}
while (cells[pos].getSymbol() != MemoryCell.NONE);
cells[pos].setSymbol(symbols[s]);
}
ersteZelle = null;
zweiteZelle = null;
if (isVisible())
repaint();
nMismatched = 0;
fehlschlagLB.setText("Number of Mismatches: 0");
}
}
}
------------------------------------------------------------------------------------
Frage: Warum sind repaint, getsize,illegal Start of expression etc... in meiner Fehlerlog, würde sehr über rasche Hilfe freuen, danke!!!