?
Solved

question about tag

Posted on 2004-04-27
13
Medium Priority
?
202 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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
Course of the Month11 days, 20 hours left to enroll

752 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