-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
63 lines (54 loc) · 2.82 KB
/
Card.java
File metadata and controls
63 lines (54 loc) · 2.82 KB
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
import javax.swing.Icon;
import javax.swing.ImageIcon;
public class Card { // Card object
protected String suit; // suit variable
protected String number; // value(number) variable
protected String path; // variable that stores the path of card images
protected Icon icon; // icon variable to store images of cards
public Card(String path) // Card constructor that takes path string parameter
{
this.path = path; // assing path
this.suit = path.charAt(path.length()-5)+""; // take fifth character from last and assign it as suit
if (path.charAt(6) == '1') // take sixth character from path and check if it is equal to 1 or not(if it is 1 actually it is 10)
{
this.number = "10"; // if it is 1 assign 10 as number variable
}
else // if it is not 1
{
this.number = path.charAt(6)+""; // assign sixth character directly
}
this.icon = new ImageIcon(getClass().getResource(path)); // take icon from path
}
public String getPath() // getter method that gets path
{
return path; // return path
}
public void setPath(String path) // setter method that assign new path to Card
{
this.path = path; // assign new path
this.suit = path.charAt(path.length()-5)+""; // assign new suit
this.number = path.charAt(6)+""; // assign new number(value)
this.icon = new ImageIcon(getClass().getResource(getPath())); // take new icon
}
public String getSuit() // getter method that returns suit
{
return suit; // return suit
}
public String getNumber() // getter method that returns number(value)
{
return number; // return number
}
public Icon getIcon() // return icon
{
return icon; // return icon
}
public void setIcon(Icon icon) // method that sets new icon
{
this.icon = icon; // assign new icon
}
@Override // override toString method
public String toString() // toString method
{
return getSuit()+" "+getNumber(); // return suit + number as string
}
}