| |
| This applet is a very slightly modified version of
the applet from the previous lesson. The message it displays
when the user clicks the button is received as a parameter
from the HTML within the Web page. |
| |
| To test the applet, a tag such as <applet> must
exist in the App.php source file between the ...> and tags.
To verify that the tag exists, or to add it if it doesn't, use
any text editor (such as Notepad ). |
| |
| The applet's code is as follows: |
| |
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class App extends Applet implements ActionListener
{
Button b = new Button("Show message");
TextField message = new TextField("", 15);
public void init()
{
resize(300, 100);
setBackground(Color.lightGray);
b.addActionListener(this);
add(b);
message.setFont(new Font("Serif", Font.ITALIC, 24));
message.setForeground(Color.red);
message.setEditable(false);
add(message);
}
public void actionPerformed(ActionEvent e)
{
if (message.getText().length() == 0)
{
message.setText(getParameter("message"));
b.setLabel("Clear message");
}
else
{
message.setText("");
b.setLabel("Show message");
}
}
} |
|