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
| import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.ImageIcon;
public class interfacejava {
public static void main(final String[] args)throws IOException
{
final JFrame frame = new JFrame("Interface");
JMenuBar menubar=new JMenuBar();
JMenu menu = new JMenu(" File ");
JMenuItem ouvrir = new JMenuItem(" Ouvrir ",'O');
final JMenuItem genere = new JMenuItem(" Génerer les 10 meilleure posts ",'G');
menubar.add(menu);
menu.add(ouvrir);
menu.add(genere);
frame.setJMenuBar(menubar);
frame.setSize(500,300);
ouvrir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String photo;
Statement stmt;
Connection conn;
JFileChooser dialogue = new JFileChooser(new File("C:/Users/gmi/Desktop/Photos"));
File fichier;
if (dialogue.showOpenDialog(null)==
JFileChooser.APPROVE_OPTION) {
fichier = dialogue.getSelectedFile();
String namefile=dialogue.getName(fichier);
System.out.println(namefile);
});
genere.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
ma_methode (frame);
frame.show();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private static void ma_methode(JFrame frame) throws IOException {
frame.setSize(500,300);
try
{
frame.setLayout(null);
File file = new File("C:/Users/gmi/Desktop/Photos/im1.jpg");
BufferedImage im = ImageIO.read(file);
//affichage de l'image
ImageIcon icon = new ImageIcon(im);
Image zoom = scaleImage(icon.getImage(), 50, 50);
Icon iconScaled = new ImageIcon(zoom);
JLabel monImage = new JLabel(iconScaled);
monImage.setBounds(30, 30, 50, 100);
frame.add(monImage);
frame.show();
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private static Image scaleImage(Image source, int width, int height) {
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(source, 0, 0, width, height, null);
g.dispose();
return img;
}} |
Partager