我已经创建了我的卡片组,可以处理每张卡片和一套西装,直到没有剩余卡片为止.对于我的项目,我需要将其拆分为3个类,其中包括一个驱动程序类.我首先用一切创建了一个类,所以我知道如何使它全部工作.
public class DeckOfCards2 {
public static void main(String[] args) {
int[] deck = new int[52];
String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
// Initialize cards
for (int i = 0; i < deck.length; i++) {
deck[i] = i;
}
// Shuffle the cards
for (int i = 0; i < deck.length; i++) {
int index = (int)(Math.random() * deck.length);
int temp = deck[i]; …Run Code Online (Sandbox Code Playgroud) 对于我的课,我需要使用我的ActionListener.我在将ActionListener添加到按钮时遇到问题.我必须使用像"this"这样的单词来添加我的ActionListener,但是我很难做到这一点.我稍后会看到我的actionPerformed方法,但我的主要问题是我的ActionListener.
public class TextButtonsHW extends JFrame implements ActionListener {
private JButton[] buttons; //Do not change
private JTextArea textArea; //Do not change
//Assign values for these constants in the constructor
private final int ENTER; //Index of Enter button in buttons
private final int SPACE; //Index of Space button in buttons
private final int CLEAR; //Index of Clear button in buttons
/**
* Set up this frame and its contents.
* @param title Title to appear in JFrame title bar
*/
public …Run Code Online (Sandbox Code Playgroud)