hey
I have a project called ImageViewer and within this project I have these classes: DarkerFilter, EdgeFilter, Filter, FishEyeFilter, GrayScaleFilter, ImageDriver, ImageFileManager, ImagePanel, ImageViewer, InvertFilter, LighterFilter, MirrorFilter, OFImage, PixelizeFilter,SmoothFilter, SolarizeFilter and ThresholdFilter.
Task: is to add my own features to the ImageViewer, which is a slider (V and H) and a next Image button.
Problem: is my changeListener for the slider doesn't work and my actionListener for the next button works but it opens the file and i have to manual choose the image but i want it to automatically choose the next image in the file.
this is what i have so far:
is there away to do the actionListener so that the next button can selecte an image from the file when the next button is clicked?// this is the ChangeListener for the slider. public void stateChanged(ChangeEvent ce){ OFImage currentval = currentImage; JSlider source = (JSlider)ce.getSource(); if(!source.getValueIsAdjusting()){ int value = (int)source.getValue(); label.setText("current value: " + value); } currentImage = currentval; imagePanel.setImage(currentval); frame.pack(); } //this is the vertical slider slider1 = new JSlider (JSlider.VERTICAL, 0, 50, 50); slider1.setMajorTickSpacing(5); slider1.setPaintTicks(true); label = new JLabel("current value: 0"); slider1.add(label); slider1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { stateChanged(ce); } //this is not working because of the changeListener? }); contentPane.add(slider1, BorderLayout.EAST); //this is the actionListener for the next button. private void openFile() { int returnVal = fileChooser.showOpenDialog(frame); if(returnVal != JFileChooser.APPROVE_OPTION) { return; // cancelled } File selectedFile = fileChooser.getSelectedFile(); currentImage = ImageFileManager.loadImage(selectedFile); if(currentImage == null) { // image file was not a valid image JOptionPane.showMessageDialog(frame, "The file was not in a recognized image file format.", "Image Load Error", JOptionPane.ERROR_MESSAGE); return; } imagePanel.setImage(currentImage); setButtonsEnabled(true); showFilename(selectedFile.getPath()); showStatus("File loaded."); frame.pack(); } //this works if i use openFile(), in the actionPerformed but the file opens and i have to choose it manually. nextButton = new JButton("Next Image"); nextButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(); } }); toolbar.add(nextButton); //and this actionListener for the nextButton doesn't work public void nextButton(){ ArrayList<ImagePanel> nextImage = new ArrayList<ImagePanel>(); if(ImagePanel == nextImage){ newImage.openFile(); } }
does anyone know what i'm doing wrong or knows how to fix it.
thank you