Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

question about tag

Posted on 2004-04-27
13
Medium Priority
?
205 Views
Last Modified: 2010-03-31
Hi,

I wonder if in Java Swing, I can use tags??  In C++, I can use tags to go back or go to somewhere I want to.  How can I do this in Java Swing??


Xenia
0
Comment
Question by:xenia27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 1

Expert Comment

by:shji1
ID: 10927800
As far as I know, there is no built-in mechanism in swing that is similar to the tags in C++ or VB.
You will probably have to build one on your own.
--
0
 
LVL 1

Expert Comment

by:shji1
ID: 10927891
You can try and use the setName() and getName() methods from the Component class as your tagging system.
Then, you will need to code some 'findComponentByName(String name)' method that will find it for you.
--
0
 

Author Comment

by:xenia27
ID: 10927900
Is there any example I can check out???  Kinda confused how can I do that....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 10927945
>> In C++, I can use tags to go back or go to somewhere I want to.
I don't know if it exists in Java.
But if you feel the need to "jump around" in your code that way, you have to ask yourself if you're coding correct.
It's the old "go to" discussion...

So, my advice is: keep yourself far from using tags in whatever language you're coding.
It's bad for readability and maintenance and most of the time it indicates the flow of your program could be improved.
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 600 total points
ID: 10927973
This article my interest you: http://java.sun.com/developer/TechTips/2000/tt0613.html (2nd part)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10928078
Somewhere else I read:
"In Java, break, continue, and label: fill the role of goto - as the article mentioned in my previous comment illustrates -, but without many of goto's negatives."

0
 
LVL 1

Accepted Solution

by:
shji1 earned 600 total points
ID: 10928488
Thuogh I never tried it myself, I can only advice you to follow these steps.
1. When you create a new instance of a component that you want to get access to in the future, name this component using the setName method.
2. When you want to gain the focus or to set the visibility on the component, you will need to search for it from the parent component. (recursively or by loops) using the getName method.

But now... The more I think of it, I believe that you can use a simple Map (HashMap) that can store the names (tags) as 'keys' and the Components themselfs as 'values'. In this case, every 'interesting' component that you create should have a key in the hashmap so you can gain access to it at any time in a very low complexity. Use the HashMap's put() method to place a mapping, and use the get() method to get the reference to the component.
I think this is a better way then the 'search by name' option.
Hope it helps.
shji1
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10928549
Xenia, it seems that shji1 and I are talking about quite different things.
Who is the nearest to what you meant to ask?
0
 

Author Comment

by:xenia27
ID: 10928584
Still working the flow of my codes...map seems too complicate....
so I guess I need to figure out a way to design my codes now...@@
0
 
LVL 1

Expert Comment

by:shji1
ID: 10928916
Maps are pretty handy if you need a quick mepping to an object, that is why I think it's best here.
They are not as complicated as you think, and actually, the only 2 methods you need to use here are the get and the put.
If you already wrote your application and you want to integrate the maps now, you can use the singleton design pattern in order to register you components into the map from anywhere in your code.
Hope it helps... (-;
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10928992
>> Who is the nearest to what you meant to ask?
Xenia,
are we talking about code flow (cf. my comments)
or
about component referencing? (cf. shji1's comments)
0
 

Author Comment

by:xenia27
ID: 10934664
mMmm...I think I will redesign the flow of my codes...but now I understand how to do tags...^^
I meant to know how to do the component referencing...but I guess I should try an easier way before I get myself into a big trouble...@@

Thanks for everything!!!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10936116
All right. Thanks for accepting.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question