cardimage.java

来自「手机无线网络纸牌游戏源代码。非常适合学习使用」· Java 代码 · 共 102 行

JAVA
102
字号
// CardImage.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved

package com.symbian.devnet.whist.awt;

import java.awt.*;

/** 
 * This class is responsible for controlling the size of the image and 
 * for over-riding the paint and repaint methods.
 * @author Symbian Devnet
 */

public class CardImage extends Canvas
{
	/** The image of the card. */
	private Image image;
	/** The String representing the card suit. */
	private String suit;
	/** The String representing the card rank. */
	private String rank;
	
	/**
	 * Constructor associating the image of a card and the suit and rank
	 * of that card.
	 * @param i the Image of the card being represented.
	 * @param s the String representing the card, for example H for Hearts.
	 * @param r the String representing the rank of the card for example 5.
	 */
	CardImage(Image i, String s, String r)
	{
	 	this.image = i;
		suit = s;
		rank = r;
		this.setSize(30, 36);
	}
	
	/**
	 * Gets the suit of the card.
	 * @return the suit of the card.
	 */	
	public String getCardSuit()
	{
		return suit;
	}
	
	/**
	 * Gets the rank of the card.
	 * @return the rank of the card.
	 */	
	public String getCardRank()
	{
		return rank;
	}		
		
	/** From <code>Canvas</code>, allows the screen to be repainted */
	public void paint(Graphics g)
	{
		if(image != null)
			g.drawImage(image, 0, 0, this);
	}
	
	/** Updates the screen */
	public void update(Graphics g)
	{
		paint(g);
	}
	
	/** 
	 * Returns the preferred size of the CardImage object as 30, 36.
	 * @return the preferred size of the CardImage object.
	 */
	public Dimension getPreferredSize()
	{
		return new Dimension(30, 36);
	}
	
	/** 
	 * Returns the minimum size of the CardImage object as 30, 36
	 * by calling <code>getPreferredSize</code>.
	 * @return the minumum size of the CardImage object.
	 */
	public Dimension getMinimumSize()
	{
		return getPreferredSize();
	}
	
	/** 
	 * Returns the maximum size of the CardImage object as 30, 36
	 * by calling <code>getPreferredSize</code>.
	 * @return the maximum size of the CardImage object.
	 */
	public Dimension getMaximumSize()
	{
		return getPreferredSize();
	}
}	
		
		
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?