I am getting errors in my action listener brackets that I do not get, can someone help me please?? My buttons are not working, not sure what's happening. plus when I try to write

newGUI();

I get another errors saying it cannot find the symbol, but my method is there, I went ahead and deleted them, please help!

package fittingsinventory;

//Import Java library classes for program use
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.math.*;
//End Imports

//As you can see below, I have used comments to help me locate my different classes

//////////////////////////class Main///////////////////////////////////////////

//
public class Main
{


    public static void main(String[] args)
    {
       MetalFittings mymetal = null;
       Inventory myinv = new Inventory();

        //Assign values to variables in array
        mymetal = new MetalFittings("RG-06",10,34,25.66, "Anodized Titanium");
        myinv.growMetalFittings (mymetal);

        mymetal = new MetalFittings("RG-59",20,28,18.33, "Aluminum");
        myinv.growMetalFittings (mymetal);

        mymetal = new MetalFittings("RG-11",30,56,32.21, "Brass");
        myinv.growMetalFittings (mymetal);

        new MyGUI (myinv);

    }//End main method

}//End class Main


/////////////////////////////class Mymetal//////////////////////////////////////
abstract class Mymetal
{//Start class Fittings

    public String fit_type;//fitting type (rg-6, rg-59, rg-11)
    public int item_number;//Fitting number
    private int stock;//Fittings in inventory
    private double price;//Ptice of Fittings

    public Mymetal (String f_type, int f_number, int f_stock, double f_price)
    {//Construct variables

       fit_type = f_type;
       item_number = f_number;
       stock = f_stock;
       price = f_price;

    }//End constructor

       public void setf_type(String f_type)
       {
          fit_type = f_type;
       }//End set method

       public String getf_type()
       {
          return fit_type;
       }//End get method

       public void setf_number(int f_number)
       {
          item_number = f_number;
       }//End set method

       public int getitem_number()
       {
          return item_number;
       }//End get method

       public void setf_stock(int f_stock)
       {
           stock = f_stock;
       }

       public int getf_stock()
       {
          return stock;
       }

       public void setf_price (double f_price)
       {
          price = f_price;
       }

       public double getf_price()
       {
          return price;
       }

       public String toString()
       {
          return String.format("Fitting Type:%s\n Fitting #:\n Fittings in Stock: %d\n Price: $%.2f",
          getf_type(), getitem_number(), getf_stock(), getf_price());
       }//End String method

       public abstract double total_assets();

       public abstract double fee();

}//End class mymetal


//////////////////////////////////class METALFITTINGS///////////////////////////
class MetalFittings extends Mymetal
{
   private String metal;

   public MetalFittings(String f_type,int f_number,int f_stock, double f_price, String metal)
   {
      super (f_type, f_number, f_stock, f_price);
      setmetal(metal);
   }
   public void setmetal(String f_metal)
   {
      metal = f_metal;
   }

   public String getf_metal()
   {
      return metal;
   }

   public double total_assets()
   {
      return getf_price() * getf_stock();
   }//End calculation method

   public double fee()
   {
      return getf_price() * 1.05;
   }

   public String toString()
   {
      return String.format("%s: %s\n%s: %s",
      "Metal:", getf_metal());
   }//End method to get the new "metal"

}

///////////////////////////////class Inventory//////////////////////////////////
class Inventory
{//Begin class Inventory
   public static final int Array_cap = 20;

   private MetalFittings[] fittings;

   public int amount_fit;

   Inventory()
   {
      fittings = new MetalFittings[Array_cap];
      amount_fit = 0;
   }

   public int getamount_fit()
   {
       return amount_fit;
   }

   public MetalFittings getMetalFittings(int i)
   {
      return fittings[i];
   }

   public void delete(int i)
   {
      fittings[i] = fittings[amount_fit -1];
      --amount_fit;
   }

   public void growMetalFittings (MetalFittings fitting)
   {
      fittings[amount_fit]= fitting;
      ++amount_fit;
   }

   public void shrinkMetalFittings (MetalFittings fitting)
   {
      fittings[amount_fit]= fitting;
      --amount_fit;

   }

   public double asset()
   {
      double asset = 0.0;
      for(int i = 0;i<amount_fit;i++)
         asset+= fittings[i].total_assets();
         return asset;

   }

}//End class Inventory


////////////////////////////////////class art_logo//////////////////////////////
class art_logo extends JPanel
{//Begin class art_logo

   public void art(Graphics x)
   {
      super.paintComponent(x);

      x.setColor(Color.RED);

      x.draw3DRect(30, 10, 175, 30, true);

      x.setColor(Color.BLACK);
      x.setFont(new Font("Arial", Font.ITALIC, 35));
      x.drawString("Fittings INC.", 15, 49);


   }


}//End class art_logo


///////////////////////////////////class MyGUI//////////////////////////////////
class MyGUI extends JFrame
{//Begin class MyGUI

    private Inventory inventory;
    public int array_index = 0;

    private final JLabel f_size= new JLabel("Fitting Type:");
    public JTextField f_sizeText;


    private final JLabel f_num = new JLabel("Fitting #:");
    public JTextField f_numberText;


    private final JLabel f_stock= new JLabel("Fittings in Stock:");
    public JTextField f_stockText;


    private final JLabel f_price= new JLabel("Fitting Price:");
    public JTextField f_priceText;


    private final JLabel f_metal = new JLabel("Metal");
    public JTextField f_metalText;


    private final JLabel f_fee= new JLabel("Restock Fee:");
    public JTextField f_feeText;


    private final JLabel f_toassets= new JLabel("Total Assest in Inventory:");
    public JTextField f_toassetsText;


    private final JLabel f_find = new JLabel("Find Fittings(enter fitting type):");
    public JTextField f_findText;



    MyGUI (Inventory myinv)
    {
      art_logo art = new art_logo();

      final Dimension size = new Dimension(150, 40);

      final Dimension sizeA = new Dimension(400, 100);

      final Dimension sizeC = new Dimension(145, 68);

      final FlowLayout form = new FlowLayout(FlowLayout.LEFT);

      final FlowLayout form1 = new FlowLayout (FlowLayout.RIGHT);

      JPanel mypanel = new JPanel();

      JPanel button = new JPanel();

      button.setLayout(new GridLayout(3,6));

      JPanel bullseye = new JPanel();

      bullseye.setLayout(new BoxLayout(bullseye, BoxLayout.Y_AXIS));

      inventory = myinv;

      JButton first = new JButton ("FIRST");
      button.add(first);

      JButton last = new JButton ("LAST");
      button.add(last);

      JButton next = new JButton ("NEXT");
      button.add (next);

      JButton prev = new JButton ("PREVIOUS");
      button.add(prev);

      JButton save = new JButton ("SAVE");
      button.add(save);

      JButton delete = new JButton ("DELETE");
      button.add(delete);

      JButton input = new JButton("INPUT");
      button.add(input);

      JButton mod = new JButton("EDIT");
      button.add(mod);

      mypanel = new JPanel(form1);
      
      art.setPreferredSize(sizeC);
      mypanel.add(art);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_size.setPreferredSize(size);
      mypanel.add(f_size);
      f_sizeText = new JTextField(10);
      f_sizeText.setEditable(false);
      mypanel.add(f_sizeText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_num.setPreferredSize(size);
      mypanel.add(f_num);
      f_numberText = new JTextField(10);
      f_numberText.setEditable(false);
      mypanel.add(f_numberText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_stock.setPreferredSize(size);
      mypanel.add(f_stock);
      f_stockText = new JTextField(10);
      f_stockText.setEditable(false);
      mypanel.add(f_stockText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_price.setPreferredSize(size);
      mypanel.add(f_price);
      f_priceText = new JTextField(10);
      f_priceText.setEditable(false);
      mypanel.add(f_priceText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_metal.setPreferredSize(size);
      mypanel.add(f_metal);
      f_metalText = new JTextField(10);
      f_metalText.setEditable(false);
      mypanel.add(f_metalText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_fee.setPreferredSize(size);
      mypanel.add(f_fee);
      f_feeText = new JTextField(10);
      f_feeText.setEditable(false);
      mypanel.add(f_feeText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_toassets.setPreferredSize(size);
      mypanel.add(f_toassets);
      f_toassetsText = new JTextField(10);
      f_toassetsText.setEditable(false);
      mypanel.add(f_toassetsText);
      bullseye.add(mypanel);

      mypanel = new JPanel(form);

      f_find.setPreferredSize(size);
      mypanel.add(f_find);
      f_findText = new JTextField(10);
      f_findText.setEditable(false);
      mypanel.add(f_findText);
      bullseye.add(mypanel);

      JFrame see = new JFrame("Fittings Inventory Program!!");

      see.setLayout(new BorderLayout());

      see.add(button, BorderLayout.SOUTH);

      see.add(bullseye, BorderLayout.CENTER);

      see.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      see.setSize(433, 522);

      see.setResizable(true);

      see.setLocationRelativeTo(null);

      see.setVisible(true);

      

         first.addActionListener(new ActionListener()
      {
          public void action(ActionEvent Q)
          {
                     array_index = 0;
                     
          }

       

      });

         last.addActionListener(new ActionListener()
         {
            public void action(ActionEvent Q)
            {
               int fittings = inventory.getamount_fit();
               array_index = (fittings -1) % fittings;
               
            }

            public void actionPerformed(ActionEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
         });

          prev.addActionListener(new ActionListener()
        {

           public void action(ActionEvent Q)
          {
                     int fittings = inventory.getamount_fit();
                        if (fittings != 0)
                            array_index = (-- array_index) % fittings;
                        if(array_index < 0)
                            array_index = fittings -1;
                        
          }

            

        });


               next.addActionListener(new ActionListener()
      {

                   public void action(ActionEvent Q)
          {


                      int fittings = inventory.getamount_fit();
                      array_index = (++array_index) % fittings;
                      

          }

           
      });
      

      
      delete.addActionListener (new ActionListener()
      {
          public void action (ActionEvent Q)
          {
             int amount_fit = inventory.getamount_fit();
             MetalFittings temp = (MetalFittings)
                     inventory.getMetalFittings(array_index);
             
                if (amount_fit != 0)
                {
                  if(Integer.parseInt(f_numberText.getText())!= amount_fit)
                  {
                     inventory.delete(array_index);

                     

                     int i = Integer.parseInt(f_numberText.getText());

                     array_index = (++array_index) % amount_fit;

                     

                     int j = Integer.parseInt(f_sizeText.getText());
                  }
                }
             
          }

          
      });

     

           class filestore
           {
              private Formatter readto;

              public void readtoFile()
              {
                 try
                 {
                    String strDirectory = "C://data/";
                        boolean success = (new File(strDirectory)).mkdir();

                        if (success)
                        {
                           JOptionPane.showMessageDialog(null, "New file created on hard-drive","", JOptionPane.PLAIN_MESSAGE);
                        }
                 }
                           catch (Exception Q)
                           {
                              JOptionPane.showMessageDialog(null, "Cannot open file.", "", JOptionPane.ERROR_MESSAGE);
                           }

                        try
                        {
                           readto = new Formatter("C:/data/inventory.dat");
                        }

                        catch (SecurityException securityException)
                        {
                           JOptionPane.showMessageDialog(null, "Error writing file","", JOptionPane.ERROR_MESSAGE);
                        }

                         catch (FileNotFoundException filenotfoundexception)
                        {
                           JOptionPane.showMessageDialog(null, "Need file created in C drive","", JOptionPane.ERROR_MESSAGE);
                           System.exit(1);
                        }

                          JOptionPane.showMessageDialog(null, "File saved!!!","", JOptionPane.PLAIN_MESSAGE);


                        }

             public void closeFile()
             {
                if (readto != null)
                    readto.close();
             }

             public void newGUI()
             {
                MetalFittings temp = (MetalFittings)
                        inventory.getMetalFittings(array_index);

                   if (temp != null)
                   {
                      f_numberText.setText(""+ temp.getitem_number());
                      f_sizeText.setText(temp.getf_type());
                      f_metalText.setText(String.format("%s", temp.getf_metal()));
                      f_priceText.setText(String.format("%.2f", temp.getf_price()));
                      f_stockText.setText(String.format("%d", temp.getf_stock()));
                      f_feeText.setText(String.format("%.2f", temp.total_assets()));
                   }



             

             }
           }
    }
}

Sorry, the errors are at the first brace in the actionlistener and netbeans says "anonymousfittingsinventory.MyGUI$1>is not abstract and does not override abstract method actionperformed"

At what line you get the error and what does it say and at which class?

You probably haven't defined the actionPerformed method.

Edited 7 Years Ago by javaAddict: n/a

they start at line 424 and then at every first "{" at the start of subsequent action methods) netbeans wanted me to throw in code like at 444, while it will take care of the error, my button errors out during runtime. Very confused!!

I changed the code on the listeners to all say the same, but now I still have the error at the first curly brace in the first.addActionListener method

Both of your posts mean nothing to us:

first curly brace in the first.addActionListener
they start at line 424 and then at every first "{"

Do you want us to search that chaos of yours in order to find the "first curly brace"?
or do you expect us to count 424 lines?

Post relevant code where you point where is the error at what that error is.

Also the simple way for ActionListeners:

class MyFrame extends JFrame implements ActionListener {
   JButton b1;
   JButton b2;
....

   public MyFrame() {
       ....
       b1.addActionListener(this);
       b2.addActionListener(this);
   }

      public void actionPerformed(ActionEvent e) {
          Object source = e.getSource();
          if (b1==source) {
                 // b1 button clicked
          } else if (b2==source) {
                 // b2 button clicked
          }
      }
}
This article has been dead for over six months. Start a new discussion instead.