package cards;
import genericcard.CardPanel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.Box;
import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
/**
*
* @author Oran
*/
public class CardFrame extends javax.swing.JFrame implements Runnable {
/** Creates new form CardFrame */
public CardFrame() {
initComponents();
}
private void initComponents() {
cardpanel = new CardPanel();
myThread = new Thread(this);
myThread.start();
outpanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Looney Solitare!");
//configure the cardpanel
cardpanel.setMinimumSize(new java.awt.Dimension(50, 50));
cardpanel.setPreferredSize(new java.awt.Dimension(900, 600));
getContentPane().add(cardpanel, java.awt.BorderLayout.CENTER);
//configure the output panel
jLabel1.setText("Cards up: ");
outpanel.add(jLabel1);
jLabel2.setText("Cards played:");
outpanel.add(jLabel2);
getContentPane().add(outpanel,java.awt.BorderLayout.NORTH);
//configure the menu
menuBar = new JMenuBar();
setJMenuBar(menuBar);
//set up menus
fileMenu=new JMenu("File"); menuBar.add(fileMenu);
fileMenu.setMnemonic(KeyEvent.VK_F);
fileNew = new JMenuItem("New"); fileMenu.add(fileNew);
fileNew.setMnemonic(KeyEvent.VK_N);
fileNew.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cardpanel.newCardPanel();
repaint();
}
});
fileMenu.addSeparator();
fileExit=new JMenuItem("Exit"); fileMenu.add(fileExit);
fileExit.setMnemonic(KeyEvent.VK_X);
fileExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
menuBar.add(Box.createHorizontalGlue()); //Put the Help menu on the right
helpMenu=new JMenu("Help"); menuBar.add(helpMenu);
helpMenu.setMnemonic(KeyEvent.VK_H);
helpAbout = new JMenuItem("About"); helpMenu.add(helpAbout);
helpAbout.setMnemonic(KeyEvent.VK_A);
helpAbout.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JDialog helpDialog = new JDialog();
helpDialog.setLocation(400,200);
helpDialog.setTitle("About");
TextArea tempTextArea =
new TextArea("Solitare version 1.0Beta\nby Oran Looney 2005\n"+
"Written in Java with NetBeans IDE 4.0\n",20,30,3);
tempTextArea.setEditable(false);
tempTextArea.setFocusable(false);
helpDialog.getContentPane().add(tempTextArea);
helpDialog.setSize(250,200);
helpDialog.setVisible(true);
}
});
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CardFrame().setVisible(true);
}
});
}
public void run(){
while(true) {
try{
Thread.sleep(100);
jLabel1.setText("Cards Up: "+cardpanel.getScore()+" ");
jLabel2.setText("Cards Played: "+cardpanel.getPlayed());
if(cardpanel.getScore()==52)youWin();
}catch(Exception e){System.out.println(""+e);}
}
}
public void youWin(){
Graphics g=getGraphics();
g.setColor(new Color((float)Math.random(),(float)Math.random(),(float)Math.random()));
g.setFont(new Font("Century",Font.BOLD,100));
g.drawString("You Win!",200,200);
}
// Variables declaration
private JMenuBar menuBar;
private JMenu fileMenu,helpMenu;
private JMenuItem fileNew,fileExit,helpAbout;
private CardPanel cardpanel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel outpanel;
Thread myThread;
// End of variables declaration
}
|