09/01/07 15:14
jprog
Allego sotto il codice in cui uso il MediaTracker esso non mi funziona affatto ,nonho capito perchè alla chiamata :
waitForID(0); non si blocca ad aspettare il caricamento ma va avanti come se avesse già caricato tutto, e poi ovviamente non si ridimensionano le finestre e cosivia. Vi prego aiutatemi sono due giorni che ci sbatto la testa.
waitForID(0); non si blocca ad aspettare il caricamento ma va avanti come se avesse già caricato tutto, e poi ovviamente non si ridimensionano le finestre e cosivia. Vi prego aiutatemi sono due giorni che ci sbatto la testa.
package photolabv6; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import javax.media.jai.InterpolationNearest; import javax.media.jai.JAI; import javax.media.jai.PlanarImage; import javax.swing.ImageIcon; import javax.swing.JComponent; import java.awt.*; import java.awt.event.*; import java.awt.image.renderable.ParameterBlock; import javax.swing.JPanel; import javax.swing.event.*; /** * * @author Antonio */ public class DisplayFoto extends JPanel{ /** * */ private Rectangle rett ; private Point corner1 = new Point(0,0); private Point corner2 = new Point(0,0); private int a; private int c; private Image img=null; private int altezzaRidotta; private int larghezzaRidotta; private int formatoGrande; private int formatoPiccolo; private boolean stampa=false; private double doubleAltezzaRidotta; private double doubleLarghezzaRidotta; private boolean pressed1=false; private boolean pressed2=false; private boolean pressed3=false; private boolean cut=false; private int [] vet=new int[4]; static int b=5; private int width; private int heigth; private int [] vettoreCoordinate=new int[4]; private String path; /** Creates a new instance of StampaFoto */ public DisplayFoto(String path) { MediaTracker mt = new MediaTracker(this); img = Toolkit.getDefaultToolkit().getImage(path); mt.addImage(img, 0); try { mt.waitForID(0); img=img.getScaledInstance(800,-1,1); altezzaRidotta=img.getHeight(null); larghezzaRidotta=img.getWidth(null); } catch (InterruptedException ex) { ex.printStackTrace(); } mt.removeImage(img); //image = exImage.getScaledInstance(800,-1,1); MouseInputAdapter m = new RectangleExampleMouseListener(); addMouseListener(m); addMouseMotionListener(m); doubleAltezzaRidotta=altezzaRidotta; doubleLarghezzaRidotta=larghezzaRidotta; } public void paint (Graphics g){ Graphics2D g2=(Graphics2D)g; g2.drawImage(img,5,5,this); a = Math.min(corner1.x,corner2.x); c=Math.min(corner1.y,corner2.y); if(stampa){ if(vet[2]==1){ rett=new Rectangle(a,b,vet[1],vet[0]); g2.draw(rett); }else if(vet[2]==5){ rett=new Rectangle(5,getC(), vet[1],vet[0]); g2.draw(rett); } } if(isCut()){ width = Math.abs(corner1.x -corner2.x); heigth=Math.abs(corner1.y-corner2.y); rett=new Rectangle(a,getC(), width,heigth); g2.draw(rett); } } class RectangleExampleMouseListener extends MouseInputAdapter { public void mousePressed(MouseEvent e) { corner1 = e.getPoint(); corner2 = corner1; repaint(); pressed1=true; } public void mouseDragged(MouseEvent e) { corner2 = e.getPoint(); repaint(); pressed2=true; } public void mouseReleased(MouseEvent e){ pressed3=true; } } public int getAltezzaRidotta() { return altezzaRidotta; } public int getLarghezzaRidotta() { return larghezzaRidotta; } public void setFormatoGrande(int formatoGrande) { this.formatoGrande = formatoGrande; } public void setFormatoPiccolo(int formatoPiccolo) { this.formatoPiccolo = formatoPiccolo; } public void setFormeStampa(int formatoPiccolo,int formatoGrande){ stampa=true; this.formatoGrande=formatoGrande; this.formatoPiccolo=formatoPiccolo; vet=calcolaGrandezze(altezzaRidotta,larghezzaRidotta,formatoPiccolo,formatoGrande); } private int[] calcolaGrandezze(int altezza, int larghezza,int formatoPiccolo,int formatoGrande){ int altezzaReale; int larghezzaReale; double larghezzaMax; double altezzaMax; double n; int i; if(Math.min(altezza,larghezza)==altezza){ altezzaReale=altezza; larghezzaReale=larghezza; }else{ altezzaReale=larghezza; larghezzaReale=altezza; } n=(double)altezzaReale/(double)formatoPiccolo; altezzaMax=n*(double)formatoPiccolo; larghezzaMax=n*(double)formatoGrande; i=1; if(larghezzaReale<larghezzaMax){ i=5; n=(double)larghezzaReale/(double)formatoGrande; altezzaMax=n*(double)formatoPiccolo; larghezzaMax=n*(double)formatoGrande; } int[] a=new int[4]; a[0]=(int)Math.round(altezzaMax); a[1]=(int)Math.round(larghezzaMax); a[2]=i; return a; } public int getA() { return a; } public int getB() { return b; } public int[] getVet() { return vet; } public boolean ristampa(){ if(pressed1&&pressed2&&pressed3){ return true; }else return false; } public void setFinalize(){ pressed1=false; pressed2=false; pressed3=false; //stampa=false; cut=false; repaint(); } public int[] getVettoreCoordinate() { vettoreCoordinate[0]=a; vettoreCoordinate[1]=getC(); vettoreCoordinate[2]=width; vettoreCoordinate[3]=heigth; /* System.out.println(" a : "+a); System.out.println(" c : "+c); System.out.println(" width : "+width); System.out.println(" heigth : "+heigth); */ return vettoreCoordinate; } public boolean isCut() { return cut; } public void setCut(boolean cut) { this.cut = cut; } public boolean isStampa() { return stampa; } public int getC() { return c; } }
aaa