File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes using jbutton to change New objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using jbutton to change New objects" Watch "using jbutton to change New objects" New topic
Author

using jbutton to change New objects

Seamus GalIagher
Greenhorn

Joined: Aug 08, 2005
Posts: 20
Hello,

i am in the middle of writing a program in my free time (its a tile map thing). Having setup the creation of a "map" using arrays and nested loops, i wish to add a character to the map. I use jBuilder, and made a jButton that will perform an action when it is clicked. However, there is a problem!

When clicked, the button can only change properties of objects that are created initially (ie user defined). The button does not recognise any object that is created once the program is run. For example, a nested loop creats a grid of tiles(with attributes) and names them "tN" + r + c (where r + c represents row and column number = ie row 1 col 1 = tN00).
If i want to change an attribute of tN00 using the button, i cant, as tN00 is not recognised. Anything from the grid is not recognised (i cant use grid[r][c] or grid[0][0]). What should i read up on to allow tN00 to be changed, or what should i do?
This is quite important, as the whole grid[r][c] will be important to the whole program.

Thankyou for reading,

Seamus.

**edit** would 1 solution be to create an arraylist of numbers, which represents each tiles different attributes, and then link these to the grid?
[ August 09, 2005: Message edited by: Seamus GalIagher ]
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
why cant you use grid[r][c]???

post some code maybe we would be able to come up with a solution!
Seamus GalIagher
Greenhorn

Joined: Aug 08, 2005
Posts: 20
hello,

i will post my code. Things to note - I use jBuilder. Also, this code is basically my old code "cleaned up" by another forum member, in a previous post. However, it doesnt work as it should. (my previous post is called My Tiled Game Map System, and the problem is detailed in the last post). The problem is, nothing is displayed - only references are made. Reading that post will help you to understand.

jbuilder has organised my code into these seperate files
1)Frame1
2)Tile
3)Grass
4)Block.

the package is named saloon :-)
apoligies for bad code layout - ive coded and recoded about 50 times and havent cleaned up 100%

Frame1

Tile

Grass


Block


I can use the button to manipulate things like jLables created at the start of the prgam but not things created during loop. Some code is pointless, like the last loop - but it shows that the references are correct (although no image shows).
[ August 09, 2005: Message edited by: Seamus GalIagher ]
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
Hi,
You could simply put the declaration of gridref after the labels like this
Tile [][] gridref;
It would then be a member of your class. By doing so you would make it available in every function of Frame1.

Remark: the line where you define gridref right now should change and only be an initialization.
[ August 09, 2005: Message edited by: Jean-Sebastien Abella ]
Seamus GalIagher
Greenhorn

Joined: Aug 08, 2005
Posts: 20
Hello, and thankyou for taking a look at my first attempt at game programming. (ive a LONNGGG way to go lol).

firstly, i did as you suggested and made the gridref defination an init. it ends up the problem was that gridref and grid were not defined as inits. so now it works.

thanks
[ August 09, 2005: Message edited by: Seamus GalIagher ]
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
Glad to help, I'm also kind of beginning in Java Gaming... But maybe I should suggest you to use eclipse instead of JBuilder. If you have a decent machine it is worth a try!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using jbutton to change New objects