creating GUI using java, need help?
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:
Code java:
// 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();
}
}
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?
does anyone know what i'm doing wrong or knows how to fix it.
thank you
Re: creating GUI using java, need help?
Quote:
my changeListener for the slider doesn't work]
What about it doesn't work? Is it fired?
Quote:
automatically choose the next image in the file...next button can selecte an image from the file when the next button is clicked
Not sure what you mean by select the next image in the file
Re: creating GUI using java, need help?
Quote:
Originally Posted by
copeg
What about it doesn't work? Is it fired?
no it just doesn't do anything, like when u have an image up the action for the slider doesn't work
Not sure what you mean by select the next image in the file
like instead of going to file and open the file and choosing the image each time i want to selecte another one, i want the "next Button" to select the next image for me and displaying it for me on the image viewer, something like an arrayList having a number of items in an arrayList.
i hope i'm been clear about what i'm saying.
Re: creating GUI using java, need help?
Quote:
Originally Posted by
koko20
like instead of going to file and open the file and choosing the image each time i want to selecte another one, i want the "next Button" to select the next image for me and displaying it for me on the image viewer, something like an arrayList having a number of items in an arrayList.
i hope i'm been clear about what i'm saying.
Still not fully understanding...if you mean the 'next' file, then one can get the parent directory of the initially selected file and call listFiles, which will return an array of files from which you can get the next File from that array - of course not all files may be images so you will need to somehow control for this.