package projet_poo2;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class IHM extends JFrame 
{
	private static final long serialVersionUID = 1L;
	private JMenuBar menuBar = new JMenuBar();
	private JMenu menu1 = new JMenu("Fichier");
	private JMenuItem item1 = new JMenuItem("Ouvrir");
	
	public IHM()
	{
		super();
		
		this.setTitle("Project");
		this.setPreferredSize(new Dimension(200,200));
		this.menuBar.add(menu1);
		this.menu1.add(item1);
		item1.addActionListener(new ActionListener(){
		      
			public void actionPerformed(ActionEvent event)
			{
				JFileChooser chooser = new JFileChooser();
			    FileNameExtensionFilter filter = new FileNameExtensionFilter(
			        "JPG & PNG & GIF Images", "jpg", "png","gif","jpeg");
			    chooser.setFileFilter(filter);
			    int returnVal = chooser.showOpenDialog(IHM.this);
			    if(returnVal == JFileChooser.APPROVE_OPTION)
			    {
			       System.out.println("You chose to open this file: " +
			            chooser.getSelectedFile().getName());
			    }
			   
			   if(chooser.getSelectedFile() != null)
			   {
				   ouvrirImage(chooser.getSelectedFile().getAbsolutePath());
			   }
			    
		    }
		});
		this.setJMenuBar(menuBar);
	}
	
	public void ouvrirImage(String filename)
	{
		Picture pic=new Picture(filename);
		ImageIcon ic = new ImageIcon(pic.image);
		JLabel jl=new JLabel(ic);
		//this.setContentPane(jl);
		this.setSize(new Dimension(pic.width,pic.height));
		this.add(jl);
		
	}
}


/*
package projet_poo2;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class IHM extends JFrame {
	
	private JMenuBar menuBar = new JMenuBar();
	private JMenu menu1 = new JMenu("Fichier");
	private JMenuItem item1 = new JMenuItem("Ouvrir");
	
	public IHM(){
		super();
		this.setTitle("Project");
		this.setSize(1000,500);
		this.menuBar.add(menu1);
		this.menu1.add(item1);
		this.setJMenuBar(menuBar);
	}
	
	private static final long serialVersionUID = 1L;

}
*/

@@ -114,16 +114,83 @@
 istener;
+%0Aimport java.awt.event.KeyEvent;%0Aimport java.awt.event.KeyListener;
 %0A%0Aimport
@@ -474,16 +474,38 @@
  JFrame 
+implements KeyListener
 %0A%7B%0A%09priv
@@ -796,24 +796,53 @@
 (200,200));%0A
+%09%09this.addKeyListener(this);%0A
 %09%09this.menuB
@@ -1001,605 +1001,27 @@
 %09%09%09%09
-JFileChooser chooser = new JFileChooser();%0A%09%09%09    FileNameExtensionFilter filter = new FileNameExtensionFilter(%0A%09%09%09        %22JPG & PNG & GIF Images%22, %22jpg%22, %22png%22,%22gif%22,%22jpeg%22);%0A%09%09%09    chooser.setFileFilter(filter);%0A%09%09%09    int returnVal = chooser.showOpenDialog(IHM.this);%0A%09%09%09    if(returnVal == JFileChooser.APPROVE_OPTION)%0A%09%09%09    %7B%0A%09%09%09       System.out.println(%22You chose to open this file: %22 +%0A%09%09%09            chooser.getSelectedFile().getName());%0A%09%09%09    %7D%0A%09%09%09   %0A%09%09%09   if(chooser.getSelectedFile() != null)%0A%09%09%09   %7B%0A%09%09%09%09   ouvrirImage(chooser.getSelectedFile().getAbsolutePath());%0A%09%09%09   %7D%0A%09%09%09    
+openFileLocation();
 %0A%09%09 
@@ -1222,37 +1222,8 @@
 c);%0A
-%09%09//this.setContentPane(jl);%0A
 %09%09th
@@ -1297,547 +1297,731 @@
 %0A%09%7D%0A
-%7D%0A%0A%0A/*%0Apackage projet_poo2;%0A%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JMenu;%0Aimport javax.swing.JMenuBar;%0Aimport javax.swing.JMenuItem;%0A%0Apublic class IHM extends JFrame %7B%0A%09%0A%09private JMenuBar menuBar = new JMenuBar();%0A%09private JMenu menu1 = new JMenu(%22Fichier%22);%0A%09private JMenuItem item1 = new JMenuItem(%22Ouvrir%22);%0A%09%0A%09public IHM()%7B%0A%09%09super();%0A%09%09this.setTitle(%22Project%22);%0A%09%09this.setSize(1000,500);%0A%09%09this.menuBar.add(menu1);%0A%09%09this.menu1.add(item1);%0A%09%09this.setJMenuBar(menuBar
+%09%0A%09public void openFileLocation()%7B%0A%09%09JFileChooser chooser = new JFileChooser();%0A%09%09FileNameExtensionFilter filter = new FileNameExtensionFilter(%0A%09%09    %22JPG & PNG & GIF Images%22, %22jpg%22, %22png%22,%22gif%22,%22jpeg%22);%0A%09%09chooser.setFileFilter(filter);%0A%09%09chooser.showOpenDialog(IHM.this);%0A%09%09if(chooser.getSelectedFile() != null)%0A%09%09%7B%0A%09%09%09ouvrirImage(chooser.getSelectedFile().getAbsolutePath());%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void keyTyped(KeyEvent e) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09%0A%09%7D%0A%0A%09@Override%0A%09public void keyPressed(KeyEvent e) %7B%0A%09%09if (e.isControlDown() && e.getKeyChar() != 'o' && e.getKeyCode() == 79) %7B%0A%09%09%09openFileLocation(
 );%0A
+%09
 %09%7D%0A%09
-%0A%09private static final long serialVersionUID = 1L;%0A%0A%7D%0A*/%0A
+%7D%0A%0A%09@Override%0A%09public void keyReleased(KeyEvent e) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09%0A%09%7D%0A%7D

option du crtl+O ajoutée