| | |
Swing Components
![]() |
•
•
Join Date: May 2007
Posts: 12
Reputation:
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.
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list login loops mac main map method methods mobile netbeans notdisplaying number online printf problem program project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






