•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,586 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,621 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 316 | Replies: 2
![]() |
•
•
Join Date: May 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
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;
}
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.
That's about all I can comment on without understanding more of what you are trying to do.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- java calendar SWING (Java)
- AWT versus Swing (Java)
- Copy and paste Components (Java)
- Displaying GUI components relating to FloatControls (Java Sound) (Java)
- Fonts (Java)
- look and feel (Java)
- Stop Watch (Java)
- Applet or Application? (Java)
Other Threads in the Java Forum
- Previous Thread: How to solve in Mysql
- Next Thread: build but not run... need a second set of eyes



Linear Mode