-
Notifications
You must be signed in to change notification settings - Fork 153
/
HandDealer.java
79 lines (65 loc) · 1.54 KB
/
HandDealer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package chapter6;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class HandDealer extends JFrame
{
public HandDealer()
{
super("Hand Dealer");
final HandPanel aNorth = new HandPanel();
setLayout(new BorderLayout());
add(aNorth, BorderLayout.CENTER);
final JButton deal = new JButton("Deal");
add(deal, BorderLayout.SOUTH);
deal.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
aNorth.showHand(dealHand());
}
});
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(false);
setVisible(true);
}
public static void main(String[] args)
{
new HandDealer();
}
private static Card[] dealHand()
{
Card[] lReturn = new Card[13];
Deck deck = new Deck();
for( int i = 0; i < 13; i++)
{
lReturn[i] = deck.draw();
}
return lReturn;
}
}
@SuppressWarnings("serial")
class HandPanel extends JPanel
{
private static final Color CASINO_GREEN = new Color(0,102,0);
private JLabel aLabel = new JLabel();
public HandPanel()
{
setBackground(CASINO_GREEN);
add(aLabel);
aLabel.setIcon(CardImages.getBack());
}
public void showHand(Card[] pHand)
{
aLabel.setIcon(CardImages.getJoker());
}
}