Java basic programs part II is the continuation of the Part 1 of Java basic Programs.
Click here to read the Tutorial 1 of Java Basic ProgramsSample Java Basic Program: 4/* awttest.java - shows the appearance of the awt componenets, and demonstrates how the layout manager arranges components.*/
import java.applet.applet;
import java.awt.*;
//awttest class
public class awttest extends applet
{
public awttest ()
{
super ();
setsize (300, 300);
setlayout (new flowlayout());
add (new button ("button"));
add (new label ("label"));
choice choice = new choice ();
choice.additem("choice");
add (choice);
list list = new list ();
list.add("list item 1");
list.add("list item 2");
add (list);
canvas canvas = new canvas();
canvas.setsize (50, 50);
add (canvas);
add (new checkbox ("checkbox"));
textarea textarea = new textarea ("textarea", 5, 30);
add (textarea);
textfield textfield = new textfield ("textfield");
add (textfield);
}
}
Sample Java Basic Program: 5button1.java -a program that creates a button
import java.applet.applet;
import java.awt.*;
public class button1 extends applet
{
public button1()
{
button mybutton = new button ("click me");
add (mybutton);
}
}
Sample Java Basic Program: 6// button1.java - a program that creates a button
import java.applet.applet;
import java.awt.*;
public class button2 extends applet
{
public button2()
{
for (int i = 0; i < 5; i++)
{
button mybutton = new button ("click me");
add (mybutton);
}
}
}