User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: May 2007
Posts: 12
Reputation: kahilw is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kahilw kahilw is offline Offline
Newbie Poster

Swing Components

  #1  
Nov 1st, 2007
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;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Swing Components

  #2  
Nov 1st, 2007
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.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Swing Components

  #3  
Nov 1st, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC