Results 1 to 9 of 9
  1. #1
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default makeButton method not working

    Can someone please tell me what is wrong with my makeDataItems and makeButton methods in my RunInv class? I am getting the following errors. I have attached my code below as well.

    InventoryProgramPart5.java:277: cannot find symbol
    symbol : method makeTheDataItems()
    location: class RunInv
    makeTheDataItems();
    ^
    InventoryProgramPart5.java:301: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton first = makeButton( "First" );
    ^
    InventoryProgramPart5.java:302: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton next = makeButton( "Next" );
    ^
    InventoryProgramPart5.java:303: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton previous = makeButton( "Previous" );
    ^
    InventoryProgramPart5.java:304: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton last = makeButton( "Last" );
    ^
    InventoryProgramPart5.java:305: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton exit = makeButton( "Exit" );
    ^
    InventoryProgramPart5.java:308: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton add = makeButton( "Add" );
    ^
    InventoryProgramPart5.java:309: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton delete = makeButton( "Delete" );
    ^
    InventoryProgramPart5.java:310: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton modify = makeButton( "Modify" );
    ^
    InventoryProgramPart5.java:311: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton save = makeButton( "Save" );
    ^
    InventoryProgramPart5.java:312: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton find = makeButton( "Find" );
    ^
    11 errors

    Java Code:
    // CheckPoint:  InventoryProgramPart5.java
    // Week 8
    // This program calculates inventory value
    
    import java.util.Arrays;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class InventoryProgramPart5
    {
         public static void main( String args[] )
         {
              double restockingFee = 0.05;
              manufacturer[] inventory = new manufacturer[5]; // array of 5
    
              inventory[0] = new manufacturer
                   ( "notepads", restockingFee, "4000", "Ampad", 60, 2.75 );
              inventory[1] = new manufacturer
                   ( "pencils", restockingFee, "5000", "Bic", 75, 1.25 );
              inventory[2] = new manufacturer
                   ( "folders", restockingFee, "2000", "3M", 30, 4.75 );
              inventory[3] = new manufacturer
                   ( "envelopes", restockingFee, "1000", "Universal", 15, 5.25 );
              inventory[4] = new manufacturer
                   ( "markers", restockingFee, "3000", "Sanford", 45, 3.50 );
    
              manufacturer temp[] = new manufacturer[1];
          
                   for( int j = 0; j < inventory.length - 1; j++ )
                   {
                        for( int k = 0; k < inventory.length - 1; k++ )
                        {
                             if( inventory[k].getItemName().compareToIgnoreCase
                                  ( inventory[k+1].getItemName() ) > 0 )
                             {
                                  temp[0] = inventory[k];
                                  inventory[k] = inventory[k+1];
                                  inventory[k+1] = temp[0];
                             } // end if
                        } // end for    
                   } // end for
    
                   javax.swing.JTextArea ta = new javax.swing.JTextArea( 10, 25 );
                   for( int j = 0; j < inventory.length; j++ )
                   {
    
                   // System.out.println( inventory[j].toString() );<-----------------
    
                        ta.append( inventory[j].toString()+"\n" );
                   } // end for
    
              // System.out.printf( "Total value of all inventory = $%.2f",
              // Inventory.etTotalValueOfAllInventory( inventory ) );
              // return; // <------------------above line and this line
              ta.append("Total value of all inventory = "+product.getTotalValueOfAllInventory(inventory));
              javax.swing.JFrame frame = new javax.swing.JFrame();
              frame.getContentPane().add( new javax.swing.JScrollPane(ta) );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
              frame.setVisible( true );
    
         } // end main
    
    } // end class InventoryProgramPart5
    
    // The product class
    class product
    {
         String productNumber;
         String name;
         int numberOfUnits;
         double pricePerUnit;
    
         // create a new instance of Inventory
         // main constructor for the class
         product( String Item_Number, String Item_Name, int Items_in_Stock, double Item_Price )
         {
              productNumber = Item_Number;
              name = Item_Name;
              numberOfUnits = Items_in_Stock;
              pricePerUnit = Item_Price;
         } // end constructor
    
         // sets the product name
         public void setItemName( String Item_Name )
         {
              name = Item_Name;
         }
    
         // sets the product number
         public void setItemNumber( String Item_Number )
         {
              productNumber = Item_Number;
         }
    
         // sets the number of units in stock
         public void setItemsInStock( int Items_in_Stock )
         {
              numberOfUnits = Items_in_Stock;
         }
    
         // sets the price of the product
         public void setItemPrice( double Item_Price )
         {
              pricePerUnit = Item_Price;
         }
    
         // returns product name
         public String getItemName()
         {
              return name;
         }
    
         // returns product number
         public String getItemNumber()
         {
              return productNumber;
         }
    
         // returns units in stock
         public int getItemsInStock()
         {
              return numberOfUnits;
         }
    
         // returns product price
         public double getItemPrice()
         {
              return pricePerUnit;
         }
    
         // returns the total value of inventory
         public double getInventoryValue()
         {
              return pricePerUnit * numberOfUnits;
         }
    
         public static double getTotalValueOfAllInventory( product[] inv )
         {
              double tot = 0.0;
              for( int i = 0; i < inv.length; i++ )
              {
                   tot += inv[i].getInventoryValue();
              }
              return tot;
         }
    
         public String toString()
         {
              StringBuffer sb = new StringBuffer();
              sb.append( "Product Name:  \t" ).append( name ).append( "\n" );
              sb.append( "Product Number:  \t" ).append( productNumber ).append( "\n" );
              sb.append( "Units in Stock:       \t" ).append( numberOfUnits ).append( "\n" );
              sb.append( "Unit Price:            \t" ).append( String.format( "$%.2f%n", pricePerUnit ) );
              sb.append( "Inventory Value:  \t" ).append(String.format("$%.2f%n", this.getInventoryValue())); 
                   return sb.toString();
         } // end toString
    } // end class product
    
    class manufacturer extends product
    { 
         // manufacturer of product
         String manufacturer;
    
         // percentage added to base price as restocking fee
         double restockingFee;
    
         // actual inventory value will be the base inventory value plus
         // the base inventory value times this amount ( value + ( value * restockingFee ) )
         public manufacturer( String Item_Name, double restockingFee, String Item_Number,
              String manufacturer, int Items_in_Stock, double Item_Price )
    
         {
              super( Item_Number, Item_Name, Items_in_Stock, Item_Price);
                   this.manufacturer = manufacturer;               this.restockingFee = restockingFee;
         } 
    
         // returns inventory value plus the restocking fee
         public double getInventoryValue()
         {
              return super.getInventoryValue() + ( super.getInventoryValue() * restockingFee );
         } // end getInventoryValue
    
         public String toString()
         {
              StringBuffer sb = new StringBuffer( "Manufacturer:       \t" ).append( manufacturer ).append( "\n" );
              sb.append( super.toString() );
                   return sb.toString();
    
         } // end toString
    
    } // end class manufacturer
    
    class RunInv extends JFrame // implements ActionListener
    {
         // make the data items
         String makeTheDataItems;     
    
         // make button
         String makeButton;
    
         // sets the make the data items
         public void setMakeTheDataItems( String makeTheDataItems )
         {
              this.makeTheDataItems = makeTheDataItems;
         }
        
         // sets the make button
         public void setMakeButton( String button )
         {
              this.makeButton = makeButton;
         }
    
         // returns the make the data items
         public String getMakeTheDataItems()
         {
              return makeTheDataItems;
         }
    
         // returns the make button
         public String getMakeButton()
         {
              return makeButton;
         }
         
         // utility class for displaying the picture
         private class MyPanel extends JPanel
         {
              ImageIcon image = new ImageIcon( "HTML.jpg" );
              int width = image.getIconWidth();
              int height = image.getIconHeight();
              long angle = 0;
              public MyPanel()
              {
                   super();
              }
    
              public void paintComponent( Graphics g )
              {
                   super.paintComponent(g);
                   Graphics2D g2d = ( Graphics2D )g;
                   g2d.rotate( Math.toRadians(angle), 200+width/2, 90+height/2 );
                   g2d.drawImage( image.getImage(), 5, 5, this );
                   g2d.dispose();
              }
    
         } // end class MyPanel
    
         int currentIndex; // currently displayed Item
         manufacturer[] inventory = new manufacturer[5];
         JLabel name;
         JLabel number;
         JLabel manufacturer;
         JLabel units;
         JLabel price;
         JLabel fee;
         JLabel totalValue;
         JTextField nameField = new JTextField(20);
         JTextField numberField = new JTextField(20);
         JTextField manufacturerField = new JTextField(20);
         JTextField unitsField = new JTextField(20);
         JTextField priceField = new JTextField(20);
         JTextField totalValueField = new JTextField(20);
         JPanel display;
         JPanel displayHolder;
         JPanel panel;
         
         // constructor
         public RunInv( String makeTheDataItems, String makeButtons )
         {
              this.makeTheDataItems = makeTheDataItems;
              this.makeButton = makeButton;
    
              makeTheDataItems();
              setSize( 700, 300 );
              setTitle( "Inventory Program" );
    
              // make the panels
              display = new JPanel();
              JPanel other = new JPanel();
              JPanel picture = new MyPanel();
              JPanel buttons = new JPanel();
              JPanel centerPanel = new JPanel();
              displayHolder = new JPanel();
              display.setLayout( new GridLayout( 3, 3 ) );
              other.setLayout( new GridLayout( 2, 1 ) );
    
              // make the labels
              name = new JLabel( "Product Name:" );
              number = new JLabel( "Product Number:" );
              manufacturer = new JLabel( "Manufacturer:" );
              units = new JLabel( "Units in Stock:" );
              price = new JLabel( "Price     :$" );
              fee = new JLabel( "Fee     :$" );
              totalValue = new JLabel( "Total value : $" );
    
              // make the buttons
              JButton first = makeButton( "First" );
              JButton next = makeButton( "Next" );
              JButton previous = makeButton( "Previous" );
              JButton last = makeButton( "Last" );
              JButton exit = makeButton( "Exit" );
    
              // other buttons
              JButton add = makeButton( "Add" );
              JButton delete = makeButton( "Delete" );
              JButton modify = makeButton( "Modify" );
              JButton save = makeButton( "Save" );
              JButton find = makeButton( "Find" );
                   
                   // add the labels to the display panel
                   display.add( name );
                   display.add( number );
                   display.add( manufacturer );
                   display.add( units );
                   display.add( price );
                   display.add( fee );
                   display.add( totalValue );
    
                   // add the buttons to the buttonPanel
                   buttons.add( first );
                   buttons.add( previous );
                   buttons.add( next );
                   buttons.add( last );
                   buttons.add( exit );
    
                   // add the picture panel and display to the centerPanel
                   displayHolder.add( display );
                   centerPanel.setLayout( new GridLayout( 2, 1 ) );
                   centerPanel.add( picture );
                   centerPanel.add( displayHolder );
                   other.add( buttons );
                   JPanel forAdd = new JPanel(); // add the other buttons to this panel
                   forAdd.add( find );
                   forAdd.add( add );
                   forAdd.add( modify );
                   forAdd.add( delete );
                   forAdd.add( save );
                   other.add( forAdd );
    
                   // add the panels to the frame
                   getContentPane().add( centerPanel, "Center" );
                   getContentPane().add( other, "South" );
                   this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                   setVisible( true );
         
         } // end RunInv
         
    } // end class RunInv extends JFrame implements ActionListener

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Where is the makeButton method defined? I don't see it in your code! It's been used but not defined.
    I see NO reference to a makeDataItems method.
    Do you know how to write the code for a method?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Java is like math in that you have to fully understand the basic concepts before moving on to more advanced concepts. Perhaps you should consider dropping this class, take an incomplete, and try again at a local college where you have a better chance of getting one-on-one tutoring. Online college programming courses are not for everyone. I know that they're not for me.
    Last edited by Fubarable; 08-10-2008 at 08:27 PM.

  4. #4
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Norm

    Norm,

    Is this the appropriate way to define a method? This is how the textbook shows how to do it.

    Java Code:
        // constructor
         public RunInv( String makeTheDataItems, String makeButtons )
         {
              makeTheDataItems = makeTheDataItems;
              makeButton = makeButton;
         } // end constructor
    
         // sets the makeTheDataItems
         public void setMakeTheDataItems( String makeTheDataItems )
         {
              makeTheDataItems = makeTheDataItems;
         }
        
         // sets the makeButton
         public void setMakeButton( String makeButton )
         {
              makeButton = makeButton;
         }
    
         // returns the makeTheDataItems
         public String getMakeTheDataItems()
         {
              return makeTheDataItems;
         }
    
         // returns the make button
         public String getMakeButton()
         {
              return makeButton;
         }

  5. #5
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default

    Fubarable,

    Despite what you think Fubarable, I am getting an A in this class and have this assignment and one more to go before this class is done. I do not appreciate you telling me I should drop this class and get an incomplete. I am not a quitter. I joined this forum because my teacher is really hard to get a hold of. Therefore, I try to use this forum to answer some of my questions. If you would have taken the time to really look at my code, you would have realized that the majority of the code is written well except for the problem I am having with the GUI portion. If you do not know how to constructively help me, I appreciate you keeping your opinions to yourself. I felt that I had to send you this special note since you seem to find this forum as a place to criticize students versus help them. No one is more dedicated to learning than I am. I have read everything I can get my hands on related to this subject. Perhaps it would be helpful if you can provide me good sources of information versus undermind my intelligence.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Thumbs up

    Haven't given up on you yet, but am not sure you know how to write a constructor or a method. I suggested that you write a simple class to demonstrate that you know how:
    Try writing a small simple program to use these two techniques:
    The Constructor to the class will take one int as arg.
    It will have one method that has an int as arg, adds that int to the one passed in the constructor and returns the sum.
    The main method will create an instance of that class passing an int value in its constructor and then will call the method with another int and print the results returned by the method.
    I think if you do the above, it will help you understand how to solve your problem.

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    your makeButton method should be:

    Java Code:
    public JButton makeButton(String button){
    
          return new JButton(button);
    }
    But i don't understand, why do you need the method for creating the Swing Buttons?Weird,but you have the simple native constructor for creating JButton.
    Last edited by serjant; 08-10-2008 at 09:01 PM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    serjant:
    Think about it. Will the buttons have listeners or Actions?

  9. #9
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Norm,have you read my post up to the end?So that's what i meant,why not to create the buttons in a simple way:

    Java Code:
    JButton m=new JButton("Save");
    m.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent event){
                //do smth
           }
      }

    but in the jilk8590 way with makeButton(String button) method,you can also add action listener,make implemetation of ActionListenr to the class,
    in some method create button with makeButton method:
    Java Code:
    JButton m=makeButton("Save");
    m.addActionListener(this);
    and declare the actionPerformed method:

    Java Code:
    public void actionPerforemd(ActionEvent e){
              if(e.getActionCommand().equals("Save")){
    			
    			//make smth after the button clicked
    			
    		}
    }
    I hope ,i was clear .
    Last edited by serjant; 08-10-2008 at 11:41 PM.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. makeButton errors
    By ljk8950 in forum AWT / Swing
    Replies: 12
    Last Post: 08-10-2008, 01:10 AM
  3. Replies: 8
    Last Post: 05-28-2008, 07:00 AM
  4. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •