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