4 Replies - 1510 Views - Last Post: 28 March 2011 - 02:10 AM Rate Topic: -----

#1 Ebisu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 09-June 10

How can I use setEnabled() from different classes?

Posted 27 March 2011 - 01:46 PM

Hey,

I have 2 classes that make different frames. When I press a button on frame one it becomes disabled and frame 2 is shown.
when I press a button on frame two it hides and frame one should be re enabled.

I can't seem to get frame one to re enable from frame two, is there a way to access setEnabled from a different frame?
Is This A Good Question/Topic? 0
  • +

Replies To: How can I use setEnabled() from different classes?

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How can I use setEnabled() from different classes?

Posted 27 March 2011 - 03:12 PM

Just pass your first JFrame as parameter to the constructor of the second class

class MyFrame extends JFrame  {
...

    OtherFrame of = new OtherFrame(this);

}

class OtherFrame {
   private MyFrame father;
   // constructor
   OtherFrame(MyFrame father) {
      this.father = father;
      ...
   }
....
   father.setVisible(false);


Was This Post Helpful? 2
  • +
  • -

#3 Ebisu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 09-June 10

Re: How can I use setEnabled() from different classes?

Posted 27 March 2011 - 03:47 PM

Never mind it was because I was extending the first frame ( cant see a way to delete this)

This post has been edited by Ebisu: 27 March 2011 - 03:50 PM

Was This Post Helpful? 0
  • +
  • -

#4 Ebisu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 09-June 10

Re: How can I use setEnabled() from different classes?

Posted 27 March 2011 - 11:47 PM

Hey again,

Is it possible to do this with 3 frames like:

frame one is the father of frame 2 which is the father of frame 3.

the above code worked for making frame 2 the father of frame 3, but when I tried replicating it to make frame one the father of frame two I get a stack overflow error pointing at the constructor of frame 2.
Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: How can I use setEnabled() from different classes?

Posted 28 March 2011 - 02:10 AM

Yes, the same technique will work to make Frame1 the 'owner' of Frame2, Frame2 the owner of Frame3, etc. Without code to see what you've done, it's hard to be more helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1