TestParam.java
Select all
import java.awt.*; import java.applet.*; import java.awt.event.*; public class TestParam extends Applet { String[] msg = {"Greetings, ", "Go away "}; String toDisplay = ""; String name = ""; int currentMessage = 0; public void init() { setBackground(Color.yellow); name = getParameter("Name"); if (name == null) name = "Anonymous"; Button btn = new Button("Change message"); add(btn); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { currentMessage = ++currentMessage % msg.length; setMessage(currentMessage); repaint(); } }); setMessage(currentMessage); } public void paint(Graphics g) { super.paint(g); g.drawString(toDisplay, 50, 150); } private void setMessage(int n) { toDisplay = msg[n] + name; } }