import java.awt.*; import java.awt.event.*; import java.applet.*; /** Written by Lin Jensen June 6, 2005 As an introduction to Applets. This one has a paint() method and a button which changes the painted text See also June6, which just has the label */ public class June6_2 extends Applet implements ActionListener { private String myText = "By Lin Jensen"; private Label myMessage = new Label("Hello World"); // may be changed by param private Button myButton = new Button("Press me"); public void init() { String text = getParameter("custom"); if (text != null) myMessage.setText(text); add(myButton); // add button add(myMessage); // & label component to applet myButton.addActionListener(this); setBackground(Color.yellow); } public void paint(Graphics g) { g.drawString(myText,5,90); } public void actionPerformed(ActionEvent e) { myText = myText + " .. again"; // myMessage.setText(myText); // it's not a good idea to lengthen a label text repaint(); } }