Hi Everyone... I need to convert a JFRAME to an APPLET
can I do that by simply extending the JApplet Class and replacing the
main method with start ? I've tried this and my program will compile but wont run

Here Is the Original Code

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

public class CardGameCH15 extends JFrame
{
	public CardGameCH15()
	{
		super("Card Game");
		setLayout(new BorderLayout());
		setSize(500,200);
		add(new CardTable());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args)
	{
		new CardGameCH15();
	}

	class CardTable extends JPanel implements ActionListener
	{
		String card;
		ImageIcon cardIcon;
		JButton dealButton = new JButton("Deal 5");
		CardDeck deck;
		JLabel card1 = new JLabel("");
		JLabel card2 = new JLabel("");
		JLabel card3 = new JLabel("");
		JLabel card4 = new JLabel("");
		JLabel card5 = new JLabel("");

		public CardTable()
		{
			setLayout(new FlowLayout());

			deck = new CardDeck(1);
			dealHand();
			add(card1);
			add(card2);
			add(card3);
			add(card4);
			add(card5);
			add(dealButton);
			dealButton.addActionListener(this);
		}

		public void actionPerformed(ActionEvent e)
		{
			dealHand();
		}

		private void dealHand()
		{
			String str;

			if((str = deck.getCard()) != null)
				card1.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card2.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card3.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card4.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card5.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
		}
	}
}

and Here is my revision

import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CardGameCH15 extends JApplet
{
	public CardGameCH15()
	{

		setLayout(new BorderLayout());
		setSize(500,200);
		add(new CardTable());
		setVisible(true);
	}

	public void start()	{
		new CardGameCH15();
	}

	class CardTable extends JPanel implements ActionListener
	{
		String card;
		ImageIcon cardIcon;
		JButton dealButton = new JButton("Deal 5");
		CardDeck deck;
		JLabel card1 = new JLabel("");
		JLabel card2 = new JLabel("");
		JLabel card3 = new JLabel("");
		JLabel card4 = new JLabel("");
		JLabel card5 = new JLabel("");

		public void init()
		{
			setLayout(new FlowLayout());

			deck = new CardDeck(1);
			dealHand();
			add(card1);
			add(card2);
			add(card3);
			add(card4);
			add(card5);
			add(dealButton);
			dealButton.addActionListener(this);
		}

		public void actionPerformed(ActionEvent e)
		{
			dealHand();
		}

		private void dealHand()
		{
			String str;

			if((str = deck.getCard()) != null)
				card1.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card2.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card3.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card4.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card5.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
		}
	}
}

Any help would be greatly Appreciated

Thanks so much...That is exactly what im looking for... should i need to change anything else?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;

public class CardGameCH15 extends JApplet{
	//Create labels to display cards
	private JLabel card1 = new JLabel("");
	private JLabel card2 = new JLabel("");
	private JLabel card3 = new JLabel("");
	private JLabel card4 = new JLabel("");
	private JLabel card5 = new JLabel("");
	private JButton dealButton = new JButton ("Deal");
	String card;
	ImageIcon cardIcon;
	
//Initialize Interface
public void init(){

	setLayout (new FlowLayout());
	setSize (500,200);
	setVisible(true);
//Create JPanel to hold card images
JPanel p1 = new JPanel(new GridLayout(5,2));
	p1.add(card1);
	p1.add(card2);
	p1.add(card3);
	p1.add(card4);
	p1.add(card5);
//Create JPanel To Hold Deal Button
JPanel p2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	p2.add(dealButton);

//Add Panels to Applet
	add(p1, BorderLayout.CENTER);
	add(p2, BorderLayout.SOUTH);
//Register Listener
			dealButton.addActionListner(new ButtonListener());
}

private class ButtonListener implements ActionListener {

	public void actionPerformed(ActionEvent e){
					dealHand();
	}
}
	
		public void dealHand()
		{
			String str;

			if((str = deck.getCard()) != null)
				card1.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card2.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card3.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card4.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
			if((str = deck.getCard()) != null)
				card5.setIcon(new ImageIcon("image/card/" + str));
			else
				return;
		}
	}

Ok anyone know why Im getting this error??

CardGameCH15.java:43: cannot find symbol
symbol : method addActionListner(CardGameCH15.ButtonListener)
location: class javax.swing.JButton
dealButton.addActionListner(new ButtonListener());

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