Results 1 to 3 of 3
  1. #1
    kkGG is offline Member
    Join Date
    Nov 2010
    Posts
    28
    Rep Power
    0

    Exclamation Can't find error in my program!

    My program consists of two classes.

    Java 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

    Java 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!
    Last edited by kkGG; 11-10-2010 at 05:29 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kkGG View Post
    My IDE "cannot resolve Coin to a type." I can't find anything else wrong with my program. Maybe someone else can!
    Your compiler can't find any definition of 'Coin' because it doesn't know where to look for it. Try to compile both source files at once:

    Java Code:
    javac *.java
    This should be done in the directory ./prob2 where both of the .java files are stored. Note that this is not a general solution, just a quickie. I bet you're going to have troubles to run your class(es).

    kind regards,

    Jos

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    What IDE? Have you tried compiling via the command prompt? Have you tried compiling Coin first, or both files at once? How are these files organized on your file system?

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 09:48 PM
  2. Replies: 3
    Last Post: 09-26-2010, 06:29 AM
  3. I need help with an error! Cannot find symbol error!
    By ambria1975 in forum New To Java
    Replies: 2
    Last Post: 07-07-2010, 01:37 AM
  4. Replies: 1
    Last Post: 07-03-2009, 08:41 PM
  5. Can we find out program excecution Time?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 01:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •