import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class HelloBob extends JApplet implements ActionListener
{
JLabel greeting = new JLabel("What is your name?");
Font bigFont = new Font("TimesRoman", Font.ITALIC, 24);
JButton pressMe = new JButton("Press Me");
JTextField answer = new JTextField("",10);
JLabel personalGreeting = new JLabel("");
FlowLayout flow = new FlowLayout();
public void init()
{
greeting.setFont(bigFont);
Container con = getContentPane();
con.add(greeting);
con.setLayout(flow);
con.add(answer);
con.add(pressMe);
con.add(personalGreeting);
pressMe.addActionListener(this);
answer.addActionListener(this);
answer.requestFocus();
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if(source == pressMe)
{
String name = answer.getText();
personalGreeting.setText("Hello " + name);
}
else if(source instanceof JTextField)
{
String name = answer.getText();
personalGreeting.setText("Hello " + name);
}
remove(greeting);
remove(answer);
remove(pressMe);
repaint();
}
}