/**
* JJoker.java - Cory J. Goldfuss - 05 Feb 2001
* Program is derived from Joker.java, which had trouble with
* Symantec classes. New Swing approach rectifies the problems.
* --------------------------------------------------------------
* Program "knows" which card the user is selecting. It is also good
* to mention that this is purely a joke and does not acutally find your
* card. It merely shows all new cards after "removing" yours.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JJoker extends JApplet implements ActionListener, ItemListener
{
private int counter = 0; //keep track to help with timing
private String[] StatusList = {"Shuffling....", "Deducing....", "Removing Card...."};
private int statusIndex = -1;
private JLabel[] Labels;
private int labelIndex = -1;
private Timer labelTimer;
private Timer statusTimer;
private ButtonGroup radioGroup;
private Timer cardTimer;
private JLabel[] cards;
private int cardIndex = 0;
private ImageIcon kh; // king 'o hearts
private ImageIcon jc; // jack 'o clubs and so on
private ImageIcon qd;
private ImageIcon ks;
private ImageIcon qc;
private ImageIcon jd;
private ImageIcon qh;
private ImageIcon jh;
private ImageIcon qs;
private ImageIcon kd;
private ImageIcon kc;
public void init()
{
// This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
// Add my icons
kh = new ImageIcon( getImage( getCodeBase(), "kh.gif"));
jc = new ImageIcon( getImage( getCodeBase(), "jc.gif"));
qd = new ImageIcon( getImage( getCodeBase(), "qd.gif"));
ks = new ImageIcon( getImage( getCodeBase(), "ks.gif"));
qc = new ImageIcon( getImage( getCodeBase(), "qc.gif"));
jd = new ImageIcon( getImage( getCodeBase(), "jd.gif"));
qh = new ImageIcon( getImage( getCodeBase(), "qh.gif"));
jh = new ImageIcon( getImage( getCodeBase(), "jh.gif"));
qs = new ImageIcon( getImage( getCodeBase(), "qs.gif"));
kd = new ImageIcon( getImage( getCodeBase(), "kd.gif"));
kc = new ImageIcon( getImage( getCodeBase(), "kc.gif"));
cards = new JLabel[5]; //For easy card handling
cards[0] = Jcard1;
cards[1] = Jcard2;
cards[2] = Jcard3;
cards[3] = Jcard4;
cards[4] = Jcard5;
//Label Handling
Labels = new JLabel[8];
Labels[0] = JLabel1;
Labels[1] = JLabel2;
Labels[2] = JLabel3;
Labels[3] = JLabel4;
Labels[4] = JLabel5;
Labels[5] = JLabel6;
Labels[6] = JLabel7;
Labels[7] = JLabel8;
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
getContentPane().setLayout(null);
setSize(546,371);
getContentPane().add(Jcard1);
Jcard1.setBackground(java.awt.Color.red);
Jcard1.setForeground(java.awt.Color.lightGray);
Jcard1.setBounds(24,96,72,96);
Jcard1.setVisible(false);
getContentPane().add(Jcard2);
Jcard2.setBackground(java.awt.Color.red);
Jcard2.setBounds(108,96,72,96);
Jcard2.setVisible(false);
getContentPane().add(Jcard3);
Jcard3.setBackground(java.awt.Color.red);
Jcard3.setForeground(java.awt.Color.lightGray);
Jcard3.setBounds(192,96,72,96);
Jcard3.setVisible(false);
getContentPane().add(Jcard4);
Jcard4.setBackground(java.awt.Color.red);
Jcard4.setBounds(276,96,72,96);
Jcard4.setVisible(false);
getContentPane().add(Jcard5);
Jcard5.setBackground(java.awt.Color.red);
Jcard5.setForeground(java.awt.Color.lightGray);
Jcard5.setBounds(360,96,72,96);
Jcard5.setVisible(false);
getContentPane().add(Jcard6);
Jcard6.setBackground(java.awt.Color.red);
Jcard6.setBounds(444,96,72,96);
Jcard6.setVisible(false);
JLabel1.setOpaque(true);
getContentPane().add(JLabel1);
JLabel1.setBackground(java.awt.Color.red);
JLabel1.setBounds(84,276,29,22);
JLabel1.setVisible(false);
JLabel2.setOpaque(true);
getContentPane().add(JLabel2);
JLabel2.setBackground(java.awt.Color.red);
JLabel2.setBounds(132,276,29,22);
JLabel2.setVisible(false);
JLabel3.setOpaque(true);
getContentPane().add(JLabel3);
JLabel3.setBackground(java.awt.Color.red);
JLabel3.setBounds(180,276,29,22);
JLabel3.setVisible(false);
JLabel4.setOpaque(true);
getContentPane().add(JLabel4);
JLabel4.setBackground(java.awt.Color.red);
JLabel4.setBounds(228,276,29,22);
JLabel4.setVisible(false);
JLabel5.setOpaque(true);
getContentPane().add(JLabel5);
JLabel5.setBackground(java.awt.Color.red);
JLabel5.setBounds(276,276,29,22);
JLabel5.setVisible(false);
JLabel6.setOpaque(true);
getContentPane().add(JLabel6);
JLabel6.setBackground(java.awt.Color.red);
JLabel6.setBounds(324,276,29,22);
JLabel6.setVisible(false);
JLabel8.setOpaque(true);
getContentPane().add(JLabel8);
JLabel8.setBackground(java.awt.Color.red);
JLabel8.setBounds(420,276,29,22);
JLabel8.setVisible(false);
JLabel7.setOpaque(true);
getContentPane().add(JLabel7);
JLabel7.setBackground(java.awt.Color.red);
JLabel7.setBounds(372,276,29,22);
JLabel7.setVisible(false);
JstatusLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
JstatusLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
JstatusLbl.setText("Shuffling....");
JstatusLbl.setOpaque(true);
getContentPane().add(JstatusLbl);
JstatusLbl.setBackground(java.awt.Color.green);
JstatusLbl.setForeground(java.awt.Color.black);
JstatusLbl.setBounds(192,240,134,22);
JstatusLbl.setVisible(false);
JinstructLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
JinstructLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
JinstructLbl.setText("Select one of the following cards and remember it.");
JinstructLbl.setOpaque(true);
getContentPane().add(JinstructLbl);
JinstructLbl.setBackground(java.awt.Color.white);
JinstructLbl.setForeground(java.awt.Color.black);
JinstructLbl.setBounds(96,48,327,32);
JinstructLbl.setVisible(false);
JfasterLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
JfasterLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
JfasterLbl.setText("Fast Enabled");
JfasterLbl.setOpaque(true);
getContentPane().add(JfasterLbl);
JfasterLbl.setBackground(java.awt.Color.orange);
JfasterLbl.setForeground(java.awt.Color.black);
JfasterLbl.setBounds(252,324,84,28);
JfasterLbl.setVisible(false);
JshuffleBtn.setText("Shuffle >>>");
JshuffleBtn.setActionCommand("Shuffle >>>");
getContentPane().add(JshuffleBtn);
JshuffleBtn.setBounds(132,324,107,32);
JshuffleBtn.setVisible(false);
JstartBtn.setText("Start");
JstartBtn.setActionCommand("Start");
getContentPane().add(JstartBtn);
JstartBtn.setBounds(132,324,107,32);
JfasterBox.setText("Faster Algorithm");
JfasterBox.setActionCommand("Faster Algorithm");
getContentPane().add(JfasterBox);
JfasterBox.setBounds(12,324,114,31);
JtitleLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
JtitleLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
JtitleLbl.setText("Card Trick V1.0a");
JtitleLbl.setOpaque(true);
getContentPane().add(JtitleLbl);
JtitleLbl.setBackground(java.awt.Color.white);
JtitleLbl.setForeground(java.awt.Color.black);
JtitleLbl.setBounds(168,12,189,27);
JRadioButton1.setText("Double Guess");
JRadioButton1.setActionCommand("Double Guess");
getContentPane().add(JRadioButton1);
JRadioButton1.setForeground(java.awt.Color.red);
JRadioButton1.setBounds(360,312,108,27);
JRadioButton2.setText("Sample Merge");
JRadioButton2.setActionCommand("Sample Merge");
getContentPane().add(JRadioButton2);
JRadioButton2.setForeground(java.awt.Color.red);
JRadioButton2.setBounds(360,336,108,27);
radioGroup = new ButtonGroup();
radioGroup.add( JRadioButton1 );
radioGroup.add( JRadioButton2 );
labelTimer = new Timer( 1800, this );
cardTimer = new Timer( 3000, this );
statusTimer = new Timer( 4500, this );
//}}
JfasterBox.addItemListener( this );
JstartBtn.addActionListener( this );
JshuffleBtn.addActionListener( this );
}
//{{DECLARE_CONTROLS
javax.swing.JLabel Jcard1 = new javax.swing.JLabel();
javax.swing.JLabel Jcard2 = new javax.swing.JLabel();
javax.swing.JLabel Jcard3 = new javax.swing.JLabel();
javax.swing.JLabel Jcard4 = new javax.swing.JLabel();
javax.swing.JLabel Jcard5 = new javax.swing.JLabel();
javax.swing.JLabel Jcard6 = new javax.swing.JLabel();
javax.swing.JLabel JLabel1 = new javax.swing.JLabel();
javax.swing.JLabel JLabel2 = new javax.swing.JLabel();
javax.swing.JLabel JLabel3 = new javax.swing.JLabel();
javax.swing.JLabel JLabel4 = new javax.swing.JLabel();
javax.swing.JLabel JLabel5 = new javax.swing.JLabel();
javax.swing.JLabel JLabel6 = new javax.swing.JLabel();
javax.swing.JLabel JLabel8 = new javax.swing.JLabel();
javax.swing.JLabel JLabel7 = new javax.swing.JLabel();
javax.swing.JLabel JstatusLbl = new javax.swing.JLabel();
javax.swing.JLabel JinstructLbl = new javax.swing.JLabel();
javax.swing.JLabel JfasterLbl = new javax.swing.JLabel();
javax.swing.JButton JshuffleBtn = new javax.swing.JButton();
javax.swing.JButton JstartBtn = new javax.swing.JButton();
javax.swing.JCheckBox JfasterBox = new javax.swing.JCheckBox();
javax.swing.JLabel JtitleLbl = new javax.swing.JLabel();
javax.swing.JRadioButton JRadioButton1 = new javax.swing.JRadioButton();
javax.swing.JRadioButton JRadioButton2 = new javax.swing.JRadioButton();
//}}
public void actionPerformed( ActionEvent e ){
if( e.getSource() == JstartBtn ){
counter = 0;
// must be reset index otherwise images are out of sync
labelIndex = -1;
statusIndex = -1;
Jcard1.setIcon(kh);
Jcard2.setIcon(jc);
Jcard3.setIcon(ks);
Jcard4.setIcon(qd);
Jcard5.setIcon(qs);
Jcard6.setIcon(jd);
JinstructLbl.setText("Select one of the following cards and remember it.");
for (int i = 0; i < Labels.length; i++){
Labels[i].setVisible( false );
}
for (int i = 0; i < cards.length; i++){
cards[i].setVisible( true );
}
JinstructLbl.setVisible(true);
JstartBtn.setVisible(false);
JshuffleBtn.setVisible(true);
}
if( e.getSource() == JshuffleBtn ){
for (int i = 0; i < cards.length; i++){
cards[i].setVisible( false );
}
JstatusLbl.setVisible(true);
//Here we go....
statusTimer.start();
labelTimer.start();
cardTimer.start();
Jcard1.setIcon(qh);
Jcard2.setIcon(kc);
Jcard3.setIcon(jh);
Jcard4.setIcon(qs);
Jcard5.setIcon(kd);
JshuffleBtn.setVisible( false );
JfasterBox.setSelected( false );
JRadioButton1.setSelected( false );
JRadioButton2.setSelected( false );
JfasterLbl.setVisible( false );
JstartBtn.setVisible( true );
JstartBtn.setEnabled( false );
}
//"Progress" bar
if ( e.getSource() == labelTimer ){
labelIndex = ( labelIndex + 1 ) % Labels.length;
Labels[labelIndex].setVisible( true );
}
//Controls the showing of the cards...waits until counter cycles 5 times, then shows all cards.
if ( e.getSource() == cardTimer ){
counter++;
if (counter == 5){
labelTimer.stop();
cardTimer.stop();
JstatusLbl.setVisible( false );
JstartBtn.setEnabled( true );
for( int i = 0; i < cards.length; i++){
cards[i].setVisible( true );
}
JinstructLbl.setText("You should find that your card has vanished!");
}
}
//"Thinking" messages
if ( e.getSource() == statusTimer ){
if (statusIndex == 2){
statusTimer.stop();
}
statusIndex = ( statusIndex + 1 ) % StatusList.length;
JstatusLbl.setText(StatusList[statusIndex]);
}
} // end ActionListener
// Fast and radio buttons both do nothing, just for show
public void itemStateChanged( ItemEvent e ){
if (JfasterBox.isSelected() )
JfasterLbl.setVisible(true);
else
JfasterLbl.setVisible(false);
}
}