Java help

If you touch your software enough does it become hardware?

Moderator: Forum Moderators

Post Reply
buzzmong
Weighted Storage Cube
Weighted Storage Cube
Posts: 7167
Joined: February 26th, 2007, 17:26
Location: Middle England, nearish Cov

Java help

Post by buzzmong »

Bascially, I'm in a bit of a pickle due to the way I've structured my program and the way java handles tabs in an application.

The program has two tabbed panes, in the first of the tabbed panes I've got a String Array being generated *after* the user and program has performed a number of actions on the input they enter on that pane.
All dandy so far.

However, what I need is that array to be accessible from within the 2nd panel, and for the life of me I can't think how to access it due to it being buried a couple of levels down in the first panel.

Code: Select all

Program structure:

Main.java  -> GuiTabs.java -> LexPanel (the string [] is in here)
                          -> SynPanel (I need to use the array here after it's been filled with data from the LexPanel).

There's also a Token class which isn't linked but used by both.
Any ideas?
Fear
Zombie
Zombie
Posts: 2032
Joined: August 6th, 2006, 21:45

Post by Fear »

I'm no java guru, but i'd expect something like

Code: Select all

this.parent.LexPanel.YourStringArray
to work.
buzzmong
Weighted Storage Cube
Weighted Storage Cube
Posts: 7167
Joined: February 26th, 2007, 17:26
Location: Middle England, nearish Cov

Post by buzzmong »

I wish it would as I've already tried that, appears to have no way of accessing a parent (that I've found anyway) outside of visual objects.
Stoat
Site Admin
Site Admin
Posts: 3291
Joined: October 8th, 2004, 15:48
Location: Sheffield, UK
Contact:

Post by Stoat »

Have you tried this?

Code: Select all

this.parent.LexPanel.YourStringArray.please
Can't hurt.
deject
Berk
Berk
Posts: 10353
Joined: December 7th, 2004, 17:02
Location: Oklahoma City, OK, USA
Contact:

Post by deject »

How is the array defined?
buzzmong
Weighted Storage Cube
Weighted Storage Cube
Posts: 7167
Joined: February 26th, 2007, 17:26
Location: Middle England, nearish Cov

Post by buzzmong »

deject wrote:How is the array defined?
As a return value in a public get method in LexPanel. I could define it as a seperate public String[] inside the LexPanel class, but that's not the issue.

Currently I access the get and set methods in GuiTabs, using the instances of LexPanel and SynPanel, which is fine incidently, however obivously it only runs that at compilation and not whenever I need it to at run time.

I was hoping I could just call a parent method from the SynPanel instance seeing as java doesn't do object by reference, but looking at it, I might be able to pull some checks to do with the focus of the panels and just call it then.
Dr. kitteny berk
Morbo
Morbo
Posts: 19676
Joined: December 10th, 2004, 21:53
Contact:

Post by Dr. kitteny berk »

... Got any jam?
deject
Berk
Berk
Posts: 10353
Joined: December 7th, 2004, 17:02
Location: Oklahoma City, OK, USA
Contact:

Post by deject »

Wait what? Java does everything but primitives by reference.

Have you tried storing the array in the main method then passing it to the SynPanel?
Fear
Zombie
Zombie
Posts: 2032
Joined: August 6th, 2006, 21:45

Post by Fear »

Pass a reference to the parent when you initialise the child. The child can then store that reference so it can talk back to the parent.

You could even pass a reference to the string array if you really wanted - but a reference to the parent should cover you in every circumstance.

I'm surprised the base object class in Java (from which all classes will inherit) doesn't contain such simple functionality as standard.
HereComesPete
Throbbing Cupcake
Throbbing Cupcake
Posts: 10249
Joined: February 17th, 2007, 23:05
Location: The maleboge

Post by HereComesPete »

Fear wrote:a reference to the parent should cover you in every circumstance.
Even if the circumstance is

"They knew what I was doing! They let me touch him in his naughty place!"

?


/unhelpful
buzzmong
Weighted Storage Cube
Weighted Storage Cube
Posts: 7167
Joined: February 26th, 2007, 17:26
Location: Middle England, nearish Cov

Post by buzzmong »

:)

Well, I've manged to get the information I need across, as noted by my extremely dodgy use of JOptionPanes in the debugging process.

The JList doens't want to update properly, but that's a minor issue and I'm sure I can make it bend to my will.


As a note, I ended up sending the instance of the LexPanel class into the SynPanel when I initialised it a few lines down. I get the data, it's all that matters.

Cheers Fear and Deej.
Post Reply