Can't find error in my program!
My program consists of two classes.
Code:
package prob2;
import java.awt.*;
public class Coin {
private Image head;
private Image tail;
public int side;
//Constructor
public Coin(Image heads, Image tails) {
head = heads;
tail = tails;
side = 0;
}
//Flips the coin
public void flip() {
if (side == 0) {
side = 1;
}
else {
side = 0;
}
}
//draws the appropriate side of the coin
//centered at (x,y)
public void draw(Graphics g, int x, int y) {
if (side == 0) {
g.drawImage(head, x, y, null);
}
else {
g.drawImage(tail, x, y, null);
}
}
}
and
Code:
package prob2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CoinTest extends JPanel implements ActionListener {
private Coin coin;
//Constructor
public CoinTest() {
Timer timer = new Timer(2000, this);
timer.start();
Image coinhead = Toolkit.getDefaultToolkit().getImage("coinImgH.jpg");
Image cointail = Toolkit.getDefaultToolkit().getImage("coinImgT.jpg");
coin = new Coin(coinhead, cointail);
}
//Paints the coin
public void paintComponent(Graphics g) {
super.paintComponent(g);
coin.draw(g, 300, 300);
}
//Flips the coin and repaints the window
public void actionPerformed(ActionEvent e) {
coin.flip();
repaint();
}
public static void main(String[] args) {
JFrame window = new JFrame("Coin Test");
window.setSize(600, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CoinTest test1 = new CoinTest();
test1.setBackground(Color.WHITE);
Container c = window.getContentPane();
c.add(test1);
window.setVisible(true);
}
}
My IDE "cannot resolve Coin to a type." I can't find anything else wrong with my program. Maybe someone else can!