have the Vector creation in main which is outside of my JFrame derived class. The user's input for the car lot's size is the argument for the size of the vector. Not sure how to handle invalid user input's ouside on negative numbers, but that is another problem.
So I send the vector and the vector size variable to my JFrame derived class, JoesCarLot, henceforth referred to a JCL. And I do pretty much everything needed in the constructor: create widgets, add them, register listeners, etc. I implemented the interface, so I presume that I can listen with the calss itself and use the keyword this as sending a listener object.
Anyway, I cannot seem to use vector methods anywhere. Also, in my itemStateChanged and actionPerformed overriden methods, I have the definitions, but the references to the buttons are not working. But the worst part, again, is the vector processing which is preventing me from referencing the vector. I tried a data structure creation in the vehilce class, thought about it in the vehicle constructor, in main, and in the JCL constructor, or somewhere in the JCL class. It even crossed my mind to deep copy or clone the vector or array, and reference it that way.
I have spent a lot of time changing around the code to no avail, and at this point I am lost. I would appreciate any suugestions, comments, anecdotes, witicisms, criticisms, etc that you have.
Here's my code
package project4;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
/* Kenji Mapes <
kenergyone@yahoo.com>
* CMP 218 J1
* Project 3: "Class EconomyCar"
* Due 11/30/05 11:59 pm
* Vehicle.java, Car.java, EconomyCar.java, FamilyCar.java, Motorcycle.java, Project3Driver.java, , proj3.txt
*/
public class JoesCarLot extends JFrame implements ActionListener, ItemListener //SelectionListener,
{
//data fields
public int length;
public int size;
/* Default constructor JoesCarLot
* No parameters
* setups up the look and feel of the GUI object
*/
public JoesCarLot(Vector vehicles, int carLotSize)
{
//since this is a derived class, a call to the parent class, JFrame,
//with the keyowrd super() ensures proper initialization
super();
//store array/vector size coming in in a local variable
size = carLotSize;
/*
//test to see if incoming paramter is an array of type vehicle
if(o instanceof Vehicle)
{
Vehicle vehicles = o;
}
else
{
System.exit(0);
}
//prompt user for car lot size which dictates how many vehicles
// car be added to list, created, size of array, etc.
int carLotSize;
String carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
Object vehicles[ ] = new Vehicle[ carLotSize ];
/*
if(object.length < vehicles.getArraySize)
{
carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
}
//while loop to handle valid input from user
while(carLotSize < 1)
{
carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
}
*/
// FRAME/contentPane setup
//set title and font to JCL object
setTitle("Joe's Car Lot");
setFont(new Font("Arial", Font.BOLD, 20));
//creates reference for an ImageIcon object
Icon carIcon = new ImageIcon("s_coopermini.gif");
Icon carIcon2 = new ImageIcon("red_coopermini.jpeg");
//get the content pane to be able to reference it
Container container = getContentPane();
//set Layout with appropriate layout manager
//in this case multiple managers will be used
container.setLayout(new BorderLayout());
//create color objects to reference for special colors
Color colorTan = new Color(245,245,220);
Color colorDkGrey = new Color(49, 79, 79);
Color colorChoco = new Color(205, 105, 30);
Color colorAlmond = new Color(255,235,205);
Color colorKhaki = new Color(189, 183, 107);
Color colorOlive = new Color(107, 142, 35);
Color colorSiena = new Color(160, 82, 45);
Color colorSBrown = new Color(139, 69, 19);
Color colorWheat = new Color(245, 222, 179);
//set frame background color
container.setBackground(Color.GRAY);
//FRAME MENU BAR SETUP
//create Menu bar object
//and set it in frame
JMenuBar jmbMenu = new JMenuBar();
setJMenuBar(jmbMenu);
//create menu bar object "file"
//and add it to the menu
JMenu jmFile = new JMenu("File");
jmbMenu.add(jmFile);
//create menu item Open for File
JMenuItem jmiOpen = new JMenu("Open File");
/*register listener
*since this class implements the Listener interface for this object
*the class itslef is the listener and can be referenced with this
*/
jmiOpen.addItemListener(this);
//add "File" button to JMenu
jmFile.add(jmiOpen);
//create menu item Save File for File
JMenuItem jmiSave = new JMenu("Save File");
/*register listener
*since this class implements the Listener interface for this object
*the class itslef is the listener and can be referenced with this
*/
jmiSave.addItemListener(this);
//add "Save" button to JMenu
jmFile.add(jmiSave);
//create menu item Open for File
JMenuItem jmiExit = new JMenu("Exit GUI");
/*register listener
*since this class implements the Listener interface for this object
*the class itslef is the listener and can be referenced with this
*/
jmiExit.addItemListener(this);
//add "Exit" button to JMenu
jmFile.add(jmiExit);
//create menu bar object "help"
//and add it to the menu
JMenu jmHelp = new JMenu("Help");
/*register listener
*since this class implements the Listener interface for this object
*the class itslef is the listener and can be referenced with this
*/
jmHelp.addItemListener(this);
//add "Help" button to JMenu
jmbMenu.add(jmHelp);
//PANELS and NESTED PANELS
//create JPanel objects and
//add them to the frame
/*create first JPanel
*set layout for panel
*set background color
*/
//JPANEL 1
JPanel jpPanel1 = new JPanel();
jpPanel1.setLayout(new FlowLayout());
jpPanel1.setBackground(colorKhaki);
//create JButton instance "OK" for future use possibly
JButton jbtok = new JButton("OK");
//create JLabel to hold image for title panel
//prior to JTextArea
JLabel jlRedCoopMin = new JLabel(carIcon);
//add JLabel
jpPanel1.add(jlRedCoopMin);
//create uneditable text area for greeting
JTextArea jtaGreet = new JTextArea("Welcome to Joe's Car Lot's User Interface");
jtaGreet.setFont(new Font("Times", Font.ITALIC, 20));
//prevent JTextArea from being edited by user
jtaGreet.setEditable(false);
//add greeting to panel 1
jpPanel1.add(jtaGreet);
//create second JLabel to hold image for title panel
//after to JTextArea greeting
JLabel jlRedCoopMin2 = new JLabel(carIcon);
jpPanel1.add(jlRedCoopMin2);
//add panel to north area of Frame (content pane)
getContentPane().add(jpPanel1,BorderLayout.NORTH);
//create second JPanel object
//set layout
//JPANEL 2
JPanel jpPanel2 = new JPanel();
jpPanel2.setLayout(new FlowLayout());
//make background color contrasting
jpPanel2.setBackground(colorTan);
//create border for panel 2
Border panel2Border = new TitledBorder("Vehicle List");
jpPanel2.setBorder(panel2Border);
/*create labels for top of list
*purpose: defines what properties are in list contingent upon
*vehicle type
*/
JLabel carListHeader = new JLabel();
carListHeader.setText(" Car listed with: Veh ID# Year Color Model #Doors Price *mileage for family car");
jpPanel2.add(carListHeader);
JLabel motoListHeader = new JLabel();
motoListHeader.setText(" Motorcycles listed with: Veh ID# Year Model Price Engine Size");
jpPanel2.add(motoListHeader);
//create array of vehicles and add vehicles to it
/*
Vehicle vehicles[ ] = new Vehicle[ carLotSize ];
vehicles[ 0 ] = new FamilyCar( );
vehicles[ 1 ] = new EconomyCar( 1999, 5, "Grey", 13385,
"Honda Civic" );
vehicles[ 2 ] = new Motorcycle( );
vehicles[ 3 ] = new Motorcycle( 1987, "Harley Davidson Sportster",
4995, 1200 );
vehicles[ 0 ] = new FamilyCar( );
vehicles[ 4 ] = new EconomyCar( 2005, 5, "Green", 13385,
"Cooper Mini" );
vehicles[ 5 ] = new Motorcycle( );
vehicles[ 6 ] = new Motorcycle( 2003, "Honda CBR 600RR",
9995, 600 );
vehicles[ 7 ] = new FamilyCar( );
vehicles[ 8 ] = new EconomyCar( 1970, 2, "Yellow", 13385,
"Porsche Boxster" );
vehicles[ 9 ] = new Motorcycle( );
*/
//create JList for panel 2
JList jlVeh = new JList(vehicles);
//jlveh.add(o);
//edit JList properties
//jlVeh.selectionMode(SINGLE_SELECTION);
//jlVeh.setVisibleAmount(4);
//create JScrollBar for JList
JScrollBar jpP2Scroll = new JScrollBar(JScrollBar.VERTICAL);
getContentPane().add(jpP2Scroll, BorderLayout.CENTER);
//create JLabel for combo box here to inform user
JLabel comboHeader = new JLabel();
comboHeader.setText("Select vehicle here, and then choose appropriate action");
//set JLabel color for combo box
comboHeader.setForeground(Color.RED);
//create JComboBox for panel 2
JComboBox jcbVeh = new JComboBox(vehicles);
//add JList to panel 2
jpPanel2.add(jlVeh);
//add heading above combo box
jpPanel2.add(comboHeader);
//add JComboBox to panel 2
jpPanel2.add(jcbVeh);
//add second JPanel to the frame
getContentPane().add(jpPanel2, BorderLayout.CENTER);
//JPANEL 3
//create third JPanel
JPanel jpPanel3 = new JPanel();
jpPanel3.setLayout(new BorderLayout());
jpPanel3.setBackground(colorKhaki);
//JPANEL 3 ALPHA
//create first nested sub-JPanel to add to third MAIN panel
JPanel jpPanel3a = new JPanel();
jpPanel3a.setLayout(new FlowLayout());
jpPanel3a.setBackground(Color.DARK_GRAY);
//create border object to create border on panel 3a
//set it into panel 3a
Border panel3aBorder = new BevelBorder(BevelBorder.RAISED);
jpPanel3a.setBorder(panel3aBorder);
//create JLabel for panel 3a and set text
//color and literal
JLabel jlcarLotSz = new JLabel();
jlcarLotSz.setForeground(Color.RED);
//maximum vehicles allow will be user input defined
//carLotSize
jlcarLotSz.setText("Maximum # vehicles allowed: " + carLotSize);
//add JLabel to panel 3a
jpPanel3a.add(jlcarLotSz);
//add the panel to the NORTH sector of JPanel 3
jpPanel3.add(jpPanel3a, BorderLayout.NORTH);
//JPANEL 3 BRAVO
//create second nested sub-JPanel to add into third MAIN panel
//set layout
JPanel jpPanel3b = new JPanel();
jpPanel3b.setLayout(new FlowLayout(10));
jpPanel3b.setBackground(colorKhaki);
//create titled border around this panel
//and set
Border panel3bBorder = new TitledBorder("Vehicle List Actions");
jpPanel3b.setBorder(panel3bBorder);
//create buttons for JPanel 3a
//add, remove, sell
JButton jbtAdd = new JButton("Add");
JButton jbtRemove = new JButton("Remove");
JButton jbtSell = new JButton("Sell");
//set colors for panel 3b JButtons
jbtAdd.setBackground(colorTan);
jbtRemove.setBackground(colorTan);
jbtSell.setBackground(Color.PINK);
//create tool tip texts to inform user
//further of button actions
jbtAdd.setToolTipText("Adds a vehicle to the list");
jbtRemove.setToolTipText("Removes a vehicle from the list");
jbtSell.setToolTipText("Sells selected vehicle");
/*register listener for three JButtons: Add, Remove, Sell
*since this class implements the listener interface for this object
*the class itslef is the listener and can be referenced with this
*/
jbtAdd.addActionListener(this);
jbtRemove.addActionListener(this);
jbtSell.addActionListener(this);
//add the Add, Remove, Sell, buttons to the Panel
jpPanel3b.add(jbtAdd);
jpPanel3b.add(jbtRemove);
jpPanel3b.add(jbtSell);
//add second nested sub-JPanel to third MAIN panel
jpPanel3.add(jpPanel3b, BorderLayout.CENTER);
//add the third MAIN JPanel to the Frame with
//the nested panels already added
getContentPane().add(jpPanel3,BorderLayout.EAST);
//create fourth main JPanel that will go into the frame
//set layout
JPanel jpPanel4 = new JPanel();
jpPanel4.setLayout(new FlowLayout());
//set border and background color
Border border4 = new LineBorder(Color.RED, 2);
jpPanel4.setBorder(border4);
jpPanel4.setBackground(colorKhaki);
//create EXIT JButton for panel 4
JButton jbtExit = new JButton("Exit system!");
//set background red to alert user
jbtExit.setBackground(Color.RED);
//set tool tip text System Exit button
jbtExit.setToolTipText("Exits system - INFORMATION MAY BE LOST!");
//add listener to jbtExit button
jbtExit.addActionListener(this);
//add button to panel
jpPanel4.add(jbtExit);
//add panel 4 to the south portion of the frame
getContentPane().add(jpPanel4,BorderLayout.SOUTH);
}
//actionPerformed method overriden from ActionListener interface
/* void itemStateChanged
* Parameters: event object
* No return statement - statements executed as conditions permit
*/
public void actionPerformed(ActionEvent e)
{
/*
if(e.getSource() == jbtAdd)
{
}
if(e.getSource() == jbtRemove)
{
}
if(e.getSource() == jbtSell)
{
}
if(e.getSource() == jbtExit)
{
JOptionPane.showMessageDialog(null, "System is Exiting", "For Your Information:", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
*/
}//end of ActionPerformed()
//itemStateChanged method overriden from ItemListener interface
/* void itemStateChanged
* Parameters: event object
* No return statement - statements executed as conditions permit
*/
public void itemStateChanged(ItemEvent e)
{ /*
if(e.getSource() == jmiOpen)
{
}
if(e.getSource() == jmiSave)
{
}
if(e.getSource() == jmhelp)
{
}
*/
}//end of ItemStateChanged()
}//end of class
package project4;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
/* Kenji Mapes <
kenergyone@yahoo.com>
* CMP 218 J1
* Project 3: "Class EconomyCar"
* Due 11/30/05 11:59 pm
* Vehicle.java, Car.java, EconomyCar.java, FamilyCar.java, Motorcycle.java, Project3Driver.java, , proj3.txt
*/
public class Project4 extends JFrame implements ActionListener, ItemListener //SelectionListener,
{
public static void main(String[] x)
{
//prompt user for car lot size which dictates how many vehicles
// car be added to list, created, size of array, etc.
int carLotSize;
String carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
while(carLotSize < 1)
{
carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
}
Vector vehicles = new Vector(carLotSize);
vehicles.addElement(new FamilyCar());
vehicles.addElement(new EconomyCar( 1999, 5, "Grey", 13385,
"Honda Civic" ));
vehicles.addElement(new Motorcycle( ));
vehicles.addElement(new Motorcycle( 1987, "Harley Davidson Sportster",
4995, 1200 ));
vehicles.addElement(new EconomyCar( 2005, 5, "Green", 13385,
"Cooper Mini" ));
vehicles.addElement(new Motorcycle( ));
vehicles.addElement(new Motorcycle( 2003, "Honda CBR 600RR",
9995, 600 ));
vehicles.addElement(new FamilyCar( ));
vehicles.addElement(new EconomyCar( 1970, 2, "Yellow", 13385,
"Porsche Boxster" ));
vehicles.addElement(new Motorcycle( ));
vehicles.addElement(new FamilyCar( ));
vehicles.addElement(new EconomyCar( 1970, 2, "Yellow", 13385,
"Porsche Boxster" ));
vehicles.addElement(new Motorcycle( ));
//instantiate JoesCarLot object
//set title and font for JFrame type class
//set JFrame size, as visible, and close operation
//parameters pass an array of vehicles
Project4 p4 = new Project4(vehicles, carLotSize);
p4.setFont(new Font("Arial", Font.ITALIC, 4));
p4.setSize(900,800);
p4.setVisible(true);
p4.setDefaultCloseOperation(p4.EXIT_ON_CLOSE);
System.out.print(vehicles.size());
//display array which is in JList to screen
//System.out.println(vehicles.getArraySize());
}//end of main
/* Default constructor JoesCarLot
* No parameters
* setups up the look and feel of the GUI object
*/
public Project4(Vector vehicles, int carLotSize)
{
//since this is a derived class, a call to the parent class, JFrame,
//with the keyowrd super() ensures proper initialization
super();
/*
*
//test to see if incoming paramter is an array of type vehicle
if(o instanceof Vehicle)
{
Vehicle vehicles = o;
}
else
{
System.exit(0);
}
//prompt user for car lot size which dictates how many vehicles
// car be added to list, created, size of array, etc.
int carLotSize;
String carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
Object vehicles[ ] = new Vehicle[ carLotSize ];
/*
if(object.length < vehicles.getArraySize)
{
carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
}
//while loop to handle valid input from user
while(carLotSize < 1)
{
carLotInput = JOptionPane.showInputDialog("Please enter size of car lot(nonnegative integer):");
carLotSize = Integer.parseInt(carLotInput);
}
*/
// FRAME/contentPane setup
//set title and font to JCL object
setTitle("Joe's Car Lot");
setFont(new Font("Arial", Font.BOLD, 20));
//creates reference for an ImageIcon object
Icon carIcon = new ImageIcon("s_coopermini.gif");
Icon carIcon2 = new ImageIcon("red_coopermini.jpeg");
//get the content pane to be able to reference it
Container container = getContentPane();
//set Layout with appropriate layout manager
//in this case multiple managers will be used
container.setLayout(new BorderLayout());
//create color objects to reference for special colors
Color colorTan = new Color(245,245,220);
Color colorDkGrey = new Color(49, 79, 79);
Color colorChoco = new Color(205, 105, 30);
Color colorAlmond = new Color(255,235,205);
Color colorKhaki = new Color(189, 183, 107);
Color colorOlive = new Color(107, 142, 35);
Color colorSiena = new Color(160, 82, 45);
Color colorSBrown = new Color(139, 69, 19);
Color colorWheat = new Color(245, 222, 179);
//set frame background color
container.setBackground(Color.GRAY);
//FRAME MENU BAR SETUP
//create Menu bar object
//and set it in frame
JMenuBar jmbMenu = new JMenuBar();
setJMenuBar(jmbMenu);
//create menu bar object "file"
//and add it to the menu
JMenu jmFile = new JMenu("File");
jmbMenu.add(jmFile);
//create menu item Open for File
JMenuItem jmiOpen = new JMenu("Open File");
jmFile.add(jmiOpen);
//create menu item Save File for File
JMenuItem jmiSave = new JMenu("Save File");
jmFile.add(jmiSave);
//create menu item Open for File
JMenuItem jmiExit = new JMenu("Exit GUI");
jmFile.add(jmiExit);
//create menu bar object "help"
//and add it to the menu
JMenu jmHelp = new JMenu("Help");
jmbMenu.add(jmHelp);
//PANELS and NESTED PANELS
//create JPanel objects and
//add them to the frame
//create first JPanel
//set layout for panel
//set background color
//JPANEL 1
JPanel jpPanel1 = new JPanel();
jpPanel1.setLayout(new FlowLayout());
jpPanel1.setBackground(colorKhaki);
//create JButton instance "OK" for future use possibly
JButton jbtok = new JButton("OK");
//create JLabel to hold image for title panel
//prior to JTextArea
JLabel jlRedCoopMin = new JLabel(carIcon);
//add JLabel
jpPanel1.add(jlRedCoopMin);
//create uneditable text area for greeting
JTextArea jtaGreet = new JTextArea("Welcome to Joe's Car Lot's User Interface");
jtaGreet.setFont(new Font("Times", Font.ITALIC, 20));
//prevent JTextArea from being edited by user
jtaGreet.setEditable(false);
//add greeting to panel 1
jpPanel1.add(jtaGreet);
//create second JLabel to hold image for title panel
//after to JTextArea greeting
JLabel jlRedCoopMin2 = new JLabel(carIcon);
jpPanel1.add(jlRedCoopMin2);
//add panel to north area of Frame (content pane)
getContentPane().add(jpPanel1,BorderLayout.NORTH);
//create second JPanel object
//set layout
//JPANEL 2
JPanel jpPanel2 = new JPanel();
jpPanel2.setLayout(new FlowLayout());
//make background color contrasting
jpPanel2.setBackground(colorTan);
//create border for panel 2
Border panel2Border = new TitledBorder("Vehicle List");
jpPanel2.setBorder(panel2Border);
//create labels for top of list
//purpose: defines what properties are in list contingent upon
//vehicle type
JLabel carListHeader = new JLabel();
carListHeader.setText(" Car listed with: Veh ID# Year Color Model #Doors Price *mileage for family car");
jpPanel2.add(carListHeader);
JLabel motoListHeader = new JLabel();
motoListHeader.setText(" Motorcycles listed with: Veh ID# Year Model Price Engine Size");
jpPanel2.add(motoListHeader);
//create array of vehicles and add vehicles to it
/*Vehicle vehicles[ ] = new Vehicle[ carLotSize ];
vehicles[ 0 ] = new FamilyCar( );
vehicles[ 1 ] = new EconomyCar( 1999, 5, "Grey", 13385,
"Honda Civic" );
vehicles[ 2 ] = new Motorcycle( );
vehicles[ 3 ] = new Motorcycle( 1987, "Harley Davidson Sportster",
4995, 1200 );
vehicles[ 0 ] = new FamilyCar( );
/*vehicles[ 4 ] = new EconomyCar( 2005, 5, "Green", 13385,
"Cooper Mini" );
vehicles[ 5 ] = new Motorcycle( );
vehicles[ 6 ] = new Motorcycle( 2003, "Honda CBR 600RR",
9995, 600 );
vehicles[ 7 ] = new FamilyCar( );
vehicles[ 8 ] = new EconomyCar( 1970, 2, "Yellow", 13385,
"Porsche Boxster" );
vehicles[ 9 ] = new Motorcycle( );*/
//create JList for panel 2
JList jlVeh = new JList(vehicles);
//jlveh.add(o);
//edit JList properties
//jlVeh.selectionMode(SINGLE_SELECTION);
//jlVeh.setVisibleAmount(4);
//create JScrollBar for JList
JScrollBar jpP2Scroll = new JScrollBar(JScrollBar.VERTICAL);
getContentPane().add(jpP2Scroll, BorderLayout.CENTER);
//create JLabel for combo box here to inform user
JLabel comboHeader = new JLabel();
comboHeader.setText("Select vehicle here, and then choose appropriate action");
//set JLabel color for combo box
comboHeader.setForeground(Color.RED);
//create JComboBox for panel 2
JComboBox jcbVeh = new JComboBox(vehicles);
//add JList to panel 2
jpPanel2.add(jlVeh);
//add heading above combo box
jpPanel2.add(comboHeader);
//add JComboBox to panel 2
jpPanel2.add(jcbVeh);
//add second JPanel to the frame
getContentPane().add(jpPanel2, BorderLayout.CENTER);
//JPANEL 3
//create third JPanel
JPanel jpPanel3 = new JPanel();
jpPanel3.setLayout(new BorderLayout());
jpPanel3.setBackground(colorKhaki);
//JPANEL 3 ALPHA
//create first nested sub-JPanel to add to third MAIN panel
JPanel jpPanel3a = new JPanel();
jpPanel3a.setLayout(new FlowLayout());
jpPanel3a.setBackground(Color.DARK_GRAY);
//create border object to create border on panel 3a
//set it into panel 3a
Border panel3aBorder = new BevelBorder(BevelBorder.RAISED);
jpPanel3a.setBorder(panel3aBorder);
//create JLabel for panel 3a and set text
//color and literal
JLabel jlcarLotSz = new JLabel();
jlcarLotSz.setForeground(Color.RED);
//maximum vehicles allow will be user input defined
//carLotSize
jlcarLotSz.setText("Current # of vehicles in list: " + carLotSize);
//add JLabel to panel 3a
jpPanel3a.add(jlcarLotSz);
//add the panel to the NORTH sector of JPanel 3
jpPanel3.add(jpPanel3a, BorderLayout.NORTH);
//JPANEL 3 BRAVO
//create second nested sub-JPanel to add into third MAIN panel
//set layout
JPanel jpPanel3b = new JPanel();
jpPanel3b.setLayout(new FlowLayout(10));
jpPanel3b.setBackground(colorKhaki);
//create titled border around this panel
//and set
Border panel3bBorder = new TitledBorder("Vehicle List Actions");
jpPanel3b.setBorder(panel3bBorder);
//create buttons for JPanel 3a
//add, remove, sell
JButton jbtAdd = new JButton("Add");
JButton jbtRemove = new JButton("Remove");
JButton jbtSell = new JButton("Sell");
//set colors for panel 3b JButtons
jbtAdd.setBackground(colorTan);
jbtRemove.setBackground(colorTan);
jbtSell.setBackground(Color.PINK);
//create tool tip texts to inform user
//further of button actions
jbtAdd.setToolTipText("Adds a vehicle to the list");
jbtRemove.setToolTipText("Removes a vehicle from the list");
jbtSell.setToolTipText("Sells selected vehicle");
//add the buttons to the Panel
jpPanel3b.add(jbtAdd);
jpPanel3b.add(jbtRemove);
jpPanel3b.add(jbtSell);
//add second nested sub-JPanel to third MAIN panel
jpPanel3.add(jpPanel3b, BorderLayout.CENTER);
//add the third MAIN JPanel to the Frame with
//the nested panels already added
getContentPane().add(jpPanel3,BorderLayout.EAST);
//create fourth main JPanel that will go into the frame
//set layout
JPanel jpPanel4 = new JPanel();
jpPanel4.setLayout(new FlowLayout());
//set border and background color
Border border4 = new LineBorder(Color.RED, 2);
jpPanel4.setBorder(border4);
jpPanel4.setBackground(colorKhaki);
//create EXIT JButton for panel 4
JButton jbtExit = new JButton("Exit system!");
//set background red to alert user
jbtExit.setBackground(Color.RED);
//set tool tip text System Exit button
jbtExit.setToolTipText("Exits system - INFORMATION MAY BE LOST!");
//add button to panel
jpPanel4.add(jbtExit);
//add panel 4 to the south portion of the frame
getContentPane().add(jpPanel4,BorderLayout.SOUTH);
int vectorSize = vehicles.size();
}
/*protected void paint(Graphics g)
{
super.paintComponent(g);
g.drawString("Welcome to Joe's Car Lot");
}
public Vehicle displayJList(Vehicle vehicle[])
{
for(int i = 0; i < vehicles.length; i++)
System.out.println(vehicles[i]);
}
public int getArraySize()
{
return carLotSize;
}
public int getCarLotSize()
{
return carLotSize;
}
*/
public void actionPerformed(ActionEvent e)
{
/*if(e.getActionCommand().equals("OK"))
System.out.println("OK");
else
System.err.println("Error");
*/
}
public void itemStateChanged(ItemEvent e)
{
/*if(e.getActionCommand().equals("OK"))
System.out.println("OK");
else
System.err.println("Error");
*/
}
/*
public String toString()
{
System.out.println();
return vehicles;
}*/
}//end of class