Picture1: 展示出一副扑克牌中的52张
Picture2:在文本框内输入扑克
Picture3:显示出除输入之外其他的扑克牌
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class pai extends JFrame implements ActionListener {class PaiPanel extends JPanel {@Overridepublic void paint(Graphics g) {super.paint(g);show(g);}int MARGIN=15;int High=100;int wid=60;public void show(Graphics g){for(int i=1;i<=13;i++) {String str="image/"+i+".jpg";Image bg = new ImageIcon(str).getImage();for(int j=0;j<(4-counter[i-1]);j++) {g.drawImage(bg, 15+(wid+MARGIN)*(i-1), 50 + (High+ MARGIN)*j, 60, 100, null);}}}}JFrame jFrame=new JFrame();PaiPanel paiPanel=new PaiPanel();Container con=jFrame.getContentPane();JButton jbt=new JButton("确定");JTextArea jt=new JTextArea("",1,40);public void init(){jFrame.setTitle("记牌器");jFrame.setLocation(10,10);jFrame.setVisible(true);jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);jFrame.setSize(1000,600);con.add(paiPanel);paiPanel.add(jt);paiPanel.add(jbt);jbt.addActionListener(this);repaint();}
public static void main(String[] args) {new pai().init();}int counter[]=new int[13];parameter p=new parameter();public void actionPerformed(ActionEvent e) {String input=jt.getText();p.setStr(input);jt.setText("");for(int i=0;i<input.length();i++) {String str=String.valueOf((input.charAt(i)));if(str.equals("1")){counter[0]++;}else if(str.equals("2")){counter[1]++;}else if(str.equals("3")){counter[2]++;}else if(str.equals("4")){counter[3]++;}else if(str.equals("5")){counter[4]++;}else if(str.equals("6")){counter[5]++;}else if(str.equals("7")){counter[6]++;}else if(str.equals("8")){counter[7]++;}else if(str.equals("9")){counter[8]++;}else if(str.equals("0")){counter[9]++;}else if(str.equals("j")){counter[10]++;}else if(str.equals("q")){counter[11]++;}else if(str.equals("k")){counter[12]++;}}for(int i=0;i<13;i++){System.out.println(counter[i]);}}}