Wednesday, 11 December 2013

Graphic java course, Action listener in Applet [ Part 8 ]

Action listener in Applet 


Create a class named "UICDemo"


Extends the class to Applet


Now add Button 

        btnOk=new Button("ok");
\\Creating button named btnOk

        btnOk.setBounds(100, 100, 100, 100);

\\Setting size of button

Implementing ActionListener

 public class okey implements ActionListener{
              }



Source code
=========

       

import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
/**
 *
 * @author Backtrace
 */
public class UICDemo extends Applet 
{
    Button btnOk;
    public void init()
    {
        setLayout(null);
        btnOk=new Button("ok");
        btnOk.setBounds(100, 100, 100, 100);
        btnOk.addActionListener(new okey());
       add(btnOk);
     }
   public class okey implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) 
        {
           btnOk.setLabel("Button");
        }
    
                                              }
    } 

        
    


Output
=====

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes