Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday, 13 May 2015

java applet example of ActionListener java applet example of ActionListener

import java.awt.*;
import java.applet.*;
// import an extra class for the ActionListener
import java.awt.event.*;

public class ActionExample extends Applet implements ActionListener
{
     Button okButton;
     Button wrongButton;
     TextField nameField;
     CheckboxGroup radioGroup;
     Checkbox radio1;
     Checkbox radio2;
     Checkbox radio3;
     public void init() 
     { 
          setLayout(new FlowLayout());
          okButton = new Button("Action!");
          wrongButton = new Button("Don't click!");
          nameField = new TextField("Type here Something",35);
          radioGroup = new CheckboxGroup();
          radio1 = new Checkbox("Red", radioGroup,false);
          radio2 = new Checkbox("Blue", radioGroup,true);
          radio3 = new Checkbox("Green", radioGroup,false);
          add(okButton);
          add(wrongButton);
          add(nameField);
          add(radio1);
          add(radio2);
          add(radio3); 
          okButton.addActionListener(this);
          wrongButton.addActionListener(this);
         } 
         public void paint(Graphics g)
         {
 
          if (radio1.getState()) g.setColor(Color.red);
 
        else if (radio2.getState()) g.setColor(Color.blue);
          else g.setColor(Color.green);
 
 
          g.drawString(nameField.getText(),20,100);
     }
   public void actionPerformed(ActionEvent evt) 
         { 
              if (evt.getSource() == okButton)  
                   repaint(); 
          else if (evt.getSource() == wrongButton) 
          {
               wrongButton.setLabel("Not here!"); 
               nameField.setText("That was the wrong button!"); 
               repaint();
          }
     } 
}
/*<applet code="ActionExample.java" height=200 width=300></applet>*/

No comments:

Post a Comment