Re: Working with Nested Classes
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
public class GameBoard extends JFrame
{
JPanel pane;
JPanel boardAndStarterCard;
JPanel board;
JPanel starterCard;
JPanel inPlay; // remove this once it works, so the thing can look
better
JPanel inPlayR1;
JPanel inPlayR2;
JLabel tableScore;
JPanel playerHand;
JLabel out;
JTextField in;
public GameBoard(int players) {
super("Gemstones Cribbage");
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(1,1);
pane = new JPanel();
pane.setLayout(grid);
// inPlay
inPlay = new CardRow(13);
pane.add(inPlay);
// Content Pane
setContentPane(pane);
setVisible(true);
}
public void updateInPlay(ArrayList <Comparable> cards)
{
inPlay.changeCards(cards);
}
// CardRow
Class ///////////////////////////////////////////////////////////
public class CardRow extends JPanel
{
ArrayList <Comparable> cards;
int slots;
public CardRow(int mySlots)
{
setLayout(new GridLayout(1, mySlots));
cards = new ArrayList <Comparable>();
slots = mySlots;
drawCards();
}
public void drawCards()
{
}
public void changeCards(ArrayList <Comparable> list)
{
cards = list;
drawCards();
}
}
}
That's a SSCCE version of my class. Using http://www.innovation.ch/java/java_compile.html
since I'm away from my desktop, the error was:
/tmp/5587/GameBoard.java:43: cannot find symbol
symbol : method changeCards(java.util.ArrayList)
location: class javax.swing.JPanel
inPlay.changeCards(cards);
^
1 error
The only major change I made was to convert the ArrayList of <Card>
objects into an ArrayList of <Comparable> objects. Everything else
was simply triming. Thanks for the help.