Wednesday
November 26, 2014

Homework Help: Computer Science

Posted by Gaurav on Tuesday, April 10, 2012 at 9:59pm.

I am making a object oriented program and hashing the list of make of an electronic and type to the JCombobox...i am getting this number Exception error...it will nice if you could tell why am i getting it eventhough i am doing the casting and everything. Try to help ASAP! thank you. Here's my code.
The following code is for buyPrinterDialog box.
public class BuyPrinters extends JDialog {

/**
*
*/
private static final long serialVersionUID = 1L;
private final JPanel contentPanel = new JPanel();
private JTextField textField;
String[] make = {"Lexmark", "HP" , "Apple" , "Brother" , "Canon", "Xerox"};
String [] type = {"Inkjet", "Laserjet"};
HashMap LexmarkPriceList = null;
HashMap HPPriceList = null;
HashMap ApplePriceList = null;
HashMap BrotherPriceList = null;
HashMap CanonPriceList = null;
HashMap XeroxPriceList = null;



/**
* Launch the application.
*/
MyFrame parent = null;
public static void main(String[] args) {
try {
BuyPrinters dialog = new BuyPrinters(null);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the dialog.
*/
JComboBox makeComboBox = new JComboBox();
JComboBox typeComboBox = new JComboBox();
public BuyPrinters(MyFrame parent) {

this.parent = parent;

setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Gaurav sharma\\workspace\\Gaurav.Lovepreet.Harpreet.Java2.Project\\pics and icons\\printer_64.png"));
setTitle("BuyPrinters");
setBounds(100, 100, 525, 263);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(new Color(204, 204, 204));
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JLabel lblMake = new JLabel("Make:");
lblMake.setFont(new Font("Tahoma", Font.BOLD, 12));
lblMake.setBounds(10, 11, 236, 24);
contentPanel.add(lblMake);
}
{

makeComboBox.setBounds(10, 46, 305, 20);
makeComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updatePriceBox();
}


});

contentPanel.add(makeComboBox);
}


{
JLabel lblType = new JLabel("Type:");
lblType.setFont(new Font("Tahoma", Font.BOLD, 12));
lblType.setBounds(10, 77, 236, 24);
contentPanel.add(lblType);
}
{

typeComboBox.setBounds(10, 112, 305, 20);

typeComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updatePriceBox();
}


});
contentPanel.add(typeComboBox);
}
{
textField = new JTextField();
textField.setEditable(false);
textField.setBounds(66, 155, 86, 20);
contentPanel.add(textField);
textField.setColumns(10);
}
{
JLabel lblPrice = new JLabel("Price:");
lblPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
lblPrice.setBounds(10, 157, 46, 14);
contentPanel.add(lblPrice);
}
{
JPanel panel = new JPanel();
panel.setBackground(new Color(102, 255, 255));
panel.setBounds(348, 21, 151, 151);
contentPanel.add(panel);
panel.setLayout(null);
{
JButton btnNewButton = new JButton("");
btnNewButton.setIcon(new ImageIcon("C:\\Users\\Gaurav sharma\\workspace\\Gaurav.Lovepreet.Harpreet.Java2.Project\\pics and icons\\printer_64.png"));
btnNewButton.setBounds(0, 0, 151, 151);
panel.add(btnNewButton);
}
}
{
JPanel panel = new JPanel();
panel.setBackground(new Color(255, 153, 255));
panel.setBounds(0, 11, 338, 170);
contentPanel.add(panel);
}

JButton btnOk = new JButton("Ok");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
handleOk();
}
});
btnOk.setBounds(318, 191, 89, 23);
contentPanel.add(btnOk);

JButton btnCancel = new JButton("Cancel");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
handleCancel();
}
});
btnCancel.setBounds(417, 191, 89, 23);
contentPanel.add(btnCancel);
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(new Color(102, 255, 255));
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
//getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
handleCancel();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}

createMakePriceLists();

initializeMakeBox();
updatePriceBox();




}

private void handleCancel()
{
this.setVisible(false);
}


//Handling the Okay button.
private void handleOk()
{
this.setVisible(false);

Float price = Float.parseFloat(textField.getText());


Date manufactureDate = new Date();
int warrantyPeriodInYears = 3;


String make = (String) makeComboBox.getSelectedItem();
InkJet printer1 = new InkJet( price, manufactureDate, warrantyPeriodInYears, "type" ,make);

if (parent != null)
{
parent.updatePurchasedItemList(printer1);
}



}



//Creating Make pricelist which depends on the type they buy.
private void createMakePriceLists()
{
LexmarkPriceList = new HashMap();
LexmarkPriceList.put("Inkjet", 659f);
LexmarkPriceList.put("Laserjet", 799f);
HPPriceList = new HashMap();
HPPriceList.put("Inkjet", 299f);
HPPriceList.put("Laserjet", 359f);
ApplePriceList = new HashMap();
ApplePriceList.put("Inkjet", 999f);
ApplePriceList.put("Laserjet", 1089f);
BrotherPriceList = new HashMap();
BrotherPriceList.put("Inkjet", 99f);
BrotherPriceList.put("Laserjet", 159f);
CanonPriceList = new HashMap();
CanonPriceList.put("Inkjet", 299f);
CanonPriceList.put("Laserjet", 289f);
XeroxPriceList = new HashMap();
XeroxPriceList.put("Inkjet", 1299f);
XeroxPriceList.put("Laserjet", 1599f);


}



//Creating the type Price list which changes the price depending on whether the user buys laser or inkjet.


private void updatePriceBox()
{
String make = (String) makeComboBox.getSelectedItem();
System.out.println("update price box: selected make:"+make);
HashMap map = new HashMap() ;
if (make.equals("Lexmark"))
map = LexmarkPriceList;
if (make.equals("HP"))
map = HPPriceList;
if (make.equals("Xerox"))
map = XeroxPriceList;
if (make.equals("Brother"))
map = BrotherPriceList;
if (make.equals("Canon"))
map = CanonPriceList;
if (make.equals("Apple"))
map.equals(ApplePriceList);


makeComboBox.getSelectedItem();
Float price = (Float) map.get(make);
System.out.println(price);
textField.setText(""+ price);
}

//Initialize the Make box.
private void initializeMakeBox()
{
makeComboBox.removeAllItems();
for (String s : make) {
makeComboBox.addItem(s);
}

typeComboBox.removeAllItems();
for (String s : type) {
typeComboBox.addItem(s);

}


}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

computer science - to write a report on Object-Oriented Systems. The report ...
computer - Object-Oriented Data and Processes Identify a task you perform ...
computer programming - Write a program that simulates the dial of a phone number...
computer - A-Asking the user to pick a number between 1 and 20 and having the ...
computer programming - Mr. Dacara owns 20 apartment buildings. Each building ...
Computers - 1. There is a requirement to store 750 records. The number of ...
Computers - 1. There is a requirement to store 750 records. The number of ...
Medical Information Management - Medical records at willow nursing home have the...
computer science /use java language - write the program that inputs a string ...
Programming - Hello All i am new in dynamics Ax when i am going to connect the C...

Search
Members