1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
package ouvrirfichier;
import java.awt.Graphics;
import javax.swing.JFrame;
public class ChargerImage{
public static void main(String[] args){
JFrame fenetre = new JFrame();
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setSize(400,300);
fenetre.setVisible(true);
fenetre.setTitle("création de panorama");
OuvrirFichier of=new OuvrirFichier(fenetre);
}
}
package ouvrirfichier;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowListener;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class OuvrirFichier extends JFrame {
private JFileChooser hf;
public OuvrirFichier(JFrame frame){
JMenuBar mb=new JMenuBar();
JMenu fichier=new JMenu("Fichier");
mb.add(fichier);
frame.setJMenuBar(mb);
JMenuItem ouvrir= new JMenuItem("Ouvrir");
JMenuItem quitter = new JMenuItem ("Quitter");
fichier.add(ouvrir);
fichier.add(quitter);
ouvrir.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser hf=new JFileChooser();
hf.setCurrentDirectory(new java.io.File("repertoires"));
hf.showOpenDialog(null);
System.out.println(hf.getSelectedFile());
Container leContenant = getContentPane();
leContenant.setLayout(new GridLayout(1,2));
AffichageImage image=new AffichageImage(hf.getSelectedFile().getAbsolutePath());
leContenant.add(image);
}
});
quitter.addActionListener( new ActionListener (){
public void actionPerformed (ActionEvent e){
Object[] options = {"Oui", "Non"};
JFrame frame2=new JFrame("Quitter");
int n = JOptionPane.showOptionDialog(frame2,
"Voulez vous vraiment quitter?",
"Quitter",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if( n==JOptionPane.YES_OPTION) {
System.exit(0);
}
}
});
}
}
package ouvrirfichier;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
public class AffichageImage extends Canvas
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// int largeurEcran = screenSize.width;
//int hauteurEcran = screenSize.height;
Image image;
public AffichageImage(String url)
{
image = getToolkit().getImage(url);
prepareImage(image, this);
}
public void paint(Graphics g)
{
g.drawImage(image, 0, 0,
100,
100, this);
}
} |
Partager