Cant find this error and all these java scripts are talking together can someone please find it. error has been noted blow.

import javax.swing.JFrame;

 public class WindowApp{
      public static void main(String [] args){
        JFrame window = new JFrame("A window");//cans et the title on the title bar
        window.getContentPane().add(new ImagePanel());
        window.setVisible(true);
        window.pack();
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
    }





import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.ArrayList;

public class ImagePanel extends JPanel{
  private JLabel imageLabel = new JLabel("");
  private ImageIcon left = new ImageIcon("images/leftArrow.png");
  private JButton leftArrowButton = new JButton(left);
  private ImageIcon right = new ImageIcon("images/rightArrow.png");
  private JButton rightArrowButton = new JButton(left);
  private JLabel captionLabel = new JLabel("");

  private JPanel lower = new JPanel();
  private JPanel picturePanel = new JPanel();
  private JPanel upperPanel = new JPanel();
  private JPanel moveOnPanel = new JPanel();
  private JPanel moveBackPanel = new JPanel();

  private ArrayList<ImageInfo> photos; //this is the main idea of the structure
  private int target = 0;

  /**Constructor with the arrayList parameters*/

  public ImagePanel(ArrayList<ImageInfo> photos){
    this.photos = photos; //fill the data fields with the incoming info
    //set up the listener
    EventListener listener = new EventListener();
    leftArrowButton.addActionListener(listener);
    rightArrowButton.addActionListener(listener);

    //set up the panels
    setLayout(new BorderLayout());

    //north border is just there for colour and size
    upperPanel.setPreferredSize(new Dimension(400,50));
    upperPanel.setBackground(Color.black);
    add(upperPanel,BorderLayout.NORTH);

    //east border contains right arrow button
    moveOnPanel.setPreferredSize(new Dimension(50,200));
    moveOnPanel.add(rightArrowButton);
    moveOnPanel.setBackground(Color.black);
    add(moveOnPanel,BorderLayout.EAST);

    //west borde contains left arrow button
    moveBackPanel.setPreferredSize(new Dimension (50,200));
    moveBackPanel.add(leftArrowButton);
    moveBackPanel.setBackground(Color.black);
    add(moveBackPanel,BorderLayout.WEST);

    //lower border contains caption
    lower.setPreferredSize(new Dimension(400,50));
    captionLabel.setFont(new Font("Courier",Font.BOLD,35));
    captionLabel.setForeground(Color.white);
    lower.add(captionLabel);
    lower.setBackground(Color.black);
    add(lower,BorderLayout.SOUTH);

    //center border contains the image
    picturePanel.add(imageLabel);
    picturePanel.setBackground(Color.black);
    add(picturePanel,BorderLayout.CENTER);
    showImage(0);
  }

  /**update images and caption*/
  public void showImage(int target){
    ImageIcon ii = new ImageIcon(photos.get(target).getFilename());
    imageLabel.setIcon(ii);
    captionLabel.setText(photos.get(target).getCaption());
  }

  /**move forward or back through photo list*/
  private class EventListener implements ActionListener{
    public void actionPerformed (ActionEvent e){
      //select target photo
      if(e.getSource() == leftArrowButton){
       target--;
       if(target<0){
         target = photos.size() - 1; //roll around to end
       }
      }else if (e.getSource() == rightArrowButton){
        target++;
        if(target == photos.size()){
          target = 0; //roll around to begining
        }
      }
    }
  }

}




/**Support class to hold data about an image*/
public class ImageInfo{
  private String filename; //file name and path for images
  private String caption; //a caption for this image
  private int width; //width of image in pixels
  private int height; //height of image pixels
  private int kb; //size in kilobytes

  /**constructor to set the values for the data fields*/
  public ImageInfo(String filename, String caption, int Width, int height, int kb){
    this.filename = filename;
    this.caption = caption;
    this.width = width;
    this.height = height;
    this.kb = kb;
  }

  /**descibes the data stored for each image*/
  public void showData(){
    System.out.println("Image caption: " + caption);
    System.out.println("\tdispaly size: " + width + "x " + height + "pixels.");
    System.out.println("\tfilename: " + filename);
    System.out.println("\tstorage size: " + kb + "\n\n");
  }

  /**returns the file name*/
  public String getFilename(){
    return filename;
  }

  /**returns the caption*/
  public String getCaption(){
    return caption;
  }

  /**returns the size*/
  public int getMemorySize(){
    return kb;
  }
}

i have this error: The constructor ImagePanel() is undefined. This is in the wondows app which is at the top of the page and i cnanot find it can somone please fix it. Thanks

here is the problem:

public ImagePanel(ArrayList<ImageInfo> photos){

this is the constructor you provide for your ImagePanel class.

this is the one you try to call:

window.getContentPane().add(new ImagePanel());

the compiler will automatically add a default (non argument) constructor, but only if you don't provide any constructors in your class yourself.

so, either you have to pass an ArrayList with elements of type <ImageInfo> or you'll have to add a default constructor in your ImagePanel class.

also: nice to note, you were looking in these Java 'scripts': pieces of code are called snippets. you don't "script" in Java, make sure you don't mix up the terminology of Java and JavaScript, that might make it harder for those trying to understand what you are trying to say.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.