Hello all. I am new and I am having a tough time spotting my error here. The
idea is to produce an applet that will have a JButton which I can push to
display the string myName. Later I will make it so that it will chage the
font size and style, but for now I can't even get it to display the String.
It compiles fine but when I launch it in the browser or with the
appletviewer, it shows the button and nothing happens when I click it. Can
you see anything wrong with the way i set this up? Thanks in advance.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JBlueGrey extends JApplet implements ActionListener
{
String myName = new String("Randy");
JButton btnPush = new JButton("Push");
Font firstFont = new Font("Helvetica", Font.ITALIC, 8);
public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
con.add(btnPush);
btnPush.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == btnPush)
{
Graphics draw = getGraphics();
draw.setFont(firstFont);
draw.drawString(myName, 10, 100);
}
}
}