Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: creating GUI using java, need help?

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
    // 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
    Last edited by copeg; April 5th, 2011 at 03:15 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: creating GUI using java, need help?

    my changeListener for the slider doesn't work]
    What about it doesn't work? Is it fired?

    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

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: creating GUI using java, need help?

    Quote Originally Posted by copeg View Post
    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.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: creating GUI using java, need help?

    Quote Originally Posted by koko20 View Post
    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.

Similar Threads

  1. Creating a Compiler in Java
    By Superstar288 in forum Java Theory & Questions
    Replies: 20
    Last Post: February 22nd, 2013, 09:05 AM
  2. Creating a Gun in Java, I'm completely lost.
    By Pryde in forum Java Theory & Questions
    Replies: 1
    Last Post: March 21st, 2011, 09:13 AM
  3. Creating a Triagular Wave in Java
    By locorecto in forum AWT / Java Swing
    Replies: 3
    Last Post: March 8th, 2010, 01:51 AM
  4. Creating program Blackjack - Dr.Java
    By TheUntameable in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2010, 12:54 PM
  5. Creating A Count Matrix In Java
    By statsman5 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 14th, 2009, 05:40 PM