Java is similar to C in some respects but it philosophy is much closer to Object Pascal. The following code is all that is requried to produce the hello applet embedded in this page.
import java.applet.*;
import java.awt.*;
public class Hello extends Applet
{
private Button clearBtn;
private Button drawBtn;
private String drawStr="";
public Hello(){} // the constructor for the class
public void init()
{// called to initialize the applet
this.setBackground(Color.white);
clearBtn= new Button("Clear");
this.add(clearBtn);
drawBtn= new Button("Draw");
this.add(drawBtn);
}
public boolean action(Event evt, Object arg)
{// handle the button clicks
if(evt.target==clearBtn)
{
drawStr="";
repaint();
return true;
}
else if (evt.target==drawBtn)
{
drawStr="Hello World";
repaint();
return true;
}
else return super.action(evt,arg);
}
public void destroy(){}
public void paint(Graphics g)
{// paint the string
Rectangle r=this.bounds();
g.drawString(drawStr, r.width/2, r.height/2);
}
public void start(){}
public void stop(){}
}