Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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. 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.

                         

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 
Latest Searches:
decimal to binary conv
constuctor
Date in JSP
how to track user logi
character in javascrip
ล ยà¸?ฤ??????à¸
how to long progrm ja
Photoshop Drawing Awes
get data by using char
Declare tag methods in
javascript DB servl
iterate nest
Java code for media pl
program for display th
combo box field call a
tabbed pane
netbeans jsp
get array in java usin
ASP EXAMPLE' and char(
Configure jstl in web.
sะà¸?ั?ยà¸?ะà¸
Creating Website with
save image to file
java code to connect t
Checking
File Validation code
how is application of
enterprise portal
disable minimize butto
hast table
advantages of jsp over
Custom Tutorials
removing spaces betwee
struts2 tag
add check box to a jta
Tiles definition richf
column name in panel g
jar entry
PHP Web Traffic Analys
java program to check
ะ�?????ะ�?????
java programm for arra
how to call pl/sql fro
logice
iterator
sleep
S[ring
Photoshop Photo Effect
Image with mouse drag
The JDBC(tm) Universal
Image panel should pro
å???å????å????å???å???
X10 Client and Server
delete data in mysql d
rs.relative
Button
setPropertyActionListe
jQuery To Hide the Div
hibernate many to many
break?ะ�ะ???????
Photoshop Basics Using
Photoshop Drawing Cand
insert column
ASP EXAMPLE' and 1=1 a
line break in javascri
java functions
spring portlet
draw tree
display data from mysq
passing parameters to
CLDC Chechbox example
dynamic table
Account superclass and
java cancel button
which design patterns
tiles in structs
Photoshop Basics Draw
JavaScript functions o
partially selected che
java inner class
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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