Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 347909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:18:56+00:00 2026-05-12T11:18:56+00:00

I had a huge file for creating this GUI and I have shortened it

  • 0

I had a huge file for creating this GUI and I have shortened it by using arrays. I am trying to add an ActionListener but when the arrays are being added and I am getting the following errors:

/tmp/jc_3531/GUI.java:60: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (GUI)
            nButtons[c].addActionListener( this );
                       ^
/tmp/jc_3531/GUI.java:69: cannot find symbol
symbol  : method addActionListener(GUI)
location: class javax.swing.JLabel
            labels[c].addActionListener( this );
                     ^
/tmp/jc_3531/GUI.java:78: addActionListener(java.awt.event.ActionListener) in javax.swing.JTextField cannot be applied to (GUI)
            fields[c].addActionListener( this );
                     ^
/tmp/jc_3531/GUI.java:90: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (GUI)
            sButtons[c].addActionListener( this );
                       ^
4 errors

What am I doing wrong? Is there an easier way to self diagnose (like an editor with an integrated syntax guide)?

Here is my Code

// GUI with navigation amd file manipulation buttons
import javax.swing.*; // provides basic window features
import java.awt.event.*;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.text.NumberFormat;

public class GUI extends JFrame 
{
    private Inventory inv;      
    private int currentDisplay = 0; 

    private JPanel nButtonJPanel;
    private String nNames[]={"Load","Add","Modify","Delete","Search","Save"};
    private JButton nButtons[];

    private JPanel labelJPanel;
    private String labeled[]={"Item ID","Name","Rating","# in Stock","Price","Inventory Value",
    "Restocking Fee (5%)","Inventory Value with Fee","Total Value with Fee (all DVD's)"};
    private JLabel labels[];

    private JPanel fieldJPanel;
    private String fieldsBlank[]={"","","","","","","","",""};
    private JTextField fields[];

    private JPanel sButtonJPanel;
    private String sNames[]={"First","Prev","","Next","Last"};
    private JButton sButtons[];

   // LabelFrame constructor adds JLabels to JFrame
   public GUI()
   {
      super( "Inventory Program v.5" );
      setLayout( new BorderLayout() ); // set frame layout

        // initialize values
        RatedDVD d1 = new RatedDVD(1, "One Flew Over The Cuckoo's Nest", 3, 9.99, "PG");
        RatedDVD d2 = new   RatedDVD(2, "The Matrix", 1, 13.01, "PG13");
        RatedDVD d3 = new   RatedDVD(3, "Se7en", 7, 11.11, "R");
        RatedDVD d4 = new   RatedDVD(4, "Oceans Eleven", 11, 9.02, "PG13");
        RatedDVD d5 = new   RatedDVD(5, "Hitch Hikers Guide to the Galaxy", 42, 10.00, "G");    
        RatedDVD d6 = new   RatedDVD(6, "The Invisible Man", 0, 4999.59, "G");  

        // create inv and enter values
        inv = new Inventory();
        inv.add(d1);
        inv.add(d2);
        inv.add(d3);
        inv.add(d4);
        inv.add(d5);
        inv.add(d6);

        inv.sort();

        //make nButtons
        nButtonJPanel.setLayout( new GridLayout( 1, nNames.length, 5, 5 ) );
        nButtons=new JButton[nNames.length];
        for(int c=0;c<nButtons.length;c++){
            nButtons[c]=new JButton(nNames[c]);
            nButtons[c].addActionListener( this );
            nButtonJPanel.add(nButtons[c]); }
        add( nButtonJPanel, BorderLayout.NORTH );

        //make labels
        labelJPanel.setLayout( new GridLayout( labeled.length, 1 ));
        labels=new JLabel[labeled.length];  
        for(int c=0;c<labels.length;c++){
            labels[c]=new JLabel(labeled[c]);
            labels[c].addActionListener( this );
            labelJPanel.add(labels[c]);}
        add( labelJPanel, BorderLayout.WEST );

        //make fields
        fieldJPanel.setLayout( new GridLayout( fieldsBlank.length, 1 ));
        fields=new JTextField[fieldsBlank.length];
        for(int c=0;c<fields.length;c++){
            fields[c]=new JTextField(fieldsBlank[c],28);
            fields[c].addActionListener( this );
            fields[c].setEditable(false);
            fieldJPanel.add(fields[c]); }
            populate(currentDisplay);
        add( fieldJPanel, BorderLayout.EAST );

        //make sButtons
        sButtonJPanel.setLayout( new GridLayout( 1, sNames.length, 5, 5 ) );
        sButtons=new JButton[sNames.length];    
        Icon dvd50 = new ImageIcon( getClass().getResource( "dvd50.jpg" ) );
        for(int c=0;c<sButtons.length;c++){
            sButtons[c]=new JButton(sNames[c]);
            sButtons[c].addActionListener( this );
            sButtonJPanel.add(sButtons[c]);}
        sButtons[2].setIcon( dvd50 );       
        add( sButtonJPanel, BorderLayout.SOUTH );
    }// end method

    public void populate(int currentDisplay)
    {
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    fields[0].setText(String.valueOf(inv.get(currentDisplay).getItem()));
    fields[1].setText(inv.get(currentDisplay).getName());
    fields[2].setText(inv.get(currentDisplay).getRating());
    fields[3].setText(String.valueOf(inv.get(currentDisplay).getUnits()));
    fields[4].setText(String.valueOf(nf.format(inv.get(currentDisplay).getPrice())));
    fields[5].setText(String.valueOf(nf.format(inv.get(currentDisplay).value())));
    fields[6].setText(String.valueOf(nf.format(inv.get(currentDisplay).fee())));
    fields[7].setText(String.valueOf(nf.format(inv.get(currentDisplay).feeValue())));
    fields[8].setText(String.valueOf(nf.format(inv.value())));
    }

    public void actionPerformed(ActionEvent e) {


    }
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:18:56+00:00Added an answer on May 12, 2026 at 11:18 am

    You need to make your GUI class implement ActionListener by changing

    public class GUI extends JFrame 
    

    to

    public class GUI extends JFrame implements ActionListener
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
First of all, I have never written a property editor from scratch, but had
This is a theoretical question as I don't have an actual problem, but I
We are converting large PDF file using Adobe LiveCycle ConvertPDF service. This works fine
I have a huge text file (~5GB) which is the database for my program.
We had huge performance problem when deploying our ASP.NET app at a customer, which
Say if you had to develop a huge windows desktop app what language/technology you
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
Had a problem with the recursive conflictCheck() method. That seems fine now. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.