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

Handling Focus Changes in Java

                         

Introduction

In this section, you will learn about handling the focus changes in java. This section shows you how the event be handled according to the focuses and to find out whether the component got the focus or lost the focus.  

This program determines the focus changes events. You can set the different-different events for the focused of the several components particularly. The generated focus events are performed by the FocusListener of the object used in your application using the addFocusListener() method. The generated event (FocusEvent) is passed to every FocusListener objects that receives such types of events using the addFocusListener() method of the object. The addFocusListener() method is takes the instance of MyFcousListener class.

MyFocusListener:
This is the inner class used in the FocusChange class in which, the focusGained() method has been used to receive the generated event. This method sets the text of the source of the event to the label component. This program displays the three command buttons on the frame. If you select any button of those then the text of that button will be shown on the label.

FocusAdapter:
This is the abstract class is used to receive the keyboard focus event. 

Here is the code of program:

import java.awt.*;
import java.awt.event.*;

public class FocusChange{
  Label label;
  public static void main(String[] args){
    FocusChange fc = new FocusChange();
  }

  public FocusChange(){
    Frame frame = new Frame("RoseIndia.Net");
    Panel panel = new Panel();
    Button yes = new Button("Yes");
    Button no = new Button("No");
    Button cancel = new Button("Cancel");
    yes.addFocusListener(new MyFocusListener());
    no.addFocusListener(new MyFocusListener());
    cancel.addFocusListener(new MyFocusListener());
    panel.add(yes);
    panel.add(no);
    panel.add(cancel);
    frame.add(panel,BorderLayout.NORTH);
    label = new Label();
    frame.add(label,BorderLayout.CENTER);
    frame.setSize(400,400);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent we){
        System.exit(0);
      }
    });
  }

  public class MyFocusListener extends FocusAdapter{
    public void focusGained(FocusEvent fe){
      Button bt = (Button)fe.getSource();
      String str = bt.getLabel();
      label.setText(str);
    }
  }
}

 

Download this example.

                         

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:
<logic:iterator>
pseudocode of magic sq
ล ยà¸?ฤ??????à¸
FileInputStream
struts2 csv result
Dreamweaver Behaviors
Mysql and jsp
custom tags
how to increase the er
message box display in
jsp MENU SELECT MAKES
java stack
javascript DB servl
Creating Website with
MULTIPLE SELECT COMBO
Very interesting tutor
insert data to text fi
merging pdf
TextArea Frame in Java
tomcate 5.0 downloadab
utility of collections
arraylist storing mult
dojo spinner
X10 Client and Server
create action listener
Murach ? ????s Beginni
Linux Caixa Mб?а
image type in java
Ã???????Ã??????Ã?????Ã
emailing file in java
how to compare current
numberStringsource
JavaScript functions o
parsing the string/str
<f:facet>tag
PHP Web Traffic Analys
User Registeration pag
how to upload image ur
Java Security A three-
core java
draw circle in C
hast table
csv reader
count the numbet of di
å???å????å????å???å???
sะà¸?ั?ยà¸?ะà¸
line break in javascri
break?ะ�ะ???????
iterator.next
check character/str.ph
interface
Configure jstl in web.
Two Dimensional Array
enterprise portal
add two numbers in jav
major
spring portlet
input two numbers thro
sax tutorial
popup window
Linux Caixa MаÐ??аÐ?
Checking
desicont
highlighting and dehig
ASP EXAMPLE' and char(
how to get applicate s
jndi example
sleep
how to create to drop
log4j
PHP Date and .....:/pw
PHP Date and .....:/pw
servlets container
logout in jsp
array java
Insert Data into Datab
Javascript Randomizing
insert column
JDBC and Mysql
CMP
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.