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

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




GUI JAVA Search Handler

 
Reply to this topicStart new topic

GUI JAVA Search Handler, Getting the search to work properly.

MFam
18 Mar, 2008 - 07:12 PM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

QUOTE

Can someone tell me what I am setting up incorrectly with the search button handler? Trying to get it to prompt
for a search criteria! See highlighted red area below!




CODE

import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;


class GUI extends JFrame {
// declare instance variables
// THIS IS THE VALUE THAT WILL RUN IN THE INVENTORY[ INDEX ]
//WHEN THE NEXT BUTTON IS CLICKED
    private int currentProdno = 0;

    // INVENTORY WILL GET THE VALUE PASSED IN THE CONSTRUCTOR PARAMETER
    private NameRestock[ ] inventory;

    private JTextField jtfprdItem; //1
    private JTextField jtfprdName; //2
    private JTextField jtfprdUnit; //3
    private JTextField jtfprdPrice;//4
    private JTextField jtfgetResult;//5   getresult()
    private JTextField jtfReStock; //6   getrestock()
    private JTextField jtfstrCName;//7
    private JTextField jtfinvTotal;//8
    private double totValue;
    private int i = 0;
    private JButton btnFirst;
    private JButton btnNext;
    private JButton btnPrevious;
    private JButton btnLast;
//**************************
    private JButton btnSave;
    private JButton btnAdd;
    private JButton btnDelete;
    private JButton btnModify;
    private JButton btnSearch;
//**************************
    private double tmp;
    //private Formatter output;


    GUI( NameRestock[ ] inv ) {
        super("Inventory Part 4 Program");
        inventory = inv; // ASSIGN inv FROM TO inventor

        JPanel jp;
        JLabel jl;
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Inventory Part 4");
        titlePanel.add(jl);
    ImageIcon ig = new ImageIcon("CpyLogo.jpg");
        //outerPanel.add(titlePanel);
    outerPanel.add(new JLabel(ig));

//******************************************
        JPanel numberPanel = new JPanel();
        numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Number: " );//Count of each item
        numberPanel.add(jl);
        jtfprdItem = new JTextField (3);
        jtfprdItem.setEditable(false);
        numberPanel.add(jtfprdItem);
        outerPanel.add(numberPanel);

        JPanel number1Panel = new JPanel();
        number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Name: " );//Name of item
        number1Panel.add(jl);
        jtfprdName = new JTextField (12);
        jtfprdName.setEditable(false);
        number1Panel.add(jtfprdName);
        outerPanel.add(number1Panel);

        JPanel number2Panel = new JPanel();
        number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Units: " );// Number of each item
        number2Panel.add(jl);
        jtfprdUnit = new JTextField(3);
        jtfprdUnit.setEditable(false);
        number2Panel.add(jtfprdUnit);
        outerPanel.add(number2Panel);

        JPanel number3Panel = new JPanel();
        number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Price: $ " );
        number3Panel.add(jl);
        jtfprdPrice = new JTextField(4);
        jtfprdPrice.setEditable(false);
        number3Panel.add(jtfprdPrice);
        outerPanel.add(number3Panel);

        JPanel number4Panel = new JPanel();
        number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Total: $ " );//Total Price of Items
        number4Panel.add(jl);
        jtfgetResult = new JTextField(5);
        jtfgetResult.setEditable(false);
        number4Panel.add(jtfgetResult);
        outerPanel.add(number4Panel);

        JPanel number5Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );//Restocking FEE
        number5Panel.add(jl);
        jtfReStock = new JTextField(6);
        jtfReStock.setEditable(false);
        number5Panel.add(jtfReStock);
        outerPanel.add(number5Panel);

        JPanel number6Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Company Name: " );//Company Name
        number6Panel.add(jl);
        jtfstrCName = new JTextField(7);
        jtfstrCName.setEditable(false);
        number6Panel.add(jtfstrCName);
        outerPanel.add(number6Panel);

        JPanel number7Panel = new JPanel();
        number7Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Total Invenory Value: $" );//Total Inventory Value
        number7Panel.add(jl);
        jtfinvTotal = new JTextField(7);
        jtfinvTotal.setEditable(false);
        number7Panel.add(jtfinvTotal);
        outerPanel.add(number7Panel);

//******************************************
//Button Area:
        JPanel jpButtonF = new JPanel();
        JButton jbFirst = new JButton("First");
        jbFirst.addActionListener(new FirstButtonHandler());
        jpButtonF.add(jbFirst);
        outerPanel.add(jpButtonF);


        JPanel jpButtonN = new JPanel();
        JButton jbNext = new JButton("Next");
        jbNext.addActionListener(new NextButtonHandler());
        jpButtonN.add(jbNext);
        outerPanel.add(jpButtonN);


        JPanel jpButtonP = new JPanel();
        JButton jbPrevious = new JButton("Previous");
        jbPrevious.addActionListener(new PreviousButtonHandler());
        jpButtonP.add(jbPrevious);
        outerPanel.add(jpButtonP);

        JPanel jpButtonL = new JPanel();
        JButton jbLast = new JButton("Last");
        jbLast.addActionListener(new LastButtonHandler());
        jpButtonL.add(jbLast);
        outerPanel.add(jpButtonL);

        JPanel jpButtonS = new JPanel();
        JButton jbSave = new JButton("Save");
        jbSave.addActionListener(new LastButtonHandler());
        jpButtonS.add(jbSave);
        outerPanel.add(jpButtonS);

        JPanel jpButtonD = new JPanel();
        JButton jbDelete = new JButton("Delete");
        jbDelete.addActionListener(new LastButtonHandler());
        jpButtonD.add(jbDelete);
        outerPanel.add(jpButtonD);

        JPanel jpButtonA = new JPanel();
        JButton jbAdd = new JButton("Add");
        jbAdd.addActionListener(new LastButtonHandler());
        jpButtonA.add(jbAdd);
        outerPanel.add(jpButtonA);

        JPanel jpButtonM = new JPanel();
        JButton jbModify = new JButton("Modify");
        jbModify.addActionListener(new LastButtonHandler());
        jpButtonM.add(jbModify);
        outerPanel.add(jpButtonM);

        JPanel jpButtonSch = new JPanel();
        JButton jbSearch = new JButton("Search");
        jbSearch.addActionListener(new SearchButtonHandler());
        jpButtonSch.add(jbSearch);
        outerPanel.add(jpButtonSch);



//*******************************************

    //Call update Fields
    updateNButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(300, 75, 550, 650);

        setContentPane(outerPanel);
        setResizable(false);
        setVisible(true);



      }//end GUI


        public void updateNButton( NameRestock[ ] inventory, int index )
    {
        totValue += inventory[ index ].getRestock();

    }

        public void updatePButton( NameRestock[ ] inventory, int index )
    {
//        totValue -= inventory[currentProdno - 1].getRestock();

        if (currentProdno <= -1)
        {
            
            currentProdno = (inventory.length-1);
            totValue = inventory[currentProdno].getRestock();
            //--currentProdno;
            //totValue = inventory[currentProdno].getRestock();

        }
        else
        {
            //--currentProdno;
            totValue = inventory[currentProdno].getRestock();

        }


    }


        public void updateLButton( NameRestock[ ] inventory, int index)
    {
        //currentProdno = (inventory.length-1);
        for(i = 0;i <= (inventory.length-1);i++)
        {
            totValue += inventory[ i ].getRestock();
        }

    }



    //updateFields NEED 2 PARAMENTER THE OBJECT AND THE INDEX
    //TO SPECIFY THE ARRAY ELEMENT

        public void updateFields( NameRestock[ ] inventory, int index )
    {


        jtfprdItem.setText( "" + inventory[ index ].getnumItem() );//Number
        jtfprdName.setText( "" + inventory[ index ].getstrName() );//Name
        jtfprdUnit.setText( "" + inventory[ index ].getnumUnit() );//Units
        jtfprdPrice.setText( "" + inventory[ index ].getnumPrice() );//Price
        jtfgetResult.setText( "" + String.format("%.2f",inventory[ index ].getResult()));//Total
        jtfReStock.setText( "" + String.format("%.2f",inventory[ index ].getRestock()) );//Restocking Fee
        jtfstrCName.setText( "" + inventory[ index ].getstrCName() );//Company
        //jtfinvTotal.setText( "" + inventory[ index ].gettotValue() );//Total Value
        jtfinvTotal.setText( "" + String.format("%.2f",totValue ));//Total Value

    } // end updateFields()

//**********************************************************
//Next Button
    class NextButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
        if (currentProdno > inventory.length-2)
        {
            currentProdno = -1;
            totValue = 0;
            ++currentProdno;
            updateNButton( inventory, currentProdno );            

        }
        else
        {
            ++currentProdno;
            updateNButton( inventory, currentProdno );            

        }
            
        updateFields( inventory, currentProdno);

        }
    }//end Next Button

