Results 1 to 17 of 17
Like Tree2Likes
  • 1 Post By jlczuk
  • 1 Post By pbrockway2

Thread: Need Help reading errors

  1. #1
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Exclamation Need Help reading errors

    Hey I am making a boardsquare for a chessboard thing is I do not know what is wrong with my program, everything looks fine to me. If someone could please help me with this i would surely appreciate it. my attachment button is not working so i have to put the code here.

    Java Code:
    import java.awt.*;
    
    import javax.swing.*;
    
    
    
    public class ChessPanel extends JFrame {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	
    	
    	/**
    	 * creates a chess board piece and the square
    	 * 
    	 * @param frame
    	 *           
    	 */
    	 public ChessPanel (JFrame myFrame) {
    		 
    		 BoardSquare myBoard = new BoardSquare ('f' , 4);
    		 myBoard.setPreferredSize((new Dimension(350 , 350)));
    		 myBoard.setBackground(Color.black);
    		 
    		 myFrame.getContentPane().add(myBoard);
    		 myFrame.pack();
    		 myBoard.setVisible(true);
    		 
    		 DummyPiece dummy = new DummyPiece();
    		 myBoard.setPiece(dummy);
    		 
    		 myBoard.setSelected(true);
    		 
    		 }
    	 
    	 
    	
    
    }
    Java Code:
    public class BoardSquare extends JPanel implements ChessSquare {
    
    	private int rank;
    	private char file;
    	private ChessPiece chessPiece;
    	private boolean selected;
    	private boolean highlighted;
    
    	private static final long serialVersionUID = 12345;
    
    	/**
    	 * Initialize the BoardSquare variables with default values
    	 * 
    	 * @param f
    	 *            A letter for chess piece placement
    	 * @param r
    	 *            A number for chess piece placement
    	 */
    	public BoardSquare(char f, int r) {
    		file = f;
    		rank = r;
    		chessPiece = null;
    		selected = false;
    		highlighted = false;
    	}
    
    	/**
    	 * Gets the piece currently on this square
    	 * 
    	 * @return chess_piece
    	 */
    	public ChessPiece getPiece() {
    
    		return chessPiece;
    	}
    
    	/**
    	 * Sets a reference to the piece currently in this square. It should not
    	 * change the piece.
    	 * 
    	 * @param piece
    	 *            Type of chess piece
    	 */
    	public void setPiece(ChessPiece piece) {
    
    		chessPiece = piece;
    
    	}
    
    	/**
    	 * Gets the file(column) that this square is in. Starting with 'a' and from
    	 * left to right.
    	 * 
    	 * @return file
    	 */
    	public char getFile() {
    
    		return file;
    	}
    
    	/**
    	 * Gets the rank(row) that this square is in. Starting with 1 and from
    	 * bottom to top.
    	 * 
    	 * @return rank
    	 */
    	public int getRank() {
    
    		return rank;
    	}
    
    	/**
    	 * Returns a string in the format <file><rank>
    	 * 
    	 * @return str
    	 */
    	public String toString() {
    		String str = "" + file + rank + "";
    
    		return str;
    
    	}
    
    	/**
    	 * Determines if this square is currently highlighted.
    	 * 
    	 * @return highlighted
    	 */
    	public boolean isHighlighted() {
    
    		return highlighted;
    	}
    
    	/**
    	 * Sets the highlighted state
    	 * 
    	 * @param highlight
    	 *            Is the chess piece highlighted
    	 */
    	public void setHighlighted(boolean highlight) {
    		highlighted = highlight;
    
    	}
    
    	/**
    	 * Determines if this square is currently selected.
    	 * 
    	 * @return selected
    	 */
    	public boolean isSelected() {
    
    		return selected;
    	}
    
    	/**
    	 * Sets the selected state.
    	 * 
    	 * @param select
    	 *            True or False if piece is selected
    	 */
    	public void setSelected(boolean select) {
    		selected = select;
    
    	}
    
    	/**
    	 * Draws a chess square and piece
    	 * 
    	 * @param g
    	 *            Drawings
    	 */
    	@Override
    	protected void paintComponent(Graphics g) {
    		super.paintComponent(g);
    
    		Dimension size = getSize();
    
    		int twoThirdWi = (int) (size.getWidth() / 1.5);
    		int twoThirdHi = (int) (size.getHeight() / 1.5);
    		int x = (int) (size.getWidth() / 6.0);
    		int y = (int) (size.getHeight() / 6.0);
    		int width = (int) size.getWidth();
    		int height = (int) size.getHeight();
    
    		g.setColor(Color.orange);
    		g.drawString(toString(), (int) (x / 1.6), (int) (y / 1.6));
    
    		if (chessPiece != null) {
    			Rectangle r = new Rectangle(x, y, twoThirdWi, twoThirdHi);
    
    			DummyPiece dummy = new DummyPiece();
    
    			dummy.draw(g, r);
    
    			if (highlighted) {
    				g.setColor(Color.orange);
    				g.drawRect(0, 0, width - 1, height - 1);
    				g.drawRect(1, 1, width - 3, height - 3);
    				g.drawRect(2, 2, width - 5, height - 5);
    				g.drawRect(3, 3, width - 7, height - 7);
    
    			}
    
    			if (selected) {
    				g.setColor(Color.orange);
    				g.drawRect(0, 0, width - 1, height - 1);
    				g.drawRect(2, 2, width - 5, height - 5);
    				g.drawRect(4, 4, width - 9, height - 9);
    
    			}
    		}
    
    	}
    
    }
    Java Code:
    public class ChessWindow {
    
    	/**
    	 * creates frame; runs it.
    	 * 
    	 * @param args
    	 *            Runs Program
    	 */
    	public static void main(String[] args) {
    
    		JFrame frame = new JFrame("Random Title");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    		ChessPanel j = new ChessPanel(frame);
    		j.setPreferredSize(new Dimension(200, 200));
    
    		frame.getContentPane().add(j);
    		frame.pack();
    		frame.setVisible(true);
    
    	}
    
    }

    Please someone help me.

  2. #2
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Need Help reading errors

    That's an awful lot of code to have to sort through. Can you provide some details about what you are trying to accomplish, what the errors are that you are seeing? While you are thinking about what is wrong, maybe you can narrow down to specific areas in your code the problem might be.
    Fubarable likes this.

  3. #3
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Need Help reading errors

    Java Code:
    public class ChessPanel extends JFrame { //   ???
    shouldn't ChessPanel extend JPanel?

    Edited: I just looked at the code again. Disregard the above comment.
    Last edited by shall; 04-21-2012 at 03:34 AM.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default offtopic a little...

    Edited: I just looked at the code again. Disregard the above comment.
    'My name is Alice, but '
    'It's a stupid name enough!' Humpty Dumpty interrupted impatiently. 'What does it mean?'
    'Must a name mean something?' Alice asked doubtfully.
    'Of course it must,' Humpty Dumpty said with a short laugh: 'my name means the shape I am and a good handsome shape it is, too. With a name like yours, you might be any shape, almost.'

    ...


    'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it to mean neither more nor less.'
    'The question is,' said Alice, 'whether you can make words mean so many different things.'
    'The question is,' said Humpty Dumpty, 'which is to be master that's all.'
    DarrylBurke likes this.

  5. #5
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    I am so sorry. That was stupid of me to just put something up here without tell you the error. well this is what i get


    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    DummyPiece cannot be resolved to a type
    DummyPiece cannot be resolved to a type

    at .ChessPanel.<init>(ChessPanel.java:33)
    at .ChessWindow.main(ChessWindow.java:25)

    chesspanel line 33 is

    DummyPiece dummy = new DummyPiece();
    chesswindow line 25 is

    ChessPanel j = new ChessPanel(frame);

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  7. #7
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    yes i do would you like for me to upload it

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need Help reading errors

    Quote Originally Posted by sccot21 View Post
    yes i do would you like for me to upload it
    Yes, that would be nice, if it's short. Is it in the same package as the classes you've posted above? If not, do you import it into the above classes?

  9. #9
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    public class DummyPiece implements ChessPiece {


    @Override
    public boolean isWhite() {
    return false;
    }


    @Override
    public boolean isBlack() {
    return false;
    }


    @Override
    public void draw(Graphics g, Rectangle bounds) {
    Color oldColor = g.getColor();

    g.setColor(Color.red);
    g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);

    g.setColor(oldColor);
    }


    @Override
    public ChessSquare getSquare() {
    return null;
    }


    @Override
    public void moveTo(ChessSquare square) {
    }

    }
    I have it in the same package with everything else
    Last edited by Fubarable; 04-21-2012 at 07:36 PM. Reason: quote tags changed to code tags

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need Help reading errors

    Moderator edit: quote tags changed to code tags in the post above to help code retain formatting.

    To the original poster: please read up on how to use [code] [/code] tags here.

  11. #11
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    Java Code:
    public class DummyPiece implements ChessPiece {
    
    	
    	@Override
    	public boolean isWhite() {
    		return false;
    	}
    
    	
    	@Override
    	public boolean isBlack() {
    		return false;
    	}
    
    	
    	@Override
    	public void draw(Graphics g, Rectangle bounds) {
    		Color oldColor = g.getColor();
    		
    		g.setColor(Color.red);
    		g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
    		
    		g.setColor(oldColor);
    	}
    
    	
    	@Override
    	public ChessSquare getSquare() {
    		return null;
    	}
    
    	
    	@Override
    	public void moveTo(ChessSquare square) {		
    	}
    
    }

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need Help reading errors

    I can't fully explain your error if your DummyPiece class is present in the same package as the other classes and has been compiled correctly.

  13. #13
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    ok thank you. I may just have to start over and try to see if i can do it again without it giving me errors.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need Help reading errors

    Why did you edit the post of yours that I already corrected? You've changed the code tags that I placed back into inappropriate quote tags.

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  16. #16
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Need Help reading errors

    Quote Originally Posted by Fubarable View Post
    Why did you edit the post of yours that I already corrected? You've changed the code tags that I placed back into inappropriate quote tags.

    I am sorry I thought you had wanted me to do it so i went back and re posted it

  17. #17
    sccot21 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  2. errors
    By santosh chauhan in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 08:59 PM
  3. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  4. Errors.
    By rocky in forum New To Java
    Replies: 4
    Last Post: 04-09-2009, 09:05 AM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 AM

Posting Permissions

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