Hello I am making a "Superclass" that provides a programmer easier means of constructing a java panel by providing a template so as not to reuse code over and over. I have reached a point where I am trying to allow the programmer to call one method with in my "Superclass" and it will then add three buttons onto the frame. The problem is that it will only show one button. I am trying to figure out a way to return these three buttons at the same time. can anyone help me the code is below

Component ButtonGroup(String ButtonName){
jButton1 = new JButton();
jButton1.setText(ButtonName);
jButton1.setBounds(161, 231, 100, 28);
ButtonGroup1(ButtonName);
ButtonGroup2(ButtonName);
return jButton1;
}
Component ButtonGroup1(String ButtonName){
jButton1 = new JButton();
jButton1.setText(ButtonName);
jButton1.setBounds(50, 231, 100, 28);
return jButton1;
}
Component ButtonGroup2(String ButtonName){
jButton2 = new JButton();
jButton2.setText(ButtonName);
jButton2.setBounds(300, 231, 100, 28);
return jButton2;
}

You want it to place them on the form or just create and return them? Having three methods that only differ in the setBounds() parameters is just unnecessary code duplication and none of those methods places anything. If you just need to create and return the three buttons, your method could return a List of the buttons. If it needs to place them then you'll need a reference to the container in which they should be placed.

That's about all I can comment on without understanding more of what you are trying to do.

Such things are generally a bad idea.

What is a good idea is creating a library of commonly (in your context) used compound components that users can configure and use as required.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.