Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Common Component Methods 
 

The common methods of AWT components are as follow: 1 getLocation() - This method is used to get position of the component, as a Point.

 

Common Component Methods

                         

The common methods of AWT components are as follow:

1 getLocation() - This method is used to get position of the component, as a Point. The usage of the method is shown below.

Point p = someComponent.getLocation(); 
int x = p.x; 
int y = p.y; 

One point to note here is that if you are working on Java 2 Platform then you need not to create a new point object. The x and y parts of the location can be easily accessed by using getX() and getY(). It is always efficient to use getX() and getY() methods. For example,

int x = someComponent.getX(); 
int y = someComponent.getY(); 

2. getLocationOnScreen() - This method is used to get the position of  the upper-left corner of the screen of the component, as a Point. The usage of the method is shown below.

Point p = someComponent.getLocationOnScreen(); 
int x = p.x; 
int y = p.y; 

It is always advisable to use getLocation(); method if you are working on Java 2 platform.

3. getBounds() - This method is used to get the current bounding Rectangle of component. The usage of the method is shown below.

Rectangle r = someComponent.getBounds(); 
int height = r.height; 
int width = r.width; 
int x = r.x; 
int y = r.y; 

One point to note here is that if you need a Rectangle object then the efficient way is to use getX(), getY(), getWidth(), and getHeight() methods while working on Java 2 platform.

4. getSize() - This method is used to get the current size of component, as a Dimension. The usage of the method is shown below.

Dimension d = someComponent.getSize(); 
int height = d.height; 
int width = d.width; 

Again, it is always advisable to use getWidth() and getHeight() methods to directly access the width and height while working on Java 2 platform. You can also use getSize() if you require a Dimension object. For Example,

int height = someComponent.getHeight(); 
int width = someComponent.getWidth(); 

5. setBackground(Color)/setForeground(Color) -
This method is used to change the background/foreground colors of the component.

6. setFont(Font) - This method is used to change the font of text within a component.

7. setVisible(boolean) - This method is used for the visibility state of the component. The component appears on the screen if setVisible() is set to true and if its set to false then the component will not appear on the screen. Furthermore, if we mark the component as not visible then the component will disappear while reserving its space in the GUI.

8. setEnabled(boolean) - This method is used to toggle the state of the component. The component will appear if set to true and it will also react to the user. ON the contrary, if set to false then the component will not appear hence no user interaction will be there.

                         

» View all related tutorials
Related Tags: c class make method sed boolean value ole set oo frame if boo to ram bool argument e il not

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.