but without having to drag the cards or anything, I have to make the function work from the deck class that i have created, and i just can't seem to get this going, below is the code ive come up with so far, any help would be greatly appreciated;
public class Deck
{
private Card [] cards;
//set up the standard (or not) 52 card deck
Deck()
{
cards = new Card[52];
//create each of the 52 cards, add them to deck
for(int i=1; i<=13; i++)
{
Card a = new Card(i, "Spade");
Card b = new Card(i, "Heart");
Card c = new Card(i, "Club");
Card d = new Card(i, "Diamond");
add(a);
add(B)/>;
add(c);
add(d);
}
}
//Create a specialized deck!
//Due at midnight Friday if you didn't finish
//in lab.
Deck(int startNum, int endNum, String [] suits)
{
int cap = (endNum-startNum+1)*suits.length;
cards = new Card[cap];
for(int i=startNum; i<=endNum; i++)
{
for(int j=0; j<suits.length; j++)
{
add( new Card(i, suits[j]) );
}
}
}
//specify how a deck should appear when interpretted as
//a string
public String toString()
{
String output = "";
for(int i=0; i< cards.length; i++)
{
output += cards[i];
output += "\n";
}
return output;
}
public void add(Card c)
{
for(int i=0; i<cards.length; i++)
{
if( cards[i] == null )
{
cards[i] = c;
i= cards.length; //break out of loop
}
}
}
}
import javax.swing.*;
import java.awt.*;
public class CardPanel extends JPanel
{
Card testcard;
Card test;
CardPanel()
{
testcard = new Card(7, "Heart");
test = new Card(7, "Spades");
}
public void paintComponent(Graphics g)
{
//draw felt background
g.setColor(Color.ORANGE);
g.fillRect(0,0, getWidth(), getHeight());
}
}
import javax.swing.*;
public class Game
{
public static void main(String [] args)
{
//step 1: create a frame
JFrame frame = new JFrame("Card Game");
//step 2: create a panel, put panel in frame
CardPanel panel = new CardPanel();
frame.getContentPane().add(panel);
//step 3: set frame size, make visible
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class Card
{
int number;
String suit;
int x;
int y;
ImageIcon picture;
Card()
{
number = 0;
suit = "Joker";
picture = new ImageIcon("cards/j.gif");
}
Card(int num, String s)
{
this();
number = num;
suit = s;
String imageName = figureOutPicName();
picture = new ImageIcon(imageName);
}
String figureOutPicName()
{
String output;
output = "cards/";
if (number > 1 && number < 10)
{
output += number;
}
else if( number == 1)
{
output += "a";
}
else if( number == 11)
{
output += "j";
}
else if( number == 12)
{
output += "q";
}
else if( number == 13)
{
output += "k";
}
else
{
output += "wtf";
}
output += suit.substring(0,1).toLowerCase();
output += ".gif";
return output;
}
public void draw(Graphics g, Component comp)
{
g.drawImage(picture.getImage(), x, y, comp);
}
public String toString()
{
return number + " of " + suit + "'s";
}
}

New Topic/Question
Reply




MultiQuote



|