Learn how to activate a Button control using Java | Learnxpress

Learn how to activate a Button control using Java

March 24th, 2009 Anand Narayanaswamy 0 Comments

In this code snippet, you will learn how to activate a Button control using Java

/*<applet code = "Mybutton.class"
width = 250 height = 250></applet> */
//Compilation: javac Mybutton.java
//Execution: appletviewer Mybutton.java
import java.awt.*;
import java.awt.event.*;
public class Mybutton extends
Applet implements ActionListener
{
String msg = "":
Button byes, bno;
public void init()
{
byes = new Button("Yes");
add(byes);
byes.addActionListener(this);
bno = new Button("No");
add(bno);
bno.addActionListener(this);
}
//implementing the interface method
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();
if (str.equals("Yes"))
{
msg = "You pressed Yes";
else if (str.equals("No"))
{
msg = "You pressed No";
}
}
}
public void paint(Graphics g)
{
g.drawString(msg,6,100);
}
//end of class
}
 

If You Like This Post, Share it With Your Friends & Peers

Digg
stumbleupon
Delicious
facebook
twitter
reddit
rss feed bookmar
   

No Comment to “Learn how to activate a Button control using Java”

  1. No Comment yet. Be the first to comment...

Leave your comment here:

Terms

  • activating buttons in java
  • how to activate buttons in java applet
  • how to activate a button in java application
  • how to activate buttons in java
  • how to use buttons in java
  • how to activate an control buttons using html
  • java button control
  • using buttons java
  • create button using java
  • activating a button in java
  • using buttons in java

  • how to activate a button in java
  • using button in java
  • activating buttons
  • use button with graphics in java
  • creation of active buttons using java
  • java button contol
  • activate a button in java
  • button control in java
  • how to activate a button
  • seo forum


Google Analytics Alternative