LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-12-2004, 09:43 AM   #1
linux_ub
Member
 
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


hi

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

eg

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

if i need
label.setBounds(10,10,100,20)
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, 09:50 AM   #2
leokor
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.

Leo
 
  


Reply


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 01:17 AM
same system variable, but with different contents? kpachopoulos Linux - General 1 07-31-2005 05:15 PM
get file contents with newlines into bash variable otoomet Linux - Software 2 01-06-2005 01:23 PM
Executing web based Perl programs in userdirs markham82 Linux - General 3 12-15-2004 07:49 PM
Controlling size of JLabel and JTextFields in Java linux_ub Programming 0 07-27-2004 08:32 AM


All times are GMT -5. The time now is 01:40 PM.

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