Results 1 to 4 of 4
- 02-23-2012, 05:40 PM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
How can I pass the JPanel as a reference with a button click ?
In my actionPerformed method, I want to pass the LanguagePanel object as the parameter, but this method as it is right now is passing the button.Java Code:public class LanguagePanel extends JPanel { private JButton turkishButton = new JButton("Turkish"); private JButton englishButton = new JButton("English"); private MainFrame mainFrame; public LanguagePanel(MainFrame frame) { this.mainFrame = frame; englishButton.addActionListener(new EnglishButtonListener()); this.add(englishButton); this.add(turkishButton); } class EnglishButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { mainFrame.setContentPane(this); } } }
Is there anyway I can pass the JPanel outer object that is holding the Button object as the parameter ?
- 02-23-2012, 05:43 PM #2
Re: How can I pass the JPanel as a reference with a button click ?
Actually, I would expect that to be passing the ActionListener. Are you just looking for the LanguagePanel.this keyword?
PS- This smells like a job for CardLayout.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-23-2012, 05:46 PM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: How can I pass the JPanel as a reference with a button click ?
I guess I should quit being lazy and learn CardLayout!! >:
- 02-23-2012, 05:50 PM #4
Re: How can I pass the JPanel as a reference with a button click ?
I could be wrong, but it looks like you want to change which JPanel is displayed when a button is pressed. If that's the case, then CardLayout is your friend here. If not, then I just don't fully understand your goals.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
How to remove a JPanel from a JFrame after a button click, and add a new one ?
By fatabass in forum New To JavaReplies: 8Last Post: 02-23-2012, 06:08 PM -
static variable /pass by reference
By katturv in forum New To JavaReplies: 15Last Post: 10-03-2010, 08:17 AM -
How to create pass by reference??
By --> xeiyne! in forum CLDC and MIDPReplies: 4Last Post: 04-08-2010, 06:43 PM -
Don't pass by reference
By Lyven in forum Advanced JavaReplies: 6Last Post: 11-16-2009, 06:06 PM -
Pass-by-reference
By popjava in forum New To JavaReplies: 1Last Post: 10-19-2009, 03:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks