An ActionEvent
, same as for an application.
Here is the code that was compiled for the class file
TextRepeaterApplet.class
.
Most of it should look familiar.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TextRepeaterApplet extends JApplet implements ActionListener { JTextField source, destination; public void init() { source = new JTextField("", 15); destination = new JTextField("", 15); setLayout(new FlowLayout() ); add( new JLabel("Enter Your Name:") ); add(source); add( new JLabel("Here is Your Name:") ); add(destination); source.addActionListener( this ); this.setBackground(Color.white); } public void actionPerformed( ActionEvent evt ) { destination.setText( source.getText() ); repaint(); } }
The code is shorter than for the application because there
is no need for a main()
method.
To run the applet, what must be done?