• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using jbutton to change New objects

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why cant you use grid[r][c]???

post some code maybe we would be able to come up with a solution!
 
Seamus GalIagher
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic