Lab: File Processing

profilestevotbn2007
CIS355A_Nacham_iLab_Week4.zip

GUI/build/classes/.netbeans_automatic_build

GUI/build/classes/.netbeans_update_resources

GUI/build/classes/stocks4u/Stock.class

                package stocks4u;

                public 
                synchronized 
                class Stock {
    
                private String 
                company_name;
    
                private int 
                shares;
    
                private double 
                purchase_price;
    
                private double 
                current_price;
    
                public void Stock();
    
                public void Stock(String, int, double, double);
    
                public String 
                getCompany_name();
    
                public int 
                getShares();
    
                public double 
                getPurchase_price();
    
                public double 
                getCurrent_price();
    
                public void 
                setCompany_name(String);
    
                public void 
                setShares(int);
    
                public void 
                setPurchase_price(double);
    
                public void 
                setCurrent_price(double);
    
                public double 
                calc();
    
                public String 
                toString();
}

            

GUI/build/classes/stocks4u/Stocks4U$1.class

                package stocks4u;

                synchronized 
                class Stocks4U$1 
                implements javax.swing.event.ListSelectionListener {
    void Stocks4U$1(Stocks4U);
    
                public void 
                valueChanged(javax.swing.event.ListSelectionEvent);
}

            

GUI/build/classes/stocks4u/Stocks4U$2.class

                package stocks4u;

                synchronized 
                class Stocks4U$2 
                implements java.awt.event.ActionListener {
    void Stocks4U$2(Stocks4U);
    
                public void 
                actionPerformed(java.awt.event.ActionEvent);
}

            

GUI/build/classes/stocks4u/Stocks4U$3.class

                package stocks4u;

                synchronized 
                class Stocks4U$3 
                implements java.awt.event.ActionListener {
    void Stocks4U$3(Stocks4U);
    
                public void 
                actionPerformed(java.awt.event.ActionEvent);
}

            

GUI/build/classes/stocks4u/Stocks4U$4.class

                package stocks4u;

                final 
                synchronized 
                class Stocks4U$4 
                implements Runnable {
    void Stocks4U$4();
    
                public void 
                run();
}

            

GUI/build/classes/stocks4u/Stocks4U$5.class

                package stocks4u;

                final 
                synchronized 
                class Stocks4U$5 
                implements Runnable {
    void Stocks4U$5();
    
                public void 
                run();
}

            

GUI/build/classes/stocks4u/Stocks4U.class

                package stocks4u;

                public 
                final 
                synchronized 
                class Stocks4U 
                extends javax.swing.JFrame {
    Stock 
                stock1;
    javax.swing.DefaultListModel 
                listModel;
    java.util.ArrayList 
                stkNames;
    java.util.ArrayList 
                quantities;
    java.util.ArrayList 
                purchasePrice;
    java.util.ArrayList 
                currentPrice;
    int 
                i;
    double 
                p_price;
    double 
                c_price;
    int 
                qty;
    
                private javax.swing.JButton 
                btnAdd;
    
                private javax.swing.JButton 
                btnRemove;
    
                private javax.swing.JTextField 
                display;
    
                private javax.swing.JLabel 
                jLabel1;
    
                private javax.swing.JLabel 
                jLabel2;
    
                private javax.swing.JLabel 
                jLabel3;
    
                private javax.swing.JLabel 
                jLabel4;
    
                private javax.swing.JList 
                jList1;
    
                private javax.swing.JPanel 
                jPanel1;
    
                private javax.swing.JPanel 
                jPanel2;
    
                private javax.swing.JScrollPane 
                jScrollPane1;
    
                private javax.swing.JTabbedPane 
                jTabbedPane;
    
                private javax.swing.JTextField 
                jTxtFieldCPrice;
    
                private javax.swing.JTextField 
                jTxtFieldPPrice;
    
                private javax.swing.JTextField 
                jTxtFieldQuantity;
    
                private javax.swing.JTextField 
                jTxtFieldStockName;
    
                public void Stocks4U();
    
                public void 
                eventsHandler();
    
                public void 
                output();
    
                public void 
                addStock();
    
                public void 
                removeStock(int);
    
                private void 
                initComponents();
    
                public 
                static void 
                main(String[]);
}

            

GUI/build/classes/stocks4u/Stocks4U.form

GUI/build.xml

Builds, tests, and runs the project Stocks4U.

GUI/manifest.mf

Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build

GUI/nbproject/build-impl.xml

Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url

GUI/nbproject/genfiles.properties

build.xml.data.CRC32=67310880 build.xml.script.CRC32=855ccc4c [email protected] # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=67310880 nbproject/build-impl.xml.script.CRC32=2932a199 nbproject/[email protected]

GUI/nbproject/private/private.properties

compile.on.save=true user.properties.file=C:\\Users\\Dread Pirate Roberts\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

GUI/nbproject/private/private.xml

file:/D:/COURSEHERO/2017/java/Stocks4U/src/stocks4u/Stocks4U.java file:/D:/COURSEHERO/2017/java/Stocks4U/src/stocks4u/Stock.java

GUI/nbproject/project.properties

annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/Stocks4U.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=stocks4u.Stocks4U manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test

GUI/nbproject/project.xml

org.netbeans.modules.java.j2seproject Stocks4U

GUI/src/stocks4u/Stock.java

GUI/src/stocks4u/Stock.java

package  stocks4u ;

/**
 *
Program Name: Stock.java 
Programmer's Name: Steven Nacham
Program Description: Manages the stock activity

 */
public   class   Stock   {
    
     private   String  company_name ;
     private   int  shares ;
     private   double  purchase_price ;
     private   double  current_price ;

     //default constructor
     public   Stock ()   {
     }

     //parametized constructor
     public   Stock ( String  companyName ,   int  no_shares ,   double  purchasePrice ,   double  currentPrice )   {
         this . company_name  =  companyName ;
         this . shares  =  no_shares ;
         this . purchase_price  =  purchasePrice ;
         this . current_price  =  currentPrice ;
     }
    
     //getters

     public   String  getCompany_name ()   {
         return  company_name ;
     }

     public   int  getShares ()   {
         return  shares ;
     }

     public   double  getPurchase_price ()   {
         return  purchase_price ;
     }

     public   double  getCurrent_price ()   {
         return  current_price ;
     }
    
     //setters

     public   void  setCompany_name ( String  name )   {
         this . company_name  =  name ;
     }

     public   void  setShares ( int  no_shares )   {
         this . shares  =  no_shares ;
     }

     public   void  setPurchase_price ( double  p_price )   {
         this . purchase_price  =  p_price ;
     }

     public   void  setCurrent_price ( double  c_price )   {
         this . current_price  =  c_price ;
     }
    
     /*
    *method to calculate the profit or loss
    *return double
    */
     public   double  calc (){
         return  shares * ( current_price - purchase_price );
     }

    @ Override
     public   String  toString ()   {
         return   company_name ;
     }
    
    
}

GUI/src/stocks4u/Stocks4U.form

GUI/src/stocks4u/Stocks4U.java

GUI/src/stocks4u/Stocks4U.java

/*
*
Program Name: Stocks4U.java 
Programmer's Name: Steven Nacham 
Program Description: A GUI user interface. Manages stock for sample portfolio
*
 */
package  stocks4u ;

import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;
import  java . util . ArrayList ;
import  javax . swing . DefaultListModel ;
import  javax . swing . JOptionPane ;
import  javax . swing . ListSelectionModel ;
import  javax . swing . event . ListSelectionEvent ;
import  javax . swing . event . ListSelectionListener ;

/**
 *
 *  @author  Dread Pirate Roberts
 */
public   final   class   Stocks4U   extends  javax . swing . JFrame   {

     Stock  stock1  =   new   Stock ();
     DefaultListModel < String >  listModel  =   new   DefaultListModel <> ();

     ArrayList  stkNames  =   new   ArrayList ();
     ArrayList  quantities  =   new   ArrayList ();
     ArrayList  purchasePrice  =   new   ArrayList ();
     ArrayList  currentPrice  =   new   ArrayList ();

     int  i ;
     double  p_price ;
     double  c_price ;
     int  qty ;

     public   Stocks4U ()   {

        initComponents ();
        eventsHandler ();
     }

     /**
     * Method to handle all the UI events
     */
     public   void  eventsHandler ()   {
         /*when an item in the jlist is selected, update the jtextBox output*/
        jList1 . addListSelectionListener ( new   ListSelectionListener ()   {
            @ Override
             public   void  valueChanged ( ListSelectionEvent  e )   {
                 if   ( ! jList1 . isSelectionEmpty ())   {   //check if there is a selected item in th jlist
                    i  =  jList1 . getSelectedIndex ();

                    stock1 . setCurrent_price (( double )  currentPrice . get ( i ));
                    stock1 . setPurchase_price (( double )  purchasePrice . get ( i ));
                    stock1 . setShares (( int )  quantities . get ( i ));

                     double  result  =   Math . ceil ( stock1 . calc ());   //round off
                     if   ( result  >   0 )   {
                        display . setText ( "Profit of "   +  result );
                     }   else   {
                        display . setText ( "Loss of "   +  result );
                     }
                 }
             }
         });

         /*When the add stock button is clicked*/
        btnAdd . addActionListener ( new   ActionListener ()   {
            @ Override
             public   void  actionPerformed ( ActionEvent  e )   {

                 //call the add stock method
                addStock ();

                 //update the jList elements
                output ();
             }
         });

        btnRemove . addActionListener ( new   ActionListener ()   {
            @ Override
             public   void  actionPerformed ( ActionEvent  e )   {

                 //get the index of the removed jlist element
                i  =  jList1 . getSelectedIndex ();

                 //remove the elements from the stock
                removeStock ( i );

                 //update the jlist model
                output ();
             }
         });

     }

     /**
     *
     * Method handles displaying the elements in the various array-list to the
     * jList
     *
     *
     */
     public   void  output ()   {
         //remove all items currently in the listmodel
        listModel . removeAllElements ();
        jList1 . clearSelection ();   //unselect any selected element
        display . setText ( "" );   //Also clear the output (profit/loss) textfield

         Object []  object  =  stkNames . toArray ();   //convert the company names into an array

         /*to avoid runtime exceptions, the jlist should only be updated if there are elements in the list */
         if   ( object . length  >   0 )   {
             for   ( int  n  =   0 ;  n  <  object . length ;  n ++ )   {
                
                listModel . add ( n ,  object [ n ]. toString ());
             }

             //set  only one element can be selected at given time
            jList1 . setSelectionMode ( ListSelectionModel . SINGLE_SELECTION );

             //set the model of the jlist(currently empty)
            jList1 . setModel ( listModel );
         }
     }

     public   void  addStock ()   {
         //get the user input

         String  stockName  =  jTxtFieldStockName . getText ();
         /*check if stock name has been set.[ trim() method remove any trailling whitespaces ]*/
         if   ( stockName . isEmpty ()   ||  stockName . trim (). equals ( "" ))   {
             JOptionPane . showMessageDialog ( null ,   "Please provide the stock name" ,   "Error" ,   JOptionPane . ERROR_MESSAGE );
             return ;   //break the execution
         }

         /*use of try-catch method to catch errors such as if user enters non decimal value or if null*/
         try   {
            qty  =   Integer . parseInt ( jTxtFieldQuantity . getText ());
         }   catch   ( Exception  e )   {
             JOptionPane . showMessageDialog ( null ,   "Invalid Quantity set!" ,   "Error" ,   JOptionPane . ERROR_MESSAGE );
             return ;   //break execution
         }
         try   {
            p_price  =   Float . parseFloat ( jTxtFieldPPrice . getText ());
            c_price  =   Float . parseFloat ( jTxtFieldCPrice . getText ());
         }   catch   ( Exception  e )   {
             JOptionPane . showMessageDialog ( null ,   "Invalid price set! " ,   "Error" ,   JOptionPane . ERROR_MESSAGE );
             return ; //break the execution
         }
         //add the stock details inot respective arrays
        stkNames . add ( stockName );
        quantities . add ( qty );
        purchasePrice . add ( p_price );
        currentPrice . add ( c_price );

         /*notify the user the stock has been added & clear the inputs*/
         JOptionPane . showMessageDialog ( null ,   "New stock added successfully" ,   "Success" ,   JOptionPane . INFORMATION_MESSAGE );
        jTxtFieldCPrice . setText ( "" );
        jTxtFieldPPrice . setText ( "" );
        jTxtFieldQuantity . setText ( "" );
        jTxtFieldStockName . setText ( "" );

     }

     public   void  removeStock ( int  index )   {
        stkNames . remove ( index );
        quantities . remove ( index );
        purchasePrice . remove ( index );
        currentPrice . remove ( index );
     }

    @ SuppressWarnings ( "unchecked" )
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private   void  initComponents ()   {

        jTabbedPane  =   new  javax . swing . JTabbedPane ();
        jPanel1  =   new  javax . swing . JPanel ();
        jScrollPane1  =   new  javax . swing . JScrollPane ();
        jList1  =   new  javax . swing . JList <> ();
        display  =   new  javax . swing . JTextField ();
        btnRemove  =   new  javax . swing . JButton ();
        jPanel2  =   new  javax . swing . JPanel ();
        jLabel1  =   new  javax . swing . JLabel ();
        jLabel2  =   new  javax . swing . JLabel ();
        jLabel3  =   new  javax . swing . JLabel ();
        jLabel4  =   new  javax . swing . JLabel ();
        jTxtFieldStockName  =   new  javax . swing . JTextField ();
        jTxtFieldQuantity  =   new  javax . swing . JTextField ();
        jTxtFieldPPrice  =   new  javax . swing . JTextField ();
        jTxtFieldCPrice  =   new  javax . swing . JTextField ();
        btnAdd  =   new  javax . swing . JButton ();

        setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE );

        jPanel1 . setVerifyInputWhenFocusTarget ( false );

        jScrollPane1 . setViewportView ( jList1 );

        display . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   14 ));   // NOI18N
        display . setHorizontalAlignment ( javax . swing . JTextField . CENTER );

        btnRemove . setText ( "Remove stock" );

        javax . swing . GroupLayout  jPanel1Layout  =   new  javax . swing . GroupLayout ( jPanel1 );
        jPanel1 . setLayout ( jPanel1Layout );
        jPanel1Layout . setHorizontalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   520 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGap ( 60 ,   60 ,   60 )
                 . addComponent ( display ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   410 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addGap ( 200 ,   200 ,   200 )
                 . addComponent ( btnRemove ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   110 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
         );
        jPanel1Layout . setVerticalGroup (
            jPanel1Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel1Layout . createSequentialGroup ()
                 . addComponent ( jScrollPane1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   160 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 20 ,   20 ,   20 )
                 . addComponent ( display ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   60 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 43 ,   43 ,   43 )
                 . addComponent ( btnRemove ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   30 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
         );

        jTabbedPane . addTab ( "Show stocks" ,  jPanel1 );

        jLabel1 . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   13 ));   // NOI18N
        jLabel1 . setText ( "Stock name" );

        jLabel2 . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   13 ));   // NOI18N
        jLabel2 . setText ( "Quantity" );

        jLabel3 . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   13 ));   // NOI18N
        jLabel3 . setText ( "Purchase price" );

        jLabel4 . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   13 ));   // NOI18N
        jLabel4 . setText ( "Current price" );

        jTxtFieldStockName . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   14 ));   // NOI18N

        jTxtFieldQuantity . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   14 ));   // NOI18N

        jTxtFieldPPrice . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   14 ));   // NOI18N

        jTxtFieldCPrice . setFont ( new  java . awt . Font ( "Arial" ,   0 ,   14 ));   // NOI18N

        btnAdd . setText ( "Add stock" );

        javax . swing . GroupLayout  jPanel2Layout  =   new  javax . swing . GroupLayout ( jPanel2 );
        jPanel2 . setLayout ( jPanel2Layout );
        jPanel2Layout . setHorizontalGroup (
            jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 40 ,   40 ,   40 )
                 . addComponent ( jLabel1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   100 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 0 ,   0 ,   0 )
                 . addComponent ( jTxtFieldStockName ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   240 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 40 ,   40 ,   40 )
                 . addComponent ( jLabel2 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   100 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 0 ,   0 ,   0 )
                 . addComponent ( jTxtFieldQuantity ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   240 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 40 ,   40 ,   40 )
                 . addComponent ( jLabel3 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   100 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 0 ,   0 ,   0 )
                 . addComponent ( jTxtFieldPPrice ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   240 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 40 ,   40 ,   40 )
                 . addComponent ( jLabel4 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   100 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 0 ,   0 ,   0 )
                 . addComponent ( jTxtFieldCPrice ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   240 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 370 ,   370 ,   370 )
                 . addComponent ( btnAdd ))
         );
        jPanel2Layout . setVerticalGroup (
            jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( jPanel2Layout . createSequentialGroup ()
                 . addGap ( 50 ,   50 ,   50 )
                 . addGroup ( jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel1 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTxtFieldStockName ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addGap ( 30 ,   30 ,   30 )
                 . addGroup ( jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel2 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTxtFieldQuantity ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addGap ( 20 ,   20 ,   20 )
                 . addGroup ( jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel3 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTxtFieldPPrice ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addGap ( 20 ,   20 ,   20 )
                 . addGroup ( jPanel2Layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
                     . addComponent ( jLabel4 ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                     . addComponent ( jTxtFieldCPrice ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   40 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
                 . addGap ( 20 ,   20 ,   20 )
                 . addComponent ( btnAdd ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   30 ,  javax . swing . GroupLayout . PREFERRED_SIZE ))
         );

        jTabbedPane . addTab ( "Add stock" ,  jPanel2 );

        javax . swing . GroupLayout  layout  =   new  javax . swing . GroupLayout ( getContentPane ());
        getContentPane (). setLayout ( layout );
        layout . setHorizontalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addGroup ( layout . createSequentialGroup ()
                 . addComponent ( jTabbedPane ,  javax . swing . GroupLayout . PREFERRED_SIZE ,   542 ,  javax . swing . GroupLayout . PREFERRED_SIZE )
                 . addGap ( 0 ,   0 ,   Short . MAX_VALUE ))
         );
        layout . setVerticalGroup (
            layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING )
             . addComponent ( jTabbedPane ,  javax . swing . GroupLayout . DEFAULT_SIZE ,   395 ,   Short . MAX_VALUE )
         );

        pack ();
        setLocationRelativeTo ( null );
     } // </editor-fold>//GEN-END:initComponents

     /**
     *  @param  args the command line arguments
     */
     public   static   void  main ( String  args [])   {
         /* Set the Nimbus look and feel */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
         try   {
             for   ( javax . swing . UIManager . LookAndFeelInfo  info  :  javax . swing . UIManager . getInstalledLookAndFeels ())   {
                 if   ( "Nimbus" . equals ( info . getName ()))   {
                    javax . swing . UIManager . setLookAndFeel ( info . getClassName ());
                     break ;
                 }
             }
         }   catch   ( ClassNotFoundException  ex )   {
            java . util . logging . Logger . getLogger ( Stocks4U . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( InstantiationException  ex )   {
            java . util . logging . Logger . getLogger ( Stocks4U . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( IllegalAccessException  ex )   {
            java . util . logging . Logger . getLogger ( Stocks4U . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }   catch   ( javax . swing . UnsupportedLookAndFeelException  ex )   {
            java . util . logging . Logger . getLogger ( Stocks4U . class . getName ()). log ( java . util . logging . Level . SEVERE ,   null ,  ex );
         }
         //</editor-fold>

         /* Create and display the form */
        java . awt . EventQueue . invokeLater ( new   Runnable ()   {
             public   void  run ()   {
                 new   Stocks4U (). setVisible ( true );
             }
         });
     }

     // Variables declaration - do not modify//GEN-BEGIN:variables
     private  javax . swing . JButton  btnAdd ;
     private  javax . swing . JButton  btnRemove ;
     private  javax . swing . JTextField  display ;
     private  javax . swing . JLabel  jLabel1 ;
     private  javax . swing . JLabel  jLabel2 ;
     private  javax . swing . JLabel  jLabel3 ;
     private  javax . swing . JLabel  jLabel4 ;
     private  javax . swing . JList < String >  jList1 ;
     private  javax . swing . JPanel  jPanel1 ;
     private  javax . swing . JPanel  jPanel2 ;
     private  javax . swing . JScrollPane  jScrollPane1 ;
     private  javax . swing . JTabbedPane  jTabbedPane ;
     private  javax . swing . JTextField  jTxtFieldCPrice ;
     private  javax . swing . JTextField  jTxtFieldPPrice ;
     private  javax . swing . JTextField  jTxtFieldQuantity ;
     private  javax . swing . JTextField  jTxtFieldStockName ;
     // End of variables declaration//GEN-END:variables
}

CIS355A_Lab_Report_Template_Week4_Nacham.docx

CIS355A Lab Report

Your Name: Steven Nacham

Date: 3/25/2018

Lab Week 4

Objective/Purpose of the program

· Create a GUI that uses JList and JTabbedPanes.

· Process multiple objects in an ArrayList.

· Code event handlers for multiple events.

Stocks4U needs to develop an app for you to manage your stock purchases. They need to be able to store a list of stock purchases, view the individual stocks, add and remove stocks.

Analysis/Design

Describe the approach/structure of program. What classes/functions were used?

The GUI has two tabs using JTabbedPane.

· One tab (“Show stocks”) has

· a JList to display all the stock purchases;

· a text field or label to display information about a particular stock; and

· a JButton to remove a stock.

· One tab (“Add stock”) has textboxes, labels, and a button to input a stock.

A Stock class to manage the stock activity. It has private instance variables of

· company name;

· number of shares;

· purchase price; and

· current price.

Testing/Results

Does your program satisfy all requirements of the lab?

Yes, my program satisfies all requirements of the lab.

Conclusions / Lessons Learned

It was difficult dealing with a JList all together. I’d rather use a ComboBox.

CIS355A Lab Report Page 1