Pin It

How to add components and event handling to a Java Applet ?.

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);
 }
  });
 }

}
Output of the program :


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot