How can I change the code below to applet?

import java.awt.*;
   import java.math.*;
   import javax.swing.*;
   import java.awt.event.*;


   public class Timer extends JFrame 
   {
      JButton start = new JButton("Start/Reset");
      JButton stop = new JButton("Stop");
      JLabel time = new JLabel("Time");
      javax.swing.Timer timer;
      int count = 0;
      public Timer()
      {
         super("Timer");
         addWindowListener(
               new WindowAdapter() 
               {
                  public void windowClosing(WindowEvent ev) 
                  {dispose();
                     System.exit(0);}});
         setBounds(10,10,300,150);
         getContentPane().setLayout(null);
         start.setBounds(10,30,100,24);
         start.setBackground(Color.green);
         stop.setBounds(10,60,100,24);
         stop.setBackground(Color.red);
         start.addActionListener(
               new ActionListener()
               {
                  public void actionPerformed( ActionEvent e )
                  {
                     count = 0;
                     timer.start();
                  }
               });
         stop.addActionListener(
               new ActionListener()
               {
                  public void actionPerformed( ActionEvent e )
                  {
                     timer.stop();
                  }
               });
         time.setBounds(150,30,100,24);
         time.setOpaque(true);
         time.setBackground(Color.pink);
         getContentPane().add(stop);
         getContentPane().add(start);
         getContentPane().add(time);
         timer = new javax.swing.Timer(1000, 
               new ActionListener() 
               {
                  public void actionPerformed(ActionEvent e)
                  {
                     count++;
                     time.setText(" "+count);
                  }
               });
         setVisible(true);
      }
      public static void main (String[] args) 
      {
         new Timer();
      }
   }

You could try creating a new class and transfer the main method over to that, then extend Applet and create an instance of your Timer class, not sure if this will give a lot of bugs though.

This article has been dead for over six months. Start a new discussion instead.