0

I'm busy with an application which runs in a JFrame (using BorderLayout), and has:

  • A status bar at the bottom
  • Fixed Buttons on the left
  • Menu on top (which change relating to specific function),
  • Buttons on the right (which change relating to specific function).

I'm setting it up that for every button on the left, a separate class file will be created for its functions and procedures. At this stage it's about 8 extra classes.

How to go about changing the values on the buttons and menu for each class, by that specific class?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    One way might be to give each class a method like `public Action[] getActions()` that returns the actions appropriate to the class. On loading/changing to that functionality, call the method and add them to the tool-bar or menu. – Andrew Thompson Apr 18 '12 at 14:21
  • @AndrewThompson has the correct insight; see also this related [example](http://stackoverflow.com/a/4039359/230513). – trashgod Apr 18 '12 at 19:25

1 Answers1

0

If you're creating a separate class for each button, I would make sure that the class extends JButton. By doing this, to change the values on the buttons, you still have access to all the normal JButton methods like setText();

So hopefully your custom button classes would look something like this...

public class MyButton1 extends JButton {

    public MyButton1(String label){
        super(label);
    }

// your other methods go here
}

To create the button you would do this, which would set the button label...

MyButton1 button1 = new MyButton1("Hello");

And you can still call JButton methods if you want to change the label later, like this...

button1.setText("Goodbye");
wattostudios
  • 8,666
  • 13
  • 43
  • 57