GUI Project in Java I cant figure out these errors ComboBoxD

GUI Project in Java

I can\'t figure out these errors:

ComboBoxDemo.java:39: <anonymous ComboBoxDemo$1> is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
jcbo.addItemListener(new ItemListener() {
^
ComboBoxDemo.java:40: method does not override or implement a method from a supertype
@Override
^
2 errors

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ComboBoxDemo extends JFrame {

private String[] songTitles = {\" \", \" \", \" \"};

private ImageIcon[] songImage = {

   new ImageIcon(\" \")

   };

  

   private String[] songDescription = new String [3];

  

   private DescriptionPanel descriptionPanel = new DescriptionPanel();

  

   private JComboBox jcbo = new JComboBox(songTitles);

  

   public static void main(String[] args) {

      ComboBoxDemo frame = new ComboBoxDemo();

     

      frame.pack();

      frame.setTitle(\" \");

      frame.setLocationRelativeTo(null);

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      frame.setVisible(true);

      }

     

public ComboBoxDemo() {

   songDescription[0] = \" \";

   songDescription[1] = \" \";

   songDescription[2] = \" \";

  

   setDisplay(0);

  

   add(jcbo, BorderLayout.NORTH);

   add(descriptionPanel, BorderLayout.CENTER);

  

   jcbo.addItemListener(new ItemListener() {

      @Override

     

   public void itemSongChanged(ItemEvent e) {

      setDisplay(jcbo.getSelectedIndex());

     

      }

     });

    }

   

    public void setDisplay(int index) {

      descriptionPanel.setTitle(songTitles[index]);

      descriptionPanel.setImageIcon(songImage[index]);

      descriptionPanel.setDescription(songDescription[index]);

     }

    }   

Solution

Hi,

I have updated the code and fixed the issues and highlighted the code changes below

-

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ComboBoxDemo extends JFrame {

private String[] songTitles = {\" \", \" \", \" \"};

private ImageIcon[] songImage = {
new ImageIcon(\" \")
};
  
private String[] songDescription = new String [3];
  
private DescriptionPanel descriptionPanel = new DescriptionPanel();
  
private JComboBox jcbo = new JComboBox(songTitles);
  
public static void main(String[] args) {
ComboBoxDemo frame = new ComboBoxDemo();

frame.pack();
frame.setTitle(\" \");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public ComboBoxDemo() {
songDescription[0] = \" \";
songDescription[1] = \" \";
songDescription[2] = \" \";
  
setDisplay(0);
  
add(jcbo, BorderLayout.NORTH);
add(descriptionPanel, BorderLayout.CENTER);
  
jcbo.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {
setDisplay(jcbo.getSelectedIndex());

}

});
}

public void setDisplay(int index) {
descriptionPanel.setTitle(songTitles[index]);
descriptionPanel.setImageIcon(songImage[index]);
descriptionPanel.setDescription(songDescription[index]);
}
}

GUI Project in Java I can\'t figure out these errors: ComboBoxDemo.java:39: <anonymous ComboBoxDemo$1> is not abstract and does not override abstract meth
GUI Project in Java I can\'t figure out these errors: ComboBoxDemo.java:39: <anonymous ComboBoxDemo$1> is not abstract and does not override abstract meth
GUI Project in Java I can\'t figure out these errors: ComboBoxDemo.java:39: <anonymous ComboBoxDemo$1> is not abstract and does not override abstract meth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site