PDA

View Full Version : Resolved init(),start(),stop(),destroy()


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?

servlet
03-30-2009, 10:35 AM
See http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html for applet life cycle methods.

Applet belongs to AWT where as JApplet belongs to swing

mixmaster
03-30-2009, 01:06 PM
sweet, thanks!