Results 1 to 17 of 17
Thread: Need Help reading errors
- 04-20-2012, 11:23 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
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.
- 04-21-2012, 02:07 AM #2
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
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.
- 04-21-2012, 02:30 AM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: Need Help reading errors
shouldn't ChessPanel extend JPanel?Java Code:public class ChessPanel extends JFrame { // ???
Edited: I just looked at the code again. Disregard the above comment.Last edited by shall; 04-21-2012 at 02:34 AM.
- 04-21-2012, 03:16 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
offtopic a little...
'My name is Alice, but —'Edited: I just looked at the code again. Disregard the above comment.
'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.'
- 04-21-2012, 06:25 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
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
chesswindow line 25 isDummyPiece dummy = new DummyPiece();
ChessPanel j = new ChessPanel(frame);
-
Re: Need Help reading errors
Dumb question, I know, but do you have a DummyPiece class somewhere?
- 04-21-2012, 06:30 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: Need Help reading errors
yes i do would you like for me to upload it
-
Re: Need Help reading errors
- 04-21-2012, 06:35 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: Need Help reading errors
I have it in the same package with everything elsepublic 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) {
}
}Last edited by Fubarable; 04-21-2012 at 06:36 PM. Reason: quote tags changed to code tags
-
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.
- 04-21-2012, 06:39 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
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) { } }
-
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.
- 04-21-2012, 06:42 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
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.
-
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.
-
Re: Need Help reading errors
Is DummyPiece.java in its own file, or is it nested in another file?
- 04-21-2012, 07:03 PM #16
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
- 04-21-2012, 07:05 PM #17
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
errors
By santosh chauhan in forum New To JavaReplies: 5Last Post: 07-26-2010, 07:59 PM -
problem with reading excel sheet data reading using poi libraries
By sandeepsai17 in forum New To JavaReplies: 5Last Post: 08-21-2009, 11:03 AM -
Errors.
By rocky in forum New To JavaReplies: 4Last Post: 04-09-2009, 08:05 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks