thank you
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class deal2 extends JFrame implements ActionListener
{
JLabel labels[]=new JLabel[52];
JMenuBar menubar;
JMenu file;
JMenuItem reset;
JMenuItem exit;
public deal2()
{
cards();
menubar = new JMenuBar();
setJMenuBar(menubar);
file = new JMenu("File");
menubar.add(file);
reset = new JMenuItem("Shuffle Cards");
file.add(reset);
exit = new JMenuItem("Quet");
file.add(exit);
exit.addActionListener(this);
reset.addActionListener(this);
}
public void cards()
{
for(int i=0;i<labels.length;i++)
{
labels[i]=(new JLabel(new ImageIcon(i+".png")));
}
int [] pack = new int [52];
int n=52;
for (int i=0;i<n;i++) pack[i]=i;
Random r= new Random();
for (int i=0;i<52;i++)
{
int k= r.nextInt(n);
add(labels[pack[k]]);
pack[k]=pack[n-1];
n--;
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==exit) System.exit(0);
if(e.getSource()==reset) cards(); //this is the problem when i pressed the reset button, cards //should shuffle because am calling the method cards which is the method that creates and shuffles the cards.
}
public static void main(String args[])
{
deal2 deal = new deal2();
deal.setLayout(new GridLayout(3,2));
deal.setVisible(true);
deal.setTitle("Poker Cards shuffling");
deal.setBackground(Color.YELLOW);
deal.pack();
}
}
This post has been edited by n8wxs: 07 February 2011 - 12:01 PM
Reason for edit:: Fix code tags - closing tag missing slash: [/code]

New Topic/Question
Reply




MultiQuote




|