steve tang

Greenhorn
+ Follow
since Jun 12, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by steve tang

How can I make a line break in a textfield?
I want to make something like a list that requires line breaks and I want to add it to the end of a string

moveString += "(" + (k1 + 1) + "," + (k2 + 1) + ") " +\r\n; doesn't work

Thanks
18 years ago
Hello.
Sorry if the post is inetiquette because this my first time using the forum.
I am making a 2 player chess game using JButtons. The program is supposed to run as the following:

1. create the chessboard with pieces in it

2. select a button

3. determine where the piece could move and count the amount of legal moves and record the positions

4. color these buttons

5. goes to step 2

you click the button to move between 5 and 6

6. according to the amount and the positions~to determine is you click is a legal move or not

you click the button to move between 5 and 6

7. switch the information of the 2 buttons you clicked before

8. fresh~output the result of the switch

9. switch turns

When a piece is clicked on, the possible legal moves are shown but when the square is clicked on, nothing happens. It is supposed to move the piece to the selected square. I think the problem is that the program cannot get to step 2 to move the pieces. Also, when one of the pieces is clicked on, the following error message appears that I don't understand:


Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at Chess.select(Chess.java:957)
at Chess.movePawn(Chess.java:379)
at Chess.actionPerformed(Chess.java:126)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:18
49)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

The code is:
18 years ago