Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 8 of 9 FirstFirst ... 6789 LastLast
Results 176 to 200 of 219

Thread: Chess Program

  1. #176
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    how i can perform different tasks for the different buttons in the controller class
    I gave three solutions for the problem earlier.
    The second and third solutions put data into the object reference passed to the ActionListener method which could get that data and from it know which button was pressed.
    One used the JComponent class's ClientProperty methods: get... and put...
    The other extended the JButton class with your own class which could have methods the listener method could call. Use the getSource() method to get the object reference and cast that object reference to an instance of your class that extended the JButton class. With that reference to your class you can call its methods.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #177
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    okay

    Now i understand it and it works. The only problem is i have to press the empty button 2 times before the pieces are set to default. the first time its some weird GUI not all the pieces are there. When i click the second time the board is set to normal(default).

    Is this a common problem with a general solution and what is the solution?
    System.out.println(" dream in code ");

  3. #178
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    No, it is not a common problem.
    Try debugging with println() statements to see what the code is doing.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #179
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    it works just had to add a call to the controller object and remove the current chessboardview...this.remove(chessboardview) and after that add the new one
    System.out.println(" dream in code ");

  5. #180
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    this.remove(chessboardview) and after that add the new one
    That seems like the wrong way to do it. The program should reuse the objects, not create new ones.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #181
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    The only thing i have to do is, check the input from the user in the fenbar. Does it contains illegal characters make exceptions for them and print it out in the JTextArea which is in the infopanel class
    System.out.println(" dream in code ");

  7. #182
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    Hi i have this piece of code but dont know what come characters mean..

     int row = 7;
            int col = 0;
            while (index < fen.length() && fen.charAt(index) != ' ') {
                ch = fen.charAt(index);
                if (ch == '/') {
                    if (col != 8)
                        throw new IllegalArgumentException("Malformatted fen string: unexpected '/' found at index " + index);
                    row--; col = 0;

    what means row--;

    the -- characters. does it lower variable int row = 7 by 1
    System.out.println(" dream in code ");

  8. #183
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    what means row--;
    the -- operator subtracts one from the variable. The same as row = row - 1

    dont know what come characters mean..
    Sorry, I don't understand what your problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #184
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    To check if two Strings are the same, you can use .equals(); Is there a similair methode for type char (Character) to check if two char are the same
    System.out.println(" dream in code ");

  10. #185
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    char variables are not objects, and don't have methods. The == operator is used to compare two char variables.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #186
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    thanks, another question is there a way to define how many instances of a specific object are allowed to be made.

    Like there may only be one WHITE KING K object. Only 8 BLACK PAWN P objects are allowed.
    System.out.println(" dream in code ");

  12. #187
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    a way to define how many instances of a specific object are allowed to be made.
    Look at the Singleton pattern. It's an example of how to limit the number of instances of a classes that are created. The Singleton is for one, but the idea could be used for any number.

    Another way would be to have a counter for each type. A Map might be useful for that: The key would be the piece name and the value would be the count of instances created.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #188
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    i asked but its not necessary to define how many objects are allowed to be made.

    Another question. This is the program single window with fen, board en some buttons. this represents one FEN diagram.

    in the menubar there is a menu edit with menu item add diagram. Is it possible to "copy" the diagram or make a new one and paste it under the diagram which is all ready there so with a scrollbar you can switch between different diagrams. how can i add a new diagram right below the a other diagram
    System.out.println(" dream in code ");

  14. #189
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    Is a "diagram" the GUI things that are shown in a component like a JPanel?

    Have you tried adding them to a scroll pane to see what happens?

    Or perhaps a CardLayout would be another way to allow viewing different "diagrams".

    Or try remove() and add() to change "diagrams".
    If you don't understand my answer, don't ignore it, ask a question.

  15. #190
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    I have to program this in the controller class wright? the controller class makes the frame and the jpanel with different classes from the view which contains jpanel
    System.out.println(" dream in code ");

  16. #191
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    Do it in the class that controls what is shown in the JFrame if that is where you want to be able to change what is shown in the JFrame.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #192
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    another question.

    How can i save the current diagram? All ready have some save en open code with extension cmd but how can i save the chessboard and fen to a file is in a container with borderlayout etc

    writer.write(..........)

    store the current diagram and fen in a variable or something?
    System.out.println(" dream in code ");

  18. #193
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    Do you need to save more than the FEN string? It can be used to create a position.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #194
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    The fen string with description! So i fill in a fen-string with description white-to-win.. that needs to be saved i think. What you suggest is to save the fen and description and when its opened the chessboard pieces move to places which the fen indicates.

    But as i said earlier actually there must be a possibility to add a diagram under the current diagram, so there are more chessboards with the associated fen-notation. So i think i need to save the chessboard and fen as well

    but how to do that? store it in some kind of variable?
    System.out.println(" dream in code ");

  20. #195
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    Can each chess board can be represented by a FEN String?
    If not, what is missing?

    Save a FEN string for each board you want to save.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #196
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    Each chessboard is associated with one FEN String, if the file has more boards it also contains more fens. so you say i have to save the FEN? what about the description
    System.out.println(" dream in code ");

  22. #197
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    You can write many FEN strings and descriptions to a text file. It is up to you to design a file layout to handle that.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #198
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    and my question is how can i design a file layout to handle that can you give code examples need to finish this deadline is tomorrow

    and thanks for all you help last week! learned a lot!
    System.out.println(" dream in code ");

  24. #199
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Chess Program

    design a file layout to handle that
    What needs to go in the file?
    One design would be to have a line/record for each board. Use a special character to separate the separate parts/fields. For example use a ;
    <FEN String1>;<Description1>
    <FEN String2>;<Description2>

    When a line/record is read, the split() method can separate fields into the elements of an array.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #200
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chess Program

    Description
    Fen

    whats this?

    <FEN String1>;<Description1>
    <FEN String2>;<Description2>
    Screen Shot 2013-08-15 at 10.40.19 PM.jpg

    first jtextfield is description right under it jtextfield fen-notation
    System.out.println(" dream in code ");

Page 8 of 9 FirstFirst ... 6789 LastLast

Similar Threads

  1. Simple chess program (no AI) - Need help with structuring my code
    By MineeMo in forum Object Oriented Programming
    Replies: 6
    Last Post: June 18th, 2012, 10:12 AM
  2. Chess game help
    By that_guy in forum Java Theory & Questions
    Replies: 3
    Last Post: December 4th, 2011, 08:42 PM
  3. checking for draw by repetition in chess app
    By aisthesis in forum Algorithms & Recursion
    Replies: 0
    Last Post: February 16th, 2011, 02:40 AM
  4. Chess Problem
    By pmg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 10th, 2011, 12:07 PM
  5. Simple Chess program
    By x3rubiachica3x in forum What's Wrong With My Code?
    Replies: 23
    Last Post: September 22nd, 2010, 11:12 AM