Credits

Thursday, September 30, 2010

Intro on Java Applets

The very reason why Java has overwhelmed the greater public is because it is internet - capable and oriented. And with the basics of object - oriented  programming, Java allows reusability of codes making it more acceptable.

With Java's applets, we can create little utility codes or applets to run in our browser, offline or online. You can actually run your Java applet - embedded through your Java software's applet viewer or through an HTML document that calls for your java program.

Unlike a typical Java program, your applet does not require any main method; using the different stages of applet, it can run successfully without main method.

The program below illustrates this example.



[+/-] show/hide


import java.applet.*;
import java.awt.*;

import java.awt.event.*;

public class AppletFinalExercise1 extends Applet implements ActionListener{
Label myTeam = new Label(" ");
Button myQuestion= new Button("Who is your number 1 team?");
Font myFont = new Font("Dialog",Font.BOLD+Font.ITALIC,17);
@Override
public void init(){
myQuestion.addActionListener(this);
add(myQuestion);
add(myTeam);

}

public void actionPerformed(ActionEvent e)
{
myTeam.setLocation(20,0);
myTeam.setFont(myFont);
myTeam.setText("Purefoods");

}

}

AddThis