Welcome to Dream.In.Code
Become a Java Expert!

Join 150,124 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,021 people online right now. Registration is fast and FREE... Join Now!




errors in my GUI

 
Reply to this topicStart new topic

errors in my GUI

smithgang1994
22 Jun, 2008 - 09:37 AM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I am getting the following errors...could someone help?

C:\Users\Michael\Desktop\java6\GUI.java:317: ')' expected
^
C:\Users\Michael\Desktop\java6\GUI.java:493: ';' expected

CODE

import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;



public class GUI extends JFrame implements ActionListener
{

private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5   getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue;   //7   getresult()
private JTextField jtftotalInv;//8
private JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;
private JButton    btnAdd;
private JButton btnDelete;
private JButton btnModify;
private JButton btnSave;
private JButton btnSearch;
private JButton btnLoadfile;
DVD[] dvd;
int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
  //this.inventory1 = inventory1;


    JLabel jl;
    JPanel jp;

setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (10);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label3.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(true);
add( label3 ); // add label2 to JFrame
add(jtfVideo);


label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label4.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (5);
jtfRating.setEditable(true);
add( label4 ); // add label2 to JFrame
add(jtfRating);

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label5.setVerticalTextPosition( SwingConstants.TOP );
jtfNumber = new JTextField (20);
jtfNumber.setEditable(true);
add( label5 ); // add label2 to JFrame
add(jtfNumber);

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label6.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (10);
jtfStock.setEditable(true);
add( label6 ); // add label2 to JFrame
add(jtfStock);

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label7.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (10);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label8.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (10);
jtfPrice.setEditable(true);
add( label8 ); // add label2 to JFrame
add(jtfPrice);

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label9.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (10);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label10.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (10);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );

btnAdd = new JButton( "Add" );
btnAdd.addActionListener(this);
add( btnAdd );

btnDelete = new JButton( "Delete" );
btnDelete.addActionListener(this);
add( btnDelete );

btnModify = new JButton( "Modify" );
btnModify.addActionListener(this);
add( btnModify );

btnSave = new JButton( "Save" );
btnSave.addActionListener(this);
add( btnSave );

btnSearch = new JButton( "Search" );
btnSearch.addActionListener(this);
add( btnSearch );

btnLoadfile = new JButton( "Load file" );
btnLoadfile.addActionListener(this);
add( btnLoadfile );



setSize(800,500);
     setVisible(true);



} // end LabelFrame constructor


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;

}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" + dvd[index].CalculateTotalInventoryValue(dvd));
}
// to display next movie
void displayFirst(){
        index = 0;
        display();

    }
    void displayNext() {
          index++;
          if(index >= dvd.length )   // wrap around
            index = 0;
          display();
    }
    // display previous
        void displayPrevious() {
            index--;
            if(index < 0)                    // wrap around
              index = dvd.length - 1;
        display();
    }

    void displayLast(){
            index = dvd.length - 1;
            display();
        }

        void displaydelete(){
            index = dvd.length -1;
        }

        void displayAdd(){
            index++;
            if(index >= dvd.length )
            index = 0;
            display();
}





public void actionPerformed(ActionEvent e){
    Object buttonPressed = e.getSource();
    if(buttonPressed == btnFirst){
        index = 0;
        displayFirst();
        return;
    }
    if (buttonPressed == btnNext) {
        displayNext();
        return;
    }
    if (buttonPressed == btnPrevious){
        displayPrevious();
        return;
    }
    if (buttonPressed == btnLast){
        displayLast();
        return;
    }
    if (buttonPressed ==btnDelete){
        DVD[] newOne = new DVD[dvd.length -1];
        int k = 0;
        for(int i = 0; i<dvd.length; i++){
            newOne[k++] = dvd[i];
        }
        dvd = newOne;
        displayNext();
        return;
    }

    addButton.addActionListener(new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                FeeQtyProduct temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);
                int item = dvd.getitem() +1;

                    index = (item - 2) % item;
                    repaintGUI();


                if(video.getText().equals("Add Video" )) // catches for assigning more then one blank at a time
                {
                    JOptionPane.showMessageDialog(null, "Please fill out the blank entry you already have before adding more\nRemember: Push Modify when you finish with your changes","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                }

                if(rating.getText().equals("Add Rating" ) !=true) // allows the adding of an entry
                {
                    FeeQtyProduct product = new FeeQtyProduct( "Add Video", Integer.parseInt(number.getText()) + 1, 0, 0.0, "Add Rating");
                    index = (item - 1) % item;
                    dvd.addFeeQtyProduct(product );
                    repaintGUI();
                }
                if (item == 29) // catches for going over static inventory size
                {
                    dvd.removeFeeQtyProduct(temp);
                    JOptionPane.showMessageDialog(null, "Please No More Entries\n You can increase my capacity in the java file CdInvApp.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                }

            }// end action

}

        btnSave.addActionListener(new ActionListener() // saves the dat file in English
        {
            public void actionPerformed(ActionEvent e)
            {
                int number = dvd.getNumber();
                InventoryStorage record = new InventoryStorage(); //calls inventroy storage class
                record.openFile();
                int currentRecord = 0; // keeps track of number of cycles

                do // cycles through the list adding them one at a time
                {
                    record.addRecords();
                    currentRecord = currentRecord + 1;
                    index = (++index) % number;

                } while (currentRecord < number); //ends while

                    record.closeFile(); //closes file
            }//end action

        }  // end class

        btnModify.addActionListener(new ActionListener() // saves changes to the GUI
        {

            public void actionPerformed(ActionEvent e)
            {

                if (videoText.getText().equals(""))  //traps for blank entry
                {
                    JOptionPane.showMessageDialog(null, "Please Complete the Entry.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                }


                if (ratingText.getText().equals(""))  //traps for blank entry
                {
                    JOptionPane.showMessageDialog(null, "Please Complete the Entry.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                }

                try // traps for letters and blank entry
                {

                    Double.parseDouble(priceText.getText());
                    Double.parseDouble(stockText.getText());

                    }
                    catch (Exception d)
                    {
                    JOptionPane.showMessageDialog(null, "Recheck Entry use numbers for price and quantity.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                    }


                String name; int number;  int stock; double price; String rating; // declares variables

                video = videoText.getText();
            number = Integer.parseInt(numberText.getText());
            stock = Integer.parseInt(stockText.getText());
            price = Double.parseDouble(priceText.getText());
            rating = ratingText.getText();


            FeeQtyProduct modify =  (FeeQtyProduct) dvd.getFeeQtyProduct(index);

                modify.setNumber(number);
                modify.setVideo(video);
                modify.setStock(stock);
                modify.setPrice(price);
                modify.setRating(rating);
                repaintGUI();
            }

        } // end class

        btndelete.addActionListener(new ActionListener()  //allows user to delete entry and sorts product numbers to be in sequence
        {
            public void actionPerformed(ActionEvent e)
            {

                int number = dvd.getNumber();
                FeeQtyProduct temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);

                if (number != 0)
                {

                    if(Integer.parseInt(numberText.getText()) != item)
                    {

                        dvd.remove(index);
                        repaintGUI();
                        int i = Integer.parseInt(numberText.getText());
                        index = (++index) % item;
                        repaintGUI();
                        int j = Integer.parseInt(numberText.getText());

                        if (i > j)// my own little sort mechanism to keep Product numbers in sequence
                            index = (-- index) % number;
                            repaintGUI();
                            temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);
                            temp.setnumber(j-1);
                            index = (++index) % number;
                            repaintGUI();

                    }// end if

                    if(Integer.parseInt(numberText.getText()) == number) // uses a different method to remove entry if it is the last one prevents blank entry from being in the mix
                    {
                        dvd.removeFeeQtyProduct(temp);
                        index = (++index) % number;
                        repaintGUI();
                    }//end if

                }// end if

                if (number == 1) // catches for 0 items error
                {

                    FeeQtyProduct product = new FeeQtyProduct( "Add Video",number, 0, 0.0, "Add Rating");
                    dvd.addFeeQtyProduct(product);
                    JOptionPane.showMessageDialog(null, "Delete Process Complete.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                } //end if


            }// end action



        } // end class

        btnSearch.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                //declare variables and gets text from GUI
                String search = searchText.getText();
                String name = videoText.getText();
                int number = Integer.parseInt(numberText.getText());
                int number = dvd.getNumber();
                int currentRecord = 0;

                do // gets text and checks for a match
                {
                    index = (++index) % number;
                    repaintGUI();
                    name = artistText.getText();
                    number = Integer.parseInt(numberText.getText());
                    search = searchText.getText();
                    currentRecord = (++currentRecord);

                    if(name.equalsIgnoreCase( search )) // stops on item
                        repaintGUI();

                    if(searchText.getText().equals("" )) //catches for no entry in the search box
                    {
                        JOptionPane.showMessageDialog(null, "You wanna search for nothing?","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                        index = (--index) % number;
                        break;
                    }

                    if(currentRecord == number +1) // displays message if no results match search
                    {
                        JOptionPane.showMessageDialog(null, "No Results Found","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                        break;
                    }


                }while(video.equalsIgnoreCase(search ) != true); //ends do while


            }

}





    class InventoryStorage // creates the output file
    {
        private Formatter output; // object used to output text to file

            public void openFile()
            {
                try
                {
                        String strDirectoy ="C://data/";

                        // Create one directory
                        boolean success = (new File(strDirectoy)).mkdir();

                    if (success)
                    {

                              JOptionPane.showMessageDialog(null, "we had to create a directory named data in your C drive.","That's affirmative", JOptionPane.PLAIN_MESSAGE);

                        }   //end if


                 }//end try

                catch (Exception e)
                {


                          JOptionPane.showMessageDialog(null, "You do not have write access to the C: drive.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);

                    }//end catch



                try
                {

                              output = new Formatter( "C:/data/inventory.dat");

                } // end try

            catch ( SecurityException securityException ) //catches for write access and exits program
            {
                JOptionPane.showMessageDialog(null, "You do not have write access to this file.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                System.exit( 1 );

            } // end catch

            catch ( FileNotFoundException filesNotFoundException ) //catches for write access and exits program
            {
                JOptionPane.showMessageDialog(null, "Please create a file named data in your c drive","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                System.exit( 1 );

            } // end catch


            JOptionPane.showMessageDialog(null, "file saved successfully.","That's affirmative", JOptionPane.PLAIN_MESSAGE);



        } // end method openFile

        public void addRecords() // adds the records to the file
        {
FeeQtyProduct record = (FeeQtyProduct) dvd.getFeeQtyProduct(index);

            // rounds the output numbers to 2 decimals

            BigDecimal roundPrice = new BigDecimal(Double.toString(record.restock() ));
            roundPrice = roundPrice.setScale(2, RoundingMode.HALF_UP);

            BigDecimal roundValue= new BigDecimal(Double.toString(record.total()));
            roundValue= roundValue.setScale(2, RoundingMode.HALF_UP);

            BigDecimal roundTotal= new BigDecimal(Double.toString(dvd.value()));
            roundTotal = roundTotal.setScale(2, RoundingMode.HALF_UP);


        if (record != null) //catches for blank record - overkill because we can never have a blank record
        {
            output.format( "Video:%s Item Number#: %s Items in Stock#:%. Price: $%.Rating: %s" ,
            record.getVideo(), record.getNumber(), record.getStock(), record.getPrice() ,
            " Rating", record.getRating() + "  with restock Fee $" + (roundPrice) + "  value: $" + (roundValue) + " Inventory Total $" + (roundTotal) + "\t\n END OF LINE\t\t");

        } // end if


    } // end addRecords

    public void closeFile() // close the file
    {
        if ( output != null )
        output.close();

    } // end method closeFile



}

}

} // end class GUI

User is offlineProfile CardPM
+Quote Post

nick2price
RE: Errors In My GUI
22 Jun, 2008 - 11:20 AM
Post #2

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
What ide are you using. Why dont you just download one which points u too the line where your errors are?
User is offlineProfile CardPM
+Quote Post

pbl
RE: Errors In My GUI
22 Jun, 2008 - 11:44 AM
Post #3

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
CODE

        addButton.addActionListener(new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {


This does not make sense.. adding an actionListener to a button in your actionPerformed method
and your button name is not "addButton" but "btnAdd"

replace the preceeding lines by:

if(buttonPressed == btnAdd)
{

re-align your { and } and you should be on a better track

same thing for the other buttons for the replace, delete, ....

This post has been edited by pbl: 22 Jun, 2008 - 11:46 AM
User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Errors In My GUI
22 Jun, 2008 - 12:06 PM
Post #4

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I am still checking my {} but what about this other error?

C:\Users\Michael\Desktop\java6\GUI.java:547: illegal start of expression
public void addRecords() // adds the records to the file
^
C:\Users\Michael\Desktop\java6\GUI.java:579: ';' expected
} // end class GUI
^
C:\Users\Michael\Desktop\java6\GUI.java:579: '}' expected
} // end class GUI
CODE

import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;



public class GUI extends JFrame implements ActionListener
{

private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5   getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue;   //7   getresult()
private JTextField jtftotalInv;//8
private JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;
private JButton    btnAdd;
private JButton btnDelete;
private JButton btnModify;
private JButton btnSave;
private JButton btnSearch;
private JButton btnLoadfile;
DVD[] dvd;
int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
  //this.inventory1 = inventory1;


    JLabel jl;
    JPanel jp;

setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (10);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label3.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(true);
add( label3 ); // add label2 to JFrame
add(jtfVideo);


label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label4.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (5);
jtfRating.setEditable(true);
add( label4 ); // add label2 to JFrame
add(jtfRating);

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label5.setVerticalTextPosition( SwingConstants.TOP );
jtfNumber = new JTextField (20);
jtfNumber.setEditable(true);
add( label5 ); // add label2 to JFrame
add(jtfNumber);

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label6.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (10);
jtfStock.setEditable(true);
add( label6 ); // add label2 to JFrame
add(jtfStock);

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label7.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (10);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label8.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (10);
jtfPrice.setEditable(true);
add( label8 ); // add label2 to JFrame
add(jtfPrice);

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label9.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (10);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label10.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (10);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );

btnAdd = new JButton( "Add" );
btnAdd.addActionListener(this);
add( btnAdd );

btnDelete = new JButton( "Delete" );
btnDelete.addActionListener(this);
add( btnDelete );

btnModify = new JButton( "Modify" );
btnModify.addActionListener(this);
add( btnModify );

btnSave = new JButton( "Save" );
btnSave.addActionListener(this);
add( btnSave );

btnSearch = new JButton( "Search" );
btnSearch.addActionListener(this);
add( btnSearch );

btnLoadfile = new JButton( "Load file" );
btnLoadfile.addActionListener(this);
add( btnLoadfile );



setSize(800,500);
     setVisible(true);



} // end LabelFrame constructor


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;

}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" + dvd[index].CalculateTotalInventoryValue(dvd));
}
// to display next movie
void displayFirst(){
        index = 0;
        display();

    }
    void displayNext() {
          index++;
          if(index >= dvd.length )   // wrap around
            index = 0;
          display();
    }
    // display previous
        void displayPrevious() {
            index--;
            if(index < 0)                    // wrap around
              index = dvd.length - 1;
        display();
    }

    void displayLast(){
            index = dvd.length - 1;
            display();
        }

        void displaydelete(){
            index = dvd.length -1;
        }

        void displayAdd(){
            index++;
            if(index >= dvd.length )
            index = 0;
            display();
}





public void actionPerformed(ActionEvent e){
    Object buttonPressed = e.getSource();
    if(buttonPressed == btnFirst){
        index = 0;
        displayFirst();
        return;
    }
    if (buttonPressed == btnNext) {
        displayNext();
        return;
    }
    if (buttonPressed == btnPrevious){
        displayPrevious();
        return;
    }
    if (buttonPressed == btnLast){
        displayLast();
        return;
    }
    if (buttonPressed ==btnDelete){
        DVD[] newOne = new DVD[dvd.length -1];
        int k = 0;
        for(int i = 0; i<dvd.length; i++){
            newOne[k++] = dvd[i];
        }
        dvd = newOne;
        displayNext();
        return;
    }

    if(buttonPressed == btnAdd)
    {
        FeeQtyProduct temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);
                int item = dvd.getitem() +1;

                    index = (item - 2) % item;
                    repaintGUI();


                if(video.getText().equals("Add Video" )) // catches for assigning more then one blank at a time
                {
                    JOptionPane.showMessageDialog(null, "Please fill out the blank entry you already have before adding more\nRemember: Push Modify when you finish with your changes","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                }

                if(rating.getText().equals("Add Rating" ) !=true) // allows the adding of an entry
                {
                    FeeQtyProduct product = new FeeQtyProduct( "Add Video", Integer.parseInt(number.getText()) + 1, 0, 0.0, "Add Rating");
                    index = (item - 1) % item;
                    dvd.addFeeQtyProduct(product );
                    repaintGUI();
                }
                if (item == 29) // catches for going over static inventory size
                {
                    dvd.removeFeeQtyProduct(temp);
                    JOptionPane.showMessageDialog(null, "Please No More Entries\n You can increase my capacity in the java file CdInvApp.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                }



}

        if(buttonPressed == btnSave)
            {
                int number = dvd.getNumber();
                InventoryStorage record = new InventoryStorage(); //calls inventroy storage class
                record.openFile();
                int currentRecord = 0; // keeps track of number of cycles

                do // cycles through the list adding them one at a time
                {
                    record.addRecords();
                    currentRecord = currentRecord + 1;
                    index = (++index) % number;

                } while (currentRecord < number); //ends while

                    record.closeFile(); //closes file


        }

        if(buttonPressed == btnModify)
            {

                if (videoText.getText().equals(""))  //traps for blank entry
                {
                    JOptionPane.showMessageDialog(null, "Please Complete the Entry.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                }


                if (ratingText.getText().equals(""))  //traps for blank entry
                {
                    JOptionPane.showMessageDialog(null, "Please Complete the Entry.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                }

                try // traps for letters and blank entry
                {

                    Double.parseDouble(priceText.getText());
                    Double.parseDouble(stockText.getText());

                    }
                    catch (Exception d)
                    {
                    JOptionPane.showMessageDialog(null, "Recheck Entry use numbers for price and quantity.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                    }


                String name; int number;  int stock; double price; String rating; // declares variables

                video = videoText.getText();
            number = Integer.parseInt(numberText.getText());
            stock = Integer.parseInt(stockText.getText());
            price = Double.parseDouble(priceText.getText());
            rating = ratingText.getText();


            FeeQtyProduct modify =  (FeeQtyProduct) dvd.getFeeQtyProduct(index);

                modify.setNumber(number);
                modify.setVideo(video);
                modify.setStock(stock);
                modify.setPrice(price);
                modify.setRating(rating);
                repaintGUI();


        } // end class

        if(buttonPressed == btnDelete)
            {

                int number = dvd.getNumber();
                FeeQtyProduct temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);

                if (number != 0)
                {

                    if(Integer.parseInt(numberText.getText()) != item)
                    {

                        dvd.remove(index);
                        repaintGUI();
                        int i = Integer.parseInt(numberText.getText());
                        index = (++index) % item;
                        repaintGUI();
                        int j = Integer.parseInt(numberText.getText());

                        if (i > j)// my own little sort mechanism to keep Product numbers in sequence
                            index = (-- index) % number;
                            repaintGUI();
                            temp = (FeeQtyProduct) dvd.getFeeQtyProduct(index);
                            temp.setnumber(j-1);
                            index = (++index) % number;
                            repaintGUI();

                    }// end if

                    if(Integer.parseInt(numberText.getText()) == number) // uses a different method to remove entry if it is the last one prevents blank entry from being in the mix
                    {
                        dvd.removeFeeQtyProduct(temp);
                        index = (++index) % number;
                        repaintGUI();
                    }//end if

                }// end if

                if (number == 1) // catches for 0 items error
                {

                    FeeQtyProduct product = new FeeQtyProduct( "Add Video",number, 0, 0.0, "Add Rating");
                    dvd.addFeeQtyProduct(product);
                    JOptionPane.showMessageDialog(null, "Delete Process Complete.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                    repaintGUI();
                } //end if


            }// end action





        if(buttonPressed == btnSearch)
            {
                //declare variables and gets text from GUI
                String search = searchText.getText();
                String name = videoText.getText();
                int number = Integer.parseInt(numberText.getText());
                int number = dvd.getNumber();
                int currentRecord = 0;

                do // gets text and checks for a match
                {
                    index = (++index) % number;
                    repaintGUI();
                    name = artistText.getText();
                    number = Integer.parseInt(numberText.getText());
                    search = searchText.getText();
                    currentRecord = (++currentRecord);

                    if(name.equalsIgnoreCase( search )) // stops on item
                        repaintGUI();

                    if(searchText.getText().equals("" )) //catches for no entry in the search box
                    {
                        JOptionPane.showMessageDialog(null, "You wanna search for nothing?","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                        index = (--index) % number;
                        break;
                    }

                    if(currentRecord == number +1) // displays message if no results match search
                    {
                        JOptionPane.showMessageDialog(null, "No Results Found","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                        break;
                    }


                }while(video.equalsIgnoreCase(search ) != true); //ends do while


            }







    class InventoryStorage // creates the output file
    {
        private Formatter output; // object used to output text to file

            public void openFile()
            {
                try
                {
                        String strDirectoy ="C://data/";

                        // Create one directory
                        boolean success = (new File(strDirectoy)).mkdir();

                    if (success)
                    {

                              JOptionPane.showMessageDialog(null, "we had to create a directory named data in your C drive.","That's affirmative", JOptionPane.PLAIN_MESSAGE);

                        }   //end if


                 }//end try

                catch (Exception e)
                {


                          JOptionPane.showMessageDialog(null, "You do not have write access to the C: drive.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);

                    }//end catch



                try
                {

                              output = new Formatter( "C:/data/inventory.dat");

                } // end try

            catch ( SecurityException securityException ) //catches for write access and exits program
            {
                JOptionPane.showMessageDialog(null, "You do not have write access to this file.","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                System.exit( 1 );

            } // end catch

            catch ( FileNotFoundException filesNotFoundException ) //catches for write access and exits program
            {
                JOptionPane.showMessageDialog(null, "Please create a file named data in your c drive","Negative GhostRider the pattern is full", JOptionPane.ERROR_MESSAGE);
                System.exit( 1 );

            } // end catch


            JOptionPane.showMessageDialog(null, "file saved successfully.","That's affirmative", JOptionPane.PLAIN_MESSAGE);
}


        } // end method openFile

        public void addRecords() // adds the records to the file
        {
FeeQtyProduct record = (FeeQtyProduct) dvd.getFeeQtyProduct(index);

            // rounds the output numbers to 2 decimals

            BigDecimal roundPrice = new BigDecimal(Double.toString(record.restock() ));
            roundPrice = roundPrice.setScale(2, RoundingMode.HALF_UP);

            BigDecimal roundValue= new BigDecimal(Double.toString(record.total()));
            roundValue= roundValue.setScale(2, RoundingMode.HALF_UP);

            BigDecimal roundTotal= new BigDecimal(Double.toString(dvd.value()));
            roundTotal = roundTotal.setScale(2, RoundingMode.HALF_UP);


        if (record != null) //catches for blank record - overkill because we can never have a blank record
        {
            output.format( "Video:%s Item Number#: %s Items in Stock#:%. Price: $%.Rating: %s" ,
            record.getVideo(), record.getNumber(), record.getStock(), record.getPrice() ,
            " Rating", record.getRating() + "  with restock Fee $" + (roundPrice) + "  value: $" + (roundValue) + " Inventory Total $" + (roundTotal) + "\t\n END OF LINE\t\t");

        } // end if


    } // end addRecords

    public void closeFile() // close the file
    {