//**********************************************************
//First Button

    class FirstButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
            totValue = 0;
            currentProdno = 0;
        updateNButton( inventory, currentProdno );
            updateFields( inventory, currentProdno );
        }
    } //end First Button

//**********************************************************
//Previous Button

    class PreviousButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {



        if (currentProdno == 0)
        {
            totValue = 0;
            updateLButton( inventory, currentProdno );
            currentProdno = inventory.length - 1;
            //totValue = inventory[currentProdno].getRestock();
        }
        else
        {
            --currentProdno;
            totValue -= inventory[currentProdno + 1].getRestock();

        }
//        updatePButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );

        }
    } //end Previous Button


//**********************************************************
//Last Button

    class LastButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
            
        totValue = 0;
        currentProdno = (inventory.length-1);
        updateLButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );
        }
    } //end Last Button

//***********************************************************
[color=#FF0000]//Search Button

    class SearchButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
        String s = JOptionPane.showInputDialog( null, " Enter Product Name ",null, 1 );
             s = inventory.Search(s);

                   }
    } //end Last Button[/color]
//***********************************************************




//public void openFile()
//{
//    try
//    {
//        output = new Formatter ("clients.txt");
//    }
//    catch (SecurityException securityException)
//    {
//        System.err.println("You do not have write access to this file.");
//        System.exit(1);
//    }
//    catch ( FileNotFoundException filesNotFoundException)
//    {
//        System.err.println("Error creating file.");
//        System.exit(1);
//    }//end catch
//}//end method open file


} // end GUI class



User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: GUI JAVA Search Handler
18 Mar, 2008 - 08:15 PM
Post #2

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
I'm guessing that the error should be here :

s = inventory.Search(s);

If you have implemented the Search(); method in the Inventory class, could you please post the code?
User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI JAVA Search Handler
19 Mar, 2008 - 03:15 AM
Post #3

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

QUOTE(letthecolorsrumble @ 18 Mar, 2008 - 09:15 PM) *

I'm guessing that the error should be here :

s = inventory.Search(s);

If you have implemented the Search(); method in the Inventory class, could you please post the code?


QUOTE

That is the part a cannot figure out. Is there somewhere I can look to see how to setup a search. I've been searching the web with no luck.

User is offlineProfile CardPM
+Quote Post

MFam
RE: GUI JAVA Search Handler
19 Mar, 2008 - 06:16 AM
Post #4

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 41

QUOTE(letthecolorsrumble @ 18 Mar, 2008 - 09:15 PM) *

I'm guessing that the error should be here :

s = inventory.Search(s);

If you have implemented the Search(); method in the Inventory class, could you please post the code?

QUOTE


I have been able to build a search text area and it loads after compiling. I believe I can build a for statement that will run through each of the array Names elements and if equals break or calls that informtion out. What I should have probably asked is; I have a program that inside the "InventoryPart1.java" has an array. In that array I have 4 elements with information, hard coded. To build this search, I need to count this information plus the "added" inventory data when I create the "add button". Will I need to build an open array somehow and pull the existing array data into it before I can build an "add" and a "search"? Also, am I heading in the correct direction regarding the build of the search? If correct, can I get assistance on how I go about pulling out of the initial array into a new open array?





CODE

import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;


class GUI extends JFrame {
// declare instance variables
// THIS IS THE VALUE THAT WILL RUN IN THE INVENTORY[ INDEX ]
//WHEN THE NEXT BUTTON IS CLICKED
    private int currentProdno = 0;

    // INVENTORY WILL GET THE VALUE PASSED IN THE CONSTRUCTOR PARAMETER
    private NameRestock[ ] inventory;

    private JTextField jtfprdItem; //1
    private JTextField jtfprdName; //2
    private JTextField jtfprdUnit; //3
    private JTextField jtfprdPrice;//4
    private JTextField jtfgetResult;//5   getresult()
    private JTextField jtfReStock; //6   getrestock()
    private JTextField jtfstrCName;//7
    private JTextField jtfinvTotal;//8
    private double totValue;
    private int i = 0;
    private JButton btnFirst;
    private JButton btnNext;
    private JButton btnPrevious;
    private JButton btnLast;
//**************************
    private JButton btnSave;
    private JButton btnAdd;
    private JButton btnDelete;
    private JButton btnModify;
    private JButton btnSearch;
//**************************
    private double tmp;
    //private Formatter output;


    GUI( NameRestock[ ] inv ) {
        super("Inventory Part 4 Program");
        inventory = inv; // ASSIGN inv FROM TO inventor

        JPanel jp;
        JLabel jl;
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Inventory Part 4");
        titlePanel.add(jl);
    ImageIcon ig = new ImageIcon("CpyLogo.jpg");
        //outerPanel.add(titlePanel);
    outerPanel.add(new JLabel(ig));

//******************************************
        JPanel numberPanel = new JPanel();
        numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Number: " );//Count of each item
        numberPanel.add(jl);
        jtfprdItem = new JTextField (3);
        jtfprdItem.setEditable(false);
        numberPanel.add(jtfprdItem);
        outerPanel.add(numberPanel);

        JPanel number1Panel = new JPanel();
        number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Name: " );//Name of item
        number1Panel.add(jl);
        jtfprdName = new JTextField (12);
        jtfprdName.setEditable(false);
        number1Panel.add(jtfprdName);
        outerPanel.add(number1Panel);

        JPanel number2Panel = new JPanel();
        number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Units: " );// Number of each item
        number2Panel.add(jl);
        jtfprdUnit = new JTextField(3);
        jtfprdUnit.setEditable(false);
        number2Panel.add(jtfprdUnit);
        outerPanel.add(number2Panel);

        JPanel number3Panel = new JPanel();
        number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Price: $ " );
        number3Panel.add(jl);
        jtfprdPrice = new JTextField(4);
        jtfprdPrice.setEditable(false);
        number3Panel.add(jtfprdPrice);
        outerPanel.add(number3Panel);

        JPanel number4Panel = new JPanel();
        number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Total: $ " );//Total Price of Items
        number4Panel.add(jl);
        jtfgetResult = new JTextField(5);
        jtfgetResult.setEditable(false);
        number4Panel.add(jtfgetResult);
        outerPanel.add(number4Panel);

        JPanel number5Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );//Restocking FEE
        number5Panel.add(jl);
        jtfReStock = new JTextField(6);
        jtfReStock.setEditable(false);
        number5Panel.add(jtfReStock);
        outerPanel.add(number5Panel);

        JPanel number6Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Company Name: " );//Company Name
        number6Panel.add(jl);
        jtfstrCName = new JTextField(7);
        jtfstrCName.setEditable(false);
        number6Panel.add(jtfstrCName);
        outerPanel.add(number6Panel);

        JPanel number7Panel = new JPanel();
        number7Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Total Invenory Value: $" );//Total Inventory Value
        number7Panel.add(jl);
        jtfinvTotal = new JTextField(7);
        jtfinvTotal.setEditable(false);
        number7Panel.add(jtfinvTotal);
        outerPanel.add(number7Panel);

//******************************************
//Button Area:
        JPanel jpButtonF = new JPanel();
        JButton jbFirst = new JButton("First");
        jbFirst.addActionListener(new FirstButtonHandler());
        jpButtonF.add(jbFirst);
        outerPanel.add(jpButtonF);


        JPanel jpButtonN = new JPanel();
        JButton jbNext = new JButton("Next");
        jbNext.addActionListener(new NextButtonHandler());
        jpButtonN.add(jbNext);
        outerPanel.add(jpButtonN);


        JPanel jpButtonP = new JPanel();
        JButton jbPrevious = new JButton("Previous");
        jbPrevious.addActionListener(new PreviousButtonHandler());
        jpButtonP.add(jbPrevious);
        outerPanel.add(jpButtonP);

        JPanel jpButtonL = new JPanel();
        JButton jbLast = new JButton("Last");
        jbLast.addActionListener(new LastButtonHandler());
        jpButtonL.add(jbLast);
        outerPanel.add(jpButtonL);

        JPanel jpButtonS = new JPanel();
        JButton jbSave = new JButton("Save");
        jbSave.addActionListener(new LastButtonHandler());
        jpButtonS.add(jbSave);
        outerPanel.add(jpButtonS);

        JPanel jpButtonD = new JPanel();
        JButton jbDelete = new JButton("Delete");
        jbDelete.addActionListener(new LastButtonHandler());
        jpButtonD.add(jbDelete);
        outerPanel.add(jpButtonD);

        JPanel jpButtonA = new JPanel();
        JButton jbAdd = new JButton("Add");
        jbAdd.addActionListener(new LastButtonHandler());
        jpButtonA.add(jbAdd);
        outerPanel.add(jpButtonA);

        JPanel jpButtonM = new JPanel();
        JButton jbModify = new JButton("Modify");
        jbModify.addActionListener(new LastButtonHandler());
        jpButtonM.add(jbModify);
        outerPanel.add(jpButtonM);

        JPanel jpButtonSch = new JPanel();
        JButton jbSearch = new JButton("Search");
        jbSearch.addActionListener(new SearchButtonHandler());
        jpButtonSch.add(jbSearch);
        outerPanel.add(jpButtonSch);



//*******************************************

    //Call update Fields
    updateNButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(300, 75, 550, 650);

        setContentPane(outerPanel);
        setResizable(false);
        setVisible(true);



      }//end GUI


        public void updateNButton( NameRestock[ ] inventory, int index )
    {
        totValue += inventory[ index ].getRestock();

    }

        public void updatePButton( NameRestock[ ] inventory, int index )
    {
//        totValue -= inventory[currentProdno - 1].getRestock();

        if (currentProdno <= -1)
        {
            
            currentProdno = (inventory.length-1);
            totValue = inventory[currentProdno].getRestock();
            //--currentProdno;
            //totValue = inventory[currentProdno].getRestock();

        }
        else
        {
            //--currentProdno;
            totValue = inventory[currentProdno].getRestock();

        }


    }


        public void updateLButton( NameRestock[ ] inventory, int index)
    {
        //currentProdno = (inventory.length-1);
        for(i = 0;i <= (inventory.length-1);i++)
        {
            totValue += inventory[ i ].getRestock();
        }

    }



    //updateFields NEED 2 PARAMENTER THE OBJECT AND THE INDEX
    //TO SPECIFY THE ARRAY ELEMENT

        public void updateFields( NameRestock[ ] inventory, int index )
    {


        jtfprdItem.setText( "" + inventory[ index ].getnumItem() );//Number
        jtfprdName.setText( "" + inventory[ index ].getstrName() );//Name
        jtfprdUnit.setText( "" + inventory[ index ].getnumUnit() );//Units
        jtfprdPrice.setText( "" + inventory[ index ].getnumPrice() );//Price
        jtfgetResult.setText( "" + String.format("%.2f",inventory[ index ].getResult()));//Total
        jtfReStock.setText( "" + String.format("%.2f",inventory[ index ].getRestock()) );//Restocking Fee
        jtfstrCName.setText( "" + inventory[ index ].getstrCName() );//Company
        //jtfinvTotal.setText( "" + inventory[ index ].gettotValue() );//Total Value
        jtfinvTotal.setText( "" + String.format("%.2f",totValue ));//Total Value

    } // end updateFields()

//**********************************************************
//Next Button
    class NextButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
        if (currentProdno > inventory.length-2)
        {
            currentProdno = -1;
            totValue = 0;
            ++currentProdno;
            updateNButton( inventory, currentProdno );            

        }
        else
        {
            ++currentProdno;
            updateNButton( inventory, currentProdno );            

        }
            
        updateFields( inventory, currentProdno);

        }
    }//end Next Button

//**********************************************************
//First Button

    class FirstButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
            totValue = 0;
            currentProdno = 0;
        updateNButton( inventory, currentProdno );
            updateFields( inventory, currentProdno );
        }
    } //end First Button

//**********************************************************
//Previous Button

    class PreviousButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {



        if (currentProdno == 0)
        {
            totValue = 0;
            updateLButton( inventory, currentProdno );
            currentProdno = inventory.length - 1;
            //totValue = inventory[currentProdno].getRestock();
        }
        else
        {
            --currentProdno;
            totValue -= inventory[currentProdno + 1].getRestock();

        }
//        updatePButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );

        }
    } //end Previous Button


//**********************************************************
//Last Button

    class LastButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
            
        totValue = 0;
        currentProdno = (inventory.length-1);
        updateLButton( inventory, currentProdno );
        updateFields( inventory, currentProdno );
        }
    } //end Last Button

//***********************************************************
//Search Button

    class SearchButtonHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
    {
        String productName = JOptionPane.showInputDialog("Enter product name");
        

        }
    } //end Last Button

//***********************************************************

} // end GUI class


User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: GUI JAVA Search Handler
19 Mar, 2008 - 06:58 AM
Post #5

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
Your logic to search for the name in the array seems to be correct.

For getting your 'hard coded' products into the inventory of the 'open' array, you may want to use cloning of the objects, and storing them into the array, after increasing the size of the array.

This link might help you get the overview of Cloning object in Java.

http://java.sun.com/developer/JDCTechTips/2001/tt0306.html

Hope that helps :)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month