How To Add Components And Event Handling To A Java Applet ?.

Applets in java are the client - side codes which are executed on the browser window. These are the small programs which are loaded by the browser and executed when requested. The application based applet running requires command as java AppletViewer. Thus the small application is launched and has lifecycle which ends in a particular frame of time.

Program to demonstrate an Applet with components and event handling

package com.hubberspot.applet.example ;

import java.applet.* ;
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;

/**/

public class AddComponentToApplet extends Applet  {
JPanel panel ;
JTextField textField  ;
String print ;

public void

init()  {
textField = new JTextField( 18 ) ;
add( textField ) ;
addMouseListener( new MouseAdapter() {

public void mouseClicked( MouseEvent event )  {

/> print = " Mouse Clicked :  X  =  " + event.getX()
+ "  Y  =  " + event.getY() ;
textField.setText( print ) ;
}
} ) ;

addMouseMotionListener( new MouseMotionAdapter() {

public void mouseMoved( MouseEvent event )  {
print =  " Mouse Moved : X  =  " + event.getX()
+ " Y  =  " + event.getY();
textField.setText( print ) ;
}
} ) ;
}

}


For more of such hot topics read my other posts here :

Visit my new website



Article Written By jontymagicman

I am DInesh Varyani.

Last updated on 26-07-2016 239 0

Please login to comment on this post.
There are no comments yet.
Program To Demonstrate How To Display File Information In Java ?.
How To Create A Simple Frame Using Swing Api In Java?.