Wednesday, October 2, 2013

constructor

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.EXITONCLOSE); } } 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 photos; //this is the main idea of the structure private int target = 0; /**Constructor with the arrayList parameters*/ public ImagePanel(ArrayList 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
Full Post

No comments:

Post a Comment