mixmaster
03-29-2009, 12:57 PM
what goes in the init(), start(), stop(), and destroy() methods?
what is the difference between
... extends Applet
... extends JApplet
lets say I have this simple code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Sample extends JPanel
{
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setTitle("Sample");
window.setSize(300,100);
window.setLocation(1,1);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setContentPane(new Sample());
window.show();
}
private JButton button;
private JLabel label;
public Sample()
{
setLayout(new FlowLayout());
button = new JButton("click me");
button.addActionListener(new Listener());
add(button);
label = new JLabel();
add(label);
}
private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button)
{
label.setText("you clicked the button");
}
}
}
}
what, from this code, goes in the above mentioned methods to get this to run as an applet?
what is the difference between
... extends Applet
... extends JApplet
lets say I have this simple code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Sample extends JPanel
{
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setTitle("Sample");
window.setSize(300,100);
window.setLocation(1,1);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setContentPane(new Sample());
window.show();
}
private JButton button;
private JLabel label;
public Sample()
{
setLayout(new FlowLayout());
button = new JButton("click me");
button.addActionListener(new Listener());
add(button);
label = new JLabel();
add(label);
}
private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button)
{
label.setText("you clicked the button");
}
}
}
}
what, from this code, goes in the above mentioned methods to get this to run as an applet?