| 12
 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
 
 | import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
public class MonApplet extends JApplet implements ActionListener {
 
	JButton ouvrir = new JButton("Selectionner un fichier"); // bouton ouvrir
 
	JButton enregistrer = new JButton("Enregistrer"); // bouton enregistrer
 
	JTextField statut = new JTextField("Pas de fichier chargé!"); // bouton champs de texte
 
	JPanel panelBouton = new JPanel();
 
	JPanel panelImage = new JPanel();
 
	JFileChooser chooser;
 
	BufferedImage monImage;
 
	int nb = 0;
 
	public void init() {
		// this.getContentPane().setSize(500, 500);
		// monPanel.setSize(500, 500);
		panelBouton.setBackground(Color.gray);
		panelImage.setBackground(Color.white);
 
		panelBouton.setMinimumSize(new Dimension(this.getWidth(), (int) (this
				.getHeight() * 0.5)));
		panelImage.setMinimumSize(new Dimension(this.getWidth(), (int) (this
				.getHeight() * 0.5)));
 
		ouvrir.addActionListener(this);
		panelBouton.add(ouvrir);
		panelBouton.add(statut);
 
		this.getContentPane().add(panelBouton, BorderLayout.NORTH);
		this.getContentPane().add(panelImage, BorderLayout.SOUTH);
 
		System.out.println("OK etape1");
 
	}
 
	public void paint(Graphics g) {
 
		try {
			// Ecouteur bouton enregistrer
			EcouteurEnregistrer ec2 = null;
			panelBouton.add(enregistrer, BorderLayout.EAST);
 
			monImage = ImageIO.read(new File(statut.getText()));
			int proportionH = monImage.getHeight() / 200;
			int largeur = monImage.getWidth() / proportionH;
			int hauteur = 200;
			g.drawImage(monImage, 100, 100, largeur, hauteur, this);
 
			enregistrer.removeActionListener(ec2);
			ec2 = new EcouteurEnregistrer(monImage);
			enregistrer.addActionListener(ec2);
 
			System.out.println("OK normalement dans le try de image ");
		} catch (IOException e) {
			System.out.println("exception try image " + e);
		}
	}
 
	public void actionPerformed(ActionEvent evt) {
		chooser = new JFileChooser();// création dun filechosser
		chooser.setApproveButtonText("OK"); // intitulé du bouton
		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
			statut.setText(chooser.getSelectedFile().getAbsolutePath()); // affichage chemin dans txt
			statut.getText();
			repaint();
		}
	}
 
 
 
	public void start() {
 
	}
 
	public void stop() {
 
	}
 
	public void destroy() {
 
	}
 
} | 
Partager