/*
* REDIMION_IMAGE
* PROBLEME:L'IMAGE NE S'AFFICHE PAS,PLUSIEURS JFRAMES RESTENT OUVERTS
* COMMENT REGLER TOUT CA?
* MERCI BCP
*
* AU CAS OU C PA CLAIR:JE VEUX QUE L'IMAGE S'AFFICHE DANS CE JFRAME,
* FERMER LE PRECEDENT JFRAME CONTENANT L'IMAGE,
* TOUT EN S'ASSURANT QUE LA TAILLE DE LA-DITE JFRAME CORRESPOND A LA TAILLE DE L'IMAGE
*
* COMPRENEZ QUE JE SUIS UN JAVA_NOVICE
*/
package filechooser;
/**
*
* @author RALIMANANA
*/
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
* @author mkyong
*
*/
public class ImageTest22 extends JFrame implements ActionListener {
private JLabel jl1,jl2,jl3,jl4,jl5;
private JTextField jtf1,jtf2;
//private JPasswordField jpf;
private JTextArea jta;
private JButton jb;
private int IMG_WIDTH = 100;
private int IMG_HEIGHT = 100;
private BufferedImage originalImage;
private int type;
private String JTextAreacolor;
private JComboBox jcb1 = new JComboBox();
/* M�thode constructeur de la fen�tre de type JDialog :
* - cr�ation des composants
* - ajout d'un listener au JButton
* - ajout des composants � la fen�tre suivant un FlowLayout
* Par d�faut, le nom du serveur est "localhost" et l'username est "root"
*/
ImageTest22()
{
super();
this.setTitle("Redimension_image");
this.setSize(280,300);
this.setBackground(Color.red);
this.setLocation(new Point(600,100));
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setLayout(new FlowLayout());
jl1=new JLabel("width : ");
jtf1=new JTextField("200",4);
jl2=new JLabel("height:");
jtf2=new JTextField("200",4);
jb=new JButton("Entree");
jb.addActionListener(this);
jta=new JTextArea();
this.add(jl1);
this.add(jtf1);
this.add(jl2);
this.add(jtf2);
this.add(jb);
this.add(jta);
this.add(jcb1);
try{
this.originalImage = ImageIO.read(new File("a:\\Chat00.png"));
this.type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
}catch(IOException e){ System.out.println(e.getMessage()); }
}
/* M�thode de gestion de l'�v�nement de clic sur le bouton "Connexion"
* On r�cup�re le contenu de tous les JTextField et de la JTextArea
* que l'on passe en param�tres aux m�thodes setId et setRequete de la
* classe Testjdbcmysql.
* Une fois les param�tres pass�s, on appelle �galement la m�thode continueSQL
*/
public void actionPerformed(ActionEvent e)
{
String s1=jtf1.getText();
String s2=jtf2.getText();
//int s=Integer.parseInt(s2);
this.IMG_WIDTH=Integer.parseInt(s1);
this.IMG_HEIGHT=Integer.parseInt(s2);
//this.dispose();
this.originalImage = resizeImage(this.originalImage, type);
try{
ImageIO.write(this.originalImage, "png", new File("a:\\jp.png"));
String s3= "image redimensionne:( "+this.IMG_WIDTH+" ; "+this.IMG_HEIGHT + ")";
jta.setText(s3);
} catch(IOException es){System.out.println(es.getMessage()); }
JFrame essai=new JFrame();
loadAndDisplayImage(essai);
}
public void loadAndDisplayImage(JFrame jd) {
try{
jd.setTitle("Connexion SQL");
jd.setSize(280,300);
jd.setLocation(new Point(600,100));
jd.setAlwaysOnTop(true);
BufferedImage originalIw = ImageIO.read(new File("a:\\jp.png"));
jd.setBounds(0, 0, originalIw.getWidth(), originalIw.getHeight());
jd.add(this.jta);
jd.setVisible(true);
Graphics2D g = (Graphics2D)jd.getRootPane().getGraphics();
g.drawImage(originalIw, null, 0, 0);
System.out.println("nnnnnnnnnnnnnnnnnnnnnnnn");
//jd.dispose();
}catch(IOException et){ System.out.println(et.getMessage()); }
}
public static void main(String [] args){
ImageTest22 jd1=new ImageTest22();
jd1.setVisible(true);
}
public BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
public BufferedImage resizeImageWithHint(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
System.out.println("nandalo teto");
return resizedImage;
}
}