Solved

question about tag

Posted on 2004-04-27
13
195 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
  • 6
  • 4
  • 3
13 Comments
 
LVL 1

Expert Comment

by:shji1
Comment Utility
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
Comment Utility
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
Comment Utility
Is there any example I can check out???  Kinda confused how can I do that....
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> 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 150 total points
Comment Utility
This article my interest you: http://java.sun.com/developer/TechTips/2000/tt0613.html (2nd part)
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
shji1 earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
All right. Thanks for accepting.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
sumDigits  challenge 7 60
bitbucket vs gitbucket 3 29
how do i compare an object based on two fields 6 28
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now