I receive error at camera.Camera.<init>(Camera.java:19)
at camera.Camera.init(Camera.java:32)
at camera.Camera.<init>(Camera.java:21)
at camera.Camera.init(Camera.java:32)
at camera.Camera.<init>(Camera.java:21)
at camera.Camera.init(Camera.java:32)
at camera.Camera.<init>(Camera.java:21)
at camera.Camera.init(Camera.jav
and continues. Please help, last day
package camera;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
/**
*
* @author FDR
*/
public final class Camera extends JFrame{
private JTextArea txt;
private Camera inv;
private int currentDisplay = 0;
public Camera() {
super("Camera Program");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
}
public void init() {
ActionElectronics p1 = new ActionElectronics(1, "Action Product 1", 3, 59.99, "Misc");
ActionElectronics p2 = new ActionElectronics(2, "Action Product 2", 1, 28.99, "Other");
ActionElectronics p3 = new ActionElectronics(3, "Drama Product 1", 4, 25.49, "Other");
ActionElectronics p4 = new ActionElectronics(4, "Drama Product 2 ", 4, 21.49, "Other");
inv = new Camera();
inv.add(p1);
inv.add(p2);
inv.add(p3);
inv.add(p4);
inv.sort();
// Output
for (int i = 0; i < inv.size(); i++) {
System.out.println("Product number: " + inv.get(i).getItem());
System.out.println("Product name: " + inv.get(i).getName());
System.out.println("Units in stock: " + inv.get(i).getUnits());
System.out.println("Price: $" + String.format("%.2f",inv.get(i).getPrice()));
System.out.println("Total value: $" + String.format("%.2f",inv.get(i).value()));
System.out.println("Fee: $" + String.format("%.2f",inv.get(i).fee()));
System.out.println();
}
//total
System.out.println("Total value: $" + String.format("%.2f",inv.value()));
//GUI
JPanel panel = new JPanel();
txt = new JTextArea(15,20);
txt.setEditable(false);
panel.add(txt);
JPanel buttonpanel = new JPanel();
buttonpanel.setLayout(new BoxLayout(buttonpanel,BoxLayout.Y_AXIS));
JPanel anotherbuttonpanel = new JPanel();
anotherbuttonpanel.setLayout(new BoxLayout(anotherbuttonpanel,BoxLayout.Y_AXIS));
JButton first = new JButton("First");
first.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
currentDisplay = 0;// go to the beginning
displayProduct();
}
});
buttonpanel.add(first);
JButton previous = new JButton("Previous");
previous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentDisplay > 0) {
currentDisplay--;
}
else {
currentDisplay = inv.size() - 1;
}
displayProduct();
}
});
buttonpanel.add(previous);
JButton next = new JButton("Next");
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentDisplay < inv.size()-1) {
currentDisplay++;
} //advance to the end
else {
currentDisplay = 0;
}
displayProduct();
}
});
buttonpanel.add(next);
JButton last = new JButton("Last");
last.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
currentDisplay = inv.size()-1;
displayProduct();
}
});
buttonpanel.add(last);
// new buttons
JButton save = new JButton("Save");
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
inv.save();
}
});
anotherbuttonpanel.add(save);
JButton search = new JButton("Search");
search.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String str = JOptionPane.showInputDialog(Camera.this,"Enter Product name to search for");
int result = inv.searchForActionElectronics (str);
if (result == -1) {
JOptionPane.showMessageDialog(Camera.this, "Sorry Nothing found");
} // do nothing
else { // show the item
currentDisplay = result;
displayProduct();
}
}
});
anotherbuttonpanel.add(search);
JButton add = new JButton("Add");
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = JOptionPane.showInputDialog(Camera.this,"Enter Product name");
int units = Integer.parseInt(JOptionPane.showInputDialog(Camera.this,"Enter units in stock"));
double price = Double.parseDouble(JOptionPane.showInputDialog(Camera.this,"Enter the price of each item"));
String stu = JOptionPane.showInputDialog(Camera.this,"Enter the Category if known");
// create object
ActionElectronics ap = new ActionElectronics(inv.highestNumber()+1, name, units, price, stu);
//input
inv.addNewActionElectronics(ap);
currentDisplay = inv.size()-1;
displayProduct();
}
});
anotherbuttonpanel.add(add);
JButton modify = new JButton("Modify");
modify.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// get new values and set them
ActionElectronics ap = (ActionElectronics) inv.get(currentDisplay);
ap.setItem(Integer.parseInt(
JOptionPane.showInputDialog(Camera.this,"Enter new item number",ap.getItem())));
ap.setName(
JOptionPane.showInputDialog(Camera.this,"Enter new Product name",ap.getName()));
ap.setUnits(Integer.parseInt(
JOptionPane.showInputDialog(Camera.this,"Enter new units in stock",ap.getUnits())));
ap.setPrice(Double.parseDouble(
JOptionPane.showInputDialog(Camera.this,"Enter new price of each item",ap.getPrice())));
ap.setCategory(
JOptionPane.showInputDialog(Camera.this,"Enter new category if known",ap.getCategory()));
displayProduct();
}
});
anotherbuttonpanel.add(modify);
JButton delete = new JButton("Delete");
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (inv.size() > 0) { // else there is nothing to delete
inv.deleteActionElectronics(inv.get(currentDisplay));
currentDisplay--;
if (currentDisplay < 0) {
currentDisplay = 0;
}
displayProduct();
}
}
});
anotherbuttonpanel.add(delete);
buttonpanel.add(new Logo());
panel.add(buttonpanel);
panel.add(anotherbuttonpanel);
getContentPane().add(panel);
displayProduct();
}
// display
public void displayProduct() {
txt.setText("Product Details:\n");
txt.append("Item number: " + inv.get(currentDisplay).getItem() + "\n");
txt.append("Product name: " + inv.get(currentDisplay).getName() + "\n");
txt.append("Units in stock: " + inv.get(currentDisplay).getUnits() + "\n");
txt.append("Price: $" + String.format("%.2f",inv.get(currentDisplay).getPrice()) + "\n");
txt.append("Total value: $" + String.format("%.2f",inv.get(currentDisplay).value()) + "\n");
txt.append("Fee: $" + String.format("%.2f",inv.get(currentDisplay).fee()) + "\n\n");
txt.append("Total value: $" + String.format("%.2f",inv.value()));
}
public static void main(String args[]) {
Camera gui = new Camera();
gui.pack();
gui.setVisible(true);
}
//