Results 1 to 4 of 4
  1. #1
    BC14 is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Exclamation FileChooser Help Needed !

    I'm trying to make an Image Viewer but as I was programming I encountered some problems, I'm trying to open an image and display it in the JFrame but I don't know how :( What I'm trying to make is when the user presses the JMenuItem Open a file chooser comes up and he can open an image and then it would be viewed it in the JFrame. Can someone help me please ? Thanks :)

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

    public class ImageViewer extends JFrame{


    JMenuBar menubar;
    JMenu File;
    JMenuItem Open;
    JMenuItem Close;
    JMenuItem Exit;


    public ImageViewer() {

    setLayout(new FlowLayout());

    menubar = new JMenuBar();
    setJMenuBar(menubar);

    File = new JMenu("File");
    menubar.add(File);

    Open = new JMenuItem("Open");
    File.add(Open);

    Close = new JMenuItem("Close");
    File.add(Close);

    Exit = new JMenuItem("Exit");
    File.add(Exit);

    event exit = new event();
    Exit.addActionListener(exit);
    }

    public class event implements ActionListener {
    public void actionPerformed(ActionEvent exit) {
    System.exit(0);

    }
    }



    public static void main (String args[]){
    ImageViewer gui = new ImageViewer();
    gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    gui.setSize(200,200);
    gui.setVisible(true);
    }
    }

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    3

    Default Re: FileChooser Help Needed !

    have a look at this

    How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    follow that, then return the File selected and pass that into a load(File) method of some sort then display the loaded image :)

  3. #3
    BC14 is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Default Re: FileChooser Help Needed !

    Thanks for the reply :) I tried the link but I can't really get hold of it :/

  4. #4
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    3

    Default Re: FileChooser Help Needed !

    what exactly are you struggling with? can you get a FileChooser to open? struggling retuning the file choosen? what you struggling with mainly?

Similar Threads

  1. Help with fileChooser
    By sportinus in forum AWT / Swing
    Replies: 1
    Last Post: 05-25-2011, 09:43 PM
  2. FileChooser
    By Unsub in forum New To Java
    Replies: 7
    Last Post: 03-10-2010, 04:54 AM
  3. FileChooser
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-23-2010, 05:43 PM
  4. Filechooser
    By Joe2003 in forum New To Java
    Replies: 5
    Last Post: 02-26-2009, 08:51 AM
  5. FileChooser UI
    By heartysnowy in forum New To Java
    Replies: 5
    Last Post: 11-27-2008, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •