/* COMMUNICATION BETWEEN CLASSES. The ControlPanel class processes the bids.

//It needs to get access to what the bidder has put into the JTextfields.

// The textfields are declared and set up in AuctionGUI. How do the two classes//communicate? HOW DOES THE LISTENER CLASS IN CONTROL PANEL EXTRACT THE BIDS //INPUT IN THE TEXTFIELDS which are in AuctionGUI.

//Simple - you will send a reference (“this”) of this class(AuctionGUI) to the ControlsPanel //constructor.

publicclass AuctionGUI extends JFrame
{
//declare Variables need for THE program e.g. all the textfields and labels, panels
private ControlsPanel controls;// class that process the bidsand contains the buttons

// private BidPanel bid; // class that we will draw the images on

// Constructor

public AuctionGUI()
{
//put code to create all the textfields , labels etc here - before you declare ControlsPanel

// now create an object of the BidPanel class - we will draw the images in there

// now create an object of the ControlPanel class

controls = new ControlsPanel( the names textfields ControlPanel need access to, e.g statusField, newBidField, reference to the BidPanel, this);

// “this” means this class- AuctionGUI.

// The ControlsPanel class needs a reference to AuctionGUI, in order to call the setters and //getters methods for the textfields that you will put at the bottom of this class.

// It also needs a reference to BidPanel in order to draw the images.

Container contentPane = getContentPane();
contentPane.add(topPanel,BorderLayout.NORTH);// panel with textfields
contentPane.add(controls,BorderLayout.SOUTH); // ControlPanel with the Buttons
contentPane.add(bidPanel,BorderLayout.CENTER);// panel for images
setSize(500, 900);
} // close constructor

// example of setter and getters –

public String returnNewBid()
{
return newBidField.getText();
}

publicvoid setBiddersField(Stringamount)
{
bidders.setText(amount); }
} // close class

// This class has the listener for buttons. It collects the bids from the JTextfields in //AuctionGUi and determines which bid is accepted. It then resets the textfields in the //AuctionGUI class to what the new bid is and calls BidPanel to draw the images as each new //bidder is processed

publicclass ControlsPanel extends JPanel
{

//other declarations e.g.

//Action Handler

private ButtonHandler buttonListener; // nested listener class for buttons

private JTextField maxbidfield; //a local reference to maxbidfield
private AuctionGUI AG;// declare a reference to AuctionGUI

private BidPanel bid;// declare a reference to BidPanel class - draws images
// constructor

public ControlsPanel(JTextField maxbidfield,other textfields that ControlsPanel needs access to, BidPanel bid, AuctionGUI AS)

{
this.maxbidfield = maxbidfield;

// do same for all the textfields – declare a local reference as above and store the //appropriate textfield in the constructor

// do the same for the BidPanel reference e.g
this.AG = AG; // store a local reference to the AuctionGUI class

// NOW this class will use AG to call methods in the AuctionGUi class

// it will use the reference to BidPanel to call a method in BidPanel
// Other code to set up the Buttons and their listeners

}

{Nested inner class that acts a listener for the buttons}