HOW TO CREATE A BUTTON

This is the simplest program to understand how to apply button to the applet.
Save the program by button_click.java 
To compile the program in ubuntu type: javac button_click.java
To run the program type java button_click

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class button_click extends Applet implements ActionListener
{
int state;
Checkbox xp,linux,obj;
Button ok;
TextField disp;
public void init()
{
 xp=new Checkbox("  Windows XP");
 linux=new Checkbox(" Linux");
ok=new Button("   OK   ");
disp=new TextField(25);
add(xp);
add(linux);
add(ok);
add(disp);

ok.addActionListener(this);

}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==ok)
 {
if(xp.getState()==true)
  disp.setText(xp.getLabel());
else
  if(linux.getState()==true)
  disp.setText(linux.getLabel());
}
}
}
/*<applet code=button_click.class width=225 height=200>
</applet>  */

Comments

Popular posts from this blog

Write a java program to create an abstract class named Shape that contains two integers and an abstract method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea( ) that prints the area of the given shape.

Create Employee Class with Method getdata and setdata. Create following subclasses to generate biodata. i) Personal record ii)) Professional record iii) Academic record Assume appropriate data members and member function to accept required data & print bio-data. Use Overriding at suitable places.Create bio-data using multilevel inheritances.

Exception_Handling Program