I'm not sure I understand. Do you mean it's the name of a varable that holds a reference to the JMenu? E.g. JMenu bob = new JMenu("Edit"); Do you mean "bob" is something you might read out of a database?
Hmmm... offhand, I don't know a way. And my gut reaction is, why in the world would you want to do that anyway? I suspect there's another way to achieve whetever you're trying to do. How do the variable names get into the database anyway? And more importantly, why? If you're trying to "remember" something about the state of your application, there are other ways - most likely object serialization. Or if you want to use the database, perhaps you could store something else that you can access more easily, like the label text. This isn't sounding like a project for a beginner (I'm assuming you are one since you posted in this forum.) I'm betting there will be a much simpler way to do whatever you're trying to do, if you explain your goal.
thanks for your vote of non-confidence. heh heh. actually, what i'm trying to do is store the menu names in an oracle database so that i can enable or disable menubar items based on which user logs on to my gui. i am now trying to put the JMenu and JMenuItems in a vector and retrieve them as JMenuItems so that i can compare the text with my database strings and enable the corresponding JMenu component. i'll have to look up object serialization. thanks.
Sorry about the no-confidence. In my natural arrogance I tend to assume that if I don't understand someone, it's because they don't understand. Now that I have a bit more info, I see that's not necessarily the case. Also "beginner" can mean many things to different people - this seems more complex than I'd expect for what I consider a beginner. Your idea sounds promising. The question is, what strings will you store in the database, and later retrieve? The names of the variables which hold references to JMenuItems will probably not be very useful to you, but if you use the label text, it should work (provided each label text is unique). Or you could encode the info in a variety of ways - each menu item could correspond to a bit in a long, for example. Store the long in Oracle and read it later to determine which items to enable. Or assign each item an id code, and store the list of id codes. Consider what happens if you ever want to change the label text - old user records won't work correctly anymore. Using codes or bits, you can ensure that the underlying encoding still works even though the displayed text may change. Object serialization may not be what you'd want here, if each GUI client already has its own JMenuItem objects, and you're just trying to decide which ones to enable. Also if the user can log onto different systems, possibly running different JVMs, then things get thornier. Using the database as the central repository is proabably the correct approach. You'll want to learn about serialization eventually, but perhaps not for this. [This message has been edited by Jim Yingst (edited February 10, 2000).]
i think i will take your advice about storing ips. i don't know much about java, but i was assigned to work on a gui at work. and my supervisor lives in another state. so, i do tend to have difficulties explaining my java dilemmas to others since i have a tenuous grasp on it myself. thanks for your advice and patience. --cp
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss