/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package blackjack;
/**
*
* @author lauraharmon
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
class BlackJack extends JFrame implements ActionListener {
// these declare the deal, hit, and stay [buttons]
private JButton deal;
private JButton stay;
private JButton hit;
// these declare the dealer card slots [labels]
private JLabel dslot1;
private JLabel dslot2;
private JLabel dslot3;
private JLabel dslot4;
private JLabel dslot5;
// these declare the player card slots [labels]
private JLabel pslot1;
private JLabel pslot2;
private JLabel pslot3;
private JLabel pslot4;
private JLabel pslot5;
// this declares the dealers field
private JTextField dscore;
// this declares the players field
private JTextField pscore;
// this is the background label
private JLabel bg;
private int dealer = 1;
private Deck dk;
// these are the spade cards
ImageIcon bj = new ImageIcon("S01.jpg");
ImageIcon as = new ImageIcon("S02.jpg");
ImageIcon ss = new ImageIcon("S03.jpg");
ImageIcon ths = new ImageIcon("S03.jpg");
ImageIcon fos = new ImageIcon("S04.jpg");
ImageIcon fis = new ImageIcon("S05.jpg");
ImageIcon backofcard = new ImageIcon("back.jpg");
public table() {
// this is the blackjack table
dk = new Deck();
Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.black);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Blackjack 21");
setSize(750,700);
setResizable(false);
setLocation(100,25);
// these are the deal, stay, hit buttons
deal = new JButton("Deal");
deal.setBounds(150,600,75,25);
deal.addActionListener(this);
contentPane.add(deal);
stay = new JButton("Stay");
stay.setBounds(300,600,75,25);
stay.addActionListener(this);
contentPane.add(stay);
hit = new JButton("Hit");
hit.setBounds(450,600,75,25);
hit.addActionListener(this);
contentPane.add(hit);
// these are the dealers card slot labels
dslot5 = new JLabel("");
dslot5.setBounds(250,50,107,148);
dslot5.setBorder(BorderFactory.createLineBorder(Color.pink));
contentPane.add(dslot5);
dslot4 = new JLabel("");
dslot4.setBounds(200,50,107,148);
dslot4.setBorder(BorderFactory.createLineBorder(Color.yellow));
contentPane.add(dslot4);
dslot3 = new JLabel("");
dslot3.setBounds(150,50,107,148);
dslot3.setBorder(BorderFactory.createLineBorder(Color.green));
contentPane.add(dslot3);
dslot2 = new JLabel("");
dslot2.setBounds(100,50,107,148);
dslot2.setBorder(BorderFactory.createLineBorder(Color.blue));
contentPane.add(dslot2);
dslot1 = new JLabel("");
dslot1.setBounds(50,50,107,148);
dslot1.setBorder(BorderFactory.createLineBorder(Color.white));
contentPane.add(dslot1);
// these are the player card slot labels
pslot5 = new JLabel("");
pslot5.setBounds(250,300,107,148);
pslot5.setBorder(BorderFactory.createLineBorder(Color.pink));
contentPane.add(pslot5);
pslot4 = new JLabel("");
pslot4.setBounds(200,300,107,148);
pslot4.setBorder(BorderFactory.createLineBorder(Color.yellow));
contentPane.add(pslot4);
pslot3 = new JLabel("");
pslot3.setBounds(150,300,107,148);
pslot3.setBorder(BorderFactory.createLineBorder(Color.green));
contentPane.add(pslot3);
pslot2 = new JLabel("");
pslot2.setBounds(100,300,107,148);
pslot2.setBorder(BorderFactory.createLineBorder(Color.blue));
contentPane.add(pslot2);
pslot1 = new JLabel("");
pslot1.setBounds(50,300,107,148);
pslot1.setBorder(BorderFactory.createLineBorder(Color.white));
contentPane.add(pslot1);
// this shows the dealers score [field]
dscore = new JTextField("Dealers Score:");
dscore.setBounds(50,250,100,25);
dscore.addActionListener(this);
contentPane.add(dscore);
// this shows the players score [field]
pscore = new JTextField("Players Score:");
pscore.setBounds(50,500,100,25);
pscore.addActionListener(this);
contentPane.add(pscore);
bg = new JLabel();
bg.setBounds(0,0,743,700);
bg.setBorder(BorderFactory.createLineBorder(Color.black));
contentPane.add(bg);
bg.setIcon(new ImageIcon("black.jpg"));
}
public static void main(String args[]) {
table frame = new table();
frame.setVisible(true);
}
// this will show the dealer and player cards when deal button is pressed
public void actionPerformed(ActionEvent e){
if(e.getSource() instanceof JButton){
Button clicked = (JButton)e.getSource();
if(clicked == deal) {
{
dslot1.setIcon(as);
pslot1.setIcon(ths);
dslot2.setIcon(backofcard);
pslot2.setIcon(fos);
}
}
}
}
}
Errors:
1. In line 063, I'm getting the error it's an "invalid method declaration, return type required." What kind of return type would I use for that, and where would I put it?
2. In line 164, it says that for both "table's", it "cannot find symbol." How do I fix is so that it can?
3. In line 170, "Button clicked = (JButton)e.getSource();" it says that there's "incomparable types, java.awt.Button required, javax.swing.JButton found". I have both. Can I not use them simultaneously?
4. In line 171, "if(clicked == deal) {", it also says that there's "incomparable types: java.awt.Button and javax.swing.JButton". So do I need or not need those things?
This post has been edited by lmharmon: 08 October 2011 - 07:16 AM

New Topic/Question
Reply



MultiQuote




|