Heres my code:
I get three errors,//Thomas Harrald //IT215 Checkpoint Inventory Program //Camera Inventory program import java.util.Arrays; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import javax.swing.*; import java.awt.*; import java.awt; import java.awt.event.*; // Stores and then gets info on a Camera public class CameraProgram5 extends JFrame { private JTextArea txt; private Inventory inv; private int current = 0; private JButton next; CameraProgram5 gui = new CameraProgram5(); gui.pack(); gui.setVisible(true); public static void main(String args[]) { super("Camera Shack"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CameraClass[] cameras; CameraClass nikonCamera= new CameraClass( 3100, "Nikon", "Electronics", 5, 10.00); CameraClass sonyCamera = new CameraClass( 4500, "Sony", "Electronics", 10, 300.00); CameraClass canonCamera= new CameraClass( 1550, "Canon", "Electronics", 3, 40.00); cameras = new CameraClass[ 3 ]; cameras[ 0 ] = nikonCamera; cameras[ 1 ] = sonyCamera; cameras[ 2 ] = canonCamera; inv = new Inventory(); inv.add(nikonCamera); inv.add(sonyCamera); inv.add(canonCamera); // sort inv.sort(); //output them. for (int i = 0; i < inv.size(); i++) { System.out.println(inv.get(i)); System.out.println(); } System.out.println("Total value: $" + String.format("%.2f",inv.value())); // gui stuff JPanel panel = new JPanel(); txt = new JTextArea(15,20); txt.setEditable(false);//user shouldn't change it panel.add(txt); JPanel buttonpanel = new JPanel(); buttonpanel.setLayout(new BoxLayout(buttonpanel,BoxLayout.Y_AXIS)); JButton first = new JButton("First"); first.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { current = 0;// go to the beginning showCamera(); } }); buttonpanel.add(first); JButton previous = new JButton("Previous"); previous.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (current > 0) current--; else current = inv.size()-1; showCamera(); } }); buttonpanel.add(previous); JButton next = new JButton("Next"); next.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (current < inv.size()-1) current++; //advance to the end else current = 0; showCamera(); } }); buttonpanel.add(next); JButton last = new JButton("Last"); last.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { current = inv.size()-1; showCamera(); } }); buttonpanel.add(last); buttonpanel.add(new Logo()); panel.add(buttonpanel); getContentPane().add(panel); showCamera(); } public void showCamera() { txt.setText("Camera Details:\n"); txt.append(inv.get(current) + "\n"); txt.append("Total value: $" + String.format("%.2f",inv.value())); } class Logo extends JPanel { public Logo() { super(); setPreferredSize(new Dimension(200,200)); } public void paint(Graphics g) { g.setColor(Color.white); g.fillRoundRect(60,60,110,90,5,5); g.setColor(Color.black); g.drawString("Camera Shack", 70, 105); } } }
identifier expected: gui.pack();
identifier expected: gui.setVisible(true);
Illegal start of expression: gui.setVisible(true);
I have tried rereading the readings, and importing specifically java.awt since that is where pack() is. As I'm writing this, I think the problem might be in the first part of that ( CameraProgram5 gui = new CameraProgram5(); )
Any help would be greatly appreciated!