import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ChangeMaker extends JPanel implements ActionListener
{
// ** Declare widgets and panels needed for the ChangeMaker interface
ImageIcon imgi1, imgi2, imgi3, imgi4, imgi5;
JButton jbDc, jbCf;
JLabel jLwelcome, jLcoi, jLap, jLDollars, jLQuarters, jLDimes, jLNickels, jLPennies, jLmakeChange;
JLabel jlimgi1, jlimgi2, jlimgi3, jlimgi4, jlimgi5;
JPanel jp1, jp2, jp3, jp4, jp6, jp7, jp8, jp9, jp10, jp11, jp12;
JTextField tf1, tf2, tf3, tf4, tf5, tf6, tf7;
//Class constructor
public ChangeMaker(Color c1, Color c2, Image DollarImage, Image QuarterImage, Image DimeImage, Image NickelImage, Image PennyImage)
public void init()
{
initVar();
initJP();
buildGUI();
}
public void initVar()
{
//initialize class variables: ImageIcons and JLabels
imgi1 = new ImageIcon(DollarImage);
jlimgi1 = new JLabel(imgi1);
imgi2 = new ImageIcon(QuarterImage);
jlimgi2 = new JLabel(imgi2);
imgi3 = new ImageIcon(DimeImage);
jlimgi3 = new JLabel(imgi3);
imgi4 = new ImageIcon(NickelImage);
jlimgi4 = new JLabel(imgi4);
imgi5 = new ImageIcon(PennyImage);
jlimgi5 = new JLabel(imgi5);
//initialize class variables: Labels
jLwelcome = new JLabel("Welcome to the ChangeMaker");
jLwelcome.setFont(new Font("Times", Font.BOLD+Font.ITALIC, 20));
jLwelcome.setForeground(Color.BLUE);
jLcoi = new JLabel("Cost of Item:");
jLap = new JLabel("Amount Paid");
jLDollars = new JLabel("(Dollars)");
jLQuarters = new JLabel("(Quarters)");
jLDimes = new JLabel("(Dimes)");
jLNickels = new JLabel("(Nickels)");
jLPennies = new JLabel("(Pennies)");
jLmakeChange = new JLabel("Make Change this way =======>");
//initialize class variables: Buttons
jbDc = new JButton("Determine Change");
jbCf = new JButton("Clear Fields");
//initialize class variables: JTextFields
tf1 = new JTextField(""); //width ie 10 depends layout manager
tf2 = new JTextField("");
tf3 = new JTextField("");
tf4 = new JTextField("");
tf5 = new JTextField("");
tf6 = new JTextField("");
tf7 = new JTextField("");
}
public void initJP()
{
//initialize class variables: Panels created for NORTH
jp1 = new JPanel(new BorderLayout()); //main JPanel
jp1.setBackground(Color.PINK);
jp2 = new JPanel(new GridLayout(2,1));
jp2.setBackground(Color.PINK);
jp3 = new JPanel(new GridLayout(1,4));
jp3.setBackground(Color.PINK);
jp4 = new JPanel(new GridLayout(1,1));
jp4.setBackground(Color.PINK);
jp6 = new JPanel(new FlowLayout());
jp6.setBackground(Color.PINK);
jp7 = new JPanel(new FlowLayout());
jp7.setBackground(Color.PINK);
//initialize class variables: Panels created for CENTER
jp8 = new JPanel(new GridLayout(5,3));
jp8.setBackground(Color.PINK);
jp9 = new JPanel(new FlowLayout());
jp9.setBackground(Color.PINK);
jp10 = new JPanel(new GridLayout(1,2));
jp10.setBackground(Color.PINK);
jp11 = new JPanel(new FlowLayout());
jp11.setBackground(Color.PINK);
jp12 = new JPanel(new GridLayout(2,1));
jp12.setBackground(Color.PINK);
}
public void buildGUI()
{
//build GUI
add(jp1);
jp1.add(jp2,BorderLayout.NORTH);
jp2.add(jp6);
jp6.add(jLwelcome);
jp2.add(jp7); // jp7 is flow
jp7.add(jp3); //jp7 1x4 grid
jp3.add(jLcoi);
jp3.add(tf1);
jp3.add(jLap);
jp3.add(tf2);
jp7.add(jp4); //jp4 1x1 grid
jp4.add(jbDc);
jp1.add(jp9,BorderLayout.CENTER);
jp9.add(jp10); //jp10 2x1 grid
jp10.add(jp11);
jp11.add(jp12);
jp12.add(jLmakeChange);
jp12.add(jbCf);
jp10.add(jp8); //jp8 5x3 grid
jp8.add(jlimgi1);
jp8.add(jLDollars);
jp8.add(tf3);
jp8.add(jlimgi2); //second row
jp8.add(jLQuarters);
jp8.add(tf4);
jp8.add(jlimgi3); //third row
jp8.add(jLDimes);
jp8.add(tf5);
jp8.add(jlimgi4); // forth row
jp8.add(jLNickels);
jp8.add(tf6);
jp8.add(jlimgi5); // fifth row
jp8.add(jLPennies);
jp8.add(tf7);
}
public void actionPerformed(ActionEvent e)
{
// When a button is pressed, determine which button and take the appropriate actions
validate();
} //end actionPerformed method
} // end ChangeMaker class