• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

converting types

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i convert a string(name of a JMenu) retrieved from a database into a JMenu (so i can enable a MenuBar)?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a constructor: new JMenu(String). Read about it at http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JMenu.html#JMenu(java. lang.String).
 
cp954
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response. However, my string is actually the name of the JMenu not the menu label.

Originally posted by Jim Yingst:
There's a constructor: new JMenu(String). Read about it at http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JMenu.html#JMenu(java. lang.String).


 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
cp954
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes!
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
cp954
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
cp954
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic