Solved

question about tag

Posted on 2004-04-27
13
198 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 150 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 150 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

861 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