import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class puke extends JApplet
{
?JFrame f=new JFrame();
?Container y=getContentPane();
?JButton wash=new JButton("洗牌");
??JButton post=new JButton("發牌");
?JLabel first=new JLabel("The first is:");
?JLabel second=new JLabel("The second is:");
?JLabel third=new JLabel("The third is:");
?JLabel fourth=new JLabel("The fourth is:");
?public void init()
?{??
??y.setLayout(new GridLayout(3,2));
??y.add(wash);
??y.add(post);
??y.add(first);
??y.add(second);
??y.add(third);
??y.add(fourth);
??wash.addActionListener(new WashActionAdapter());
??post.addActionListener(new PostActionAdapter());??????
?}
//---------------------------------------------------------------
?? class MyThread extends Thread
?? {
?? ?public void run()
?? ?{
?? ??Stack save=new Stack();
?? ??Vector MyVector=new Vector(1,1);
????String[] wpkp={"紅桃","黑桃","方片","草花"};
????? Random i=new Random();
?? ???? int a,j;
?? ???? a=4;
????try
????{
???????? while(a!=0)
???{
? ???j=i.nextInt(4);
???? if(wpkp[j]!="NULL")
????? {
????? ?save.push(wpkp[j]);
??? ???? wpkp[j]="NULL";
???? ?? a-=1;
???? }
???? else continue;
????}
???? while(!save.empty())??????
???????? ?MyVector.addElement(save.pop());
???????? ?for(int ii=0;ii<MyVector.capacity();ii++)
???????? ?{
???????? ??switch(ii%5)
?????{
??????case 0:first.setText("The first is:"+MyVector.get(ii).toString());break;
??????case 1:second.setText("The second is:"+MyVector.get(ii).toString());break;
??????case 2:third.setText("The third is:"+MyVector.get(ii).toString());break;
??????case 3:fourth.setText("The fourth is:"+MyVector.get(ii).toString());break;
?????}
?????}
????}
????catch(Exception ee)
????{
????}
?? ??}
?? ?}
//----------------------------------------------------------------
??class WashActionAdapter implements ActionListener
??{
//?? Stack save=new Stack();
??????
?????
??
???public? void actionPerformed(ActionEvent e)
???{
??????????? first.setText("The first is:");
??????second.setText("The second is:");
??????third.setText("The third is:");
??????fourth.setText("The fourth is:");????
????}
???}
//-------------------------------------------------------------------------------------
???class PostActionAdapter implements ActionListener
???{
????public? void actionPerformed(ActionEvent e)
????{
?????String cmd=e.getActionCommand();
?????String title="Message Dialog";
?????String message="";
?????int type;
?????if(first.getText().equals("The first is:"))
?????{
??????Thread t=new MyThread();
??????? t.start();
??????}
?????else
?????{
??????type=JOptionPane.PLAIN_MESSAGE;
??????message="請先洗牌";
?????JOptionPane.showMessageDialog(f,message,title,type);
??????}
????
???? }
???}
//---------------------------------------------------------------------------------------???
}
自己感覺有點亂,大家有好的方法可以告訴我,精誠合作,金石為開
