card game -part2
 package cardgame;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class testcard extends JPanel implements MouseListener,MouseMotionListener 
{
card []deck=new card[52];

testcard()
{
	int xPos=10;
	int yPos=10;
	int n=0;
	String suits = "shdc";
	String faces = "a23456789tjqk";
        for (int suit=0; suit < suits.length(); suit++) {
            for (int face=0; face < faces.length(); face++) {
                //... Get the image from the images subdirectory.
                String imagePath = "E:/jdk1.4/bin/cardgame/cards/" + faces.charAt(face) +suits.charAt(suit) + ".gif";
                //URL imageURL = cldr.getResource(imagePath);
                ImageIcon img = new ImageIcon(imagePath );
                
                //... Create a card and add it to the deck.
                card c = new card(img);
                c.moveTo(xPos, yPos);
                deck[n] = c;
                add(deck[n]);
                //... Update local vars for next card.
                xPos += 5;
                yPos += 4;
                n++;
            }
        }
	
	

}
public void paintComponent(Graphics g)
{
	super.paintComponent(g);
	for(int i=0;i<52;i++)
		deck[i].draw(g,this);

}
public static void main(String []args)
{
	JFrame window=new JFrame();
	
	window.setTitle("Card Demo 1");
	window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	window.getContentPane().add(new testcard());
	window.setSize(800,600);
	window.setLocationRelativeTo(null);
	window.setVisible(true);
	window.repaint();
}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mouseClicked(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseMoved(MouseEvent me) {}
public void mouseDragged(MouseEvent me) {}
}
share on whatapp
265 Views

Comments

 
 
Private Policy   Terms of Service   4922