View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-12-2004, 10:43 AM   #1
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 17
[JAVA - JLabel] executing a method based on contents of the variable


i have a class which had a JPanel a JLabel and a JTextField ....

it has constructor methods for intializing the text of label and text field ...
it has set methods and get methods for setting and getting text, etc

the problem is ... i need this class to be generic ... i dont want to and i cant sit down and code all the possible methods for a JLabel object. i want to have a set method which accepts teo strings where the 1st is the property name like setBackground or setBounds and the second one is the parameters to be passed to the method


if i need
i want to call a function
setLabel (String a, String b)
where a = "setBackGround"
and b = "Color.White"

if i need
i want to call a function
setLabel(String a, String b)
where a = "setBounds"
and b = "10,10,100,20"

thanks a lot
Old 08-12-2004, 10:50 AM   #2
LQ Newbie
Registered: Aug 2004
Location: Brookline, MA, USA
Posts: 8

Rep: Reputation: 0
Use the Java's Reflection API. Check the javadocs for such classes as Class, Method, Constructor, etc.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
using CSS to format HTML in a Java - JLabel caged Programming 1 09-26-2005 02:17 AM
same system variable, but with different contents? kpachopoulos Linux - General 1 07-31-2005 06:15 PM
get file contents with newlines into bash variable otoomet Linux - Software 2 01-06-2005 02:23 PM
Executing web based Perl programs in userdirs markham82 Linux - General 3 12-15-2004 08:49 PM
Controlling size of JLabel and JTextFields in Java linux_ub Programming 0 07-27-2004 09:32 AM

All times are GMT -5. The time now is 01:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration