Ho provato a fare come mi hai detto ma non mi funziona....allora ho prima di tutto creato questa classe:
Codice PHP:
public class ResolutionCheck implements DocumentListener {
int height,width;
public ResolutionCheck(String tmpImg){
ImageIcon tmpImg_icon;
Image image;
tmpImg_icon = new ImageIcon(tmpImg);
image = tmpImg_icon.getImage();
this.height = tmpImg_icon.getIconHeight();
this.width = tmpImg_icon.getIconWidth();
System.out.println("Listener Created:");
}
public void changedUpdate(DocumentEvent e) { System.out.println("changedUpdate");}
public void insertUpdate(DocumentEvent e) {
System.out.println("insertUpdate");
changeResolution(new Integer(myself.text3.getText()).intValue(),new Integer(myself.text4.getText()).intValue());
}
public void removeUpdate(DocumentEvent e) {
System.out.println("removedUpdate");
changeResolution(new Integer(myself.text3.getText()).intValue(),new Integer(myself.text4.getText()).intValue());
}
void changeResolution(int nheight,int nwidth){
double nRatio = (double)nwidth / (double)nheight;
double imageRatio = (double)width / (double)height;
if (nRatio < imageRatio) {
nheight = (int)(nwidth / imageRatio);
myself.text4.setText(""+nheight);
}
else {
nwidth = (int)(nheight * imageRatio);
myself.text3.setText(""+nwidth);
}
System.out.println(nwidth+"x"+nheight);
}
}
poi ho inserito nella classe principale della gui questo codice
Codice PHP:
ResolutionCheck res = new ResolutionCheck(file.getPath());;
text3.getDocument().addDocumentListener(res);
text4.getDocument().addDocumentListener(res);
pero' quando modifico il testo dei TextField non succede nulla, nn stampa nemmeno l'out sul terminale.....quindi suppongo che non venga proprio richiamato il listener....cosa ho sbagliato?????