-
December 12th, 2011, 09:08 AM
#1
Java Board Grid + Moving objects
Hello!
Does anyone have a tutorial or some tips on making a grid in java where it is possible to select objects via the keyboard and move them to other positions in the grid.
And check if the move is a valid move so you have to be able to track the item on the board.
Kind regards.
Last edited by MaSSaSLaYeR; December 12th, 2011 at 09:20 AM.
-
December 12th, 2011, 09:29 AM
#2
Re: Java Board Grid + Moving objects
Does anyone have a tutorial or some tips on making a grid in java
Use GridLayout
where it is possible to select objects via the keyboard
Add a keyboard listener.
and move them to other positions in the grid.
How do you want to do this, eg are you typing in co-ordinates, using tab to move to the next location etc.
-
December 12th, 2011, 09:40 AM
#3
Re: Java Board Grid + Moving objects
Originally Posted by keang
How do you want to do this, eg are you typing in co-ordinates, using tab to move to the next location etc.
Move in the grid using the arrow keys (up down left right) then when you get to a position you need to press "enter" to select it then the object should be highlighted and you should be able to move to another position that is "empty" place on the board and then press enter again.
When you "drop" you need to check if your move is valid this means that you can't move to an empty space more then 2 block aways.
I tried to draw it:
http://img20.imageshack.us/img20/7320/uploadmj.png
The "O" can only be placed in place "1" and not in "2"
Btw all is done via JavaTV to make it extra harder
Last edited by MaSSaSLaYeR; December 12th, 2011 at 09:42 AM.
-
December 12th, 2011, 11:17 AM
#4
Re: Java Board Grid + Moving objects
Sorry but I can't help as I've no idea what is available under JavaTV.
-
December 12th, 2011, 01:17 PM
#5
Re: Java Board Grid + Moving objects
Originally Posted by keang
Sorry but I can't help as I've no idea what is available under JavaTV.
Is it possible to see what event/object has focus after you press enter for example?
-
December 13th, 2011, 11:56 AM
#6
Re: Java Board Grid + Moving objects
If the JavaTV GUI is based on the standard Java event model then yes but if not then I have no idea because, as I said, I don't know what features JavaTV has.
You'll have to read a JavaTV tutorial to see what you can do.
-
December 13th, 2011, 04:13 PM
#7
Re: Java Board Grid + Moving objects
Originally Posted by keang
If the JavaTV GUI is based on the standard Java event model then yes but if not then I have no idea because, as I said, I don't know what features JavaTV has.
You'll have to read a JavaTV tutorial to see what you can do.
The problem is there isn't one :/
-
December 13th, 2011, 05:31 PM
#8
Re: Java Board Grid + Moving objects
Originally Posted by MaSSaSLaYeR
The problem is there isn't one :/
That's funny, googling javatv the second result I got was this: The JavaTV Tutorial | www.tvwithoutborders.com; it was right after the Wikipedia page for Java TV which also has a reference to the same site.
-
December 14th, 2011, 02:22 AM
#9
Re: Java Board Grid + Moving objects
Originally Posted by jcaccia
I read that tutorial it's just a basic one, how the system works without in depth examples of for instance a board game.
-
December 14th, 2011, 05:43 AM
#10
Re: Java Board Grid + Moving objects
Yes you can always query the focus owner from FocusManager, there is a static getter. Note that for this work, your components need to have a KeyListener of some sorts assigned to them.
So you could, for instance do the following in the gid component (pseudo):
Add a listener that listens to arrow keys
just arrow key -> move focus
+cntrl_mask -> move button
upon selection:
get the right component in the grid, mark it selected
upon move:
find the component to which to move.
validate that the selected can move to that components place
I spose, there is a swap of states between these components (right?). If move is valid,
swap contents between the components
mark the right one as selected
advice the components to redraw.
In this sense, you do not need to think of actually moving the components. You just move one internal state of a component to another one. Also your components do not need to be anything other than graphical placeholders for the information they carry. The only "active piece" is the grid itself.
-
December 14th, 2011, 04:37 PM
#11
Re: Java Board Grid + Moving objects
I got a typ to implement a paint method how do I do that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|