Chamei uma janela depois do FileDialog

Então, tenho uma janela aqui, aí eu chamo uma imagem com um FileDialog, só que depois do FIleD gostaria de abrir a imagem em outra janela no canto da tela, a janela eu njá abri, mas naum ta aparecendo a imagem dentro dela…

[code]public void actionPerformed(ActionEvent e) {

   	    fd.show();
	  	if(fd.getFile()!= null){
	  			lbcaminho.setText(fd.getDirectory()+fd.getFile());
	  			imfoto = tk.getImage(lbcaminho.getText());
	  			

	  			new JnFoto().show();
	  			  			  	}		 
	   	}[/code]

Tenho a minha Janela Principal (JnPrincipal) e no ActionPerformed chamo o FD e depois de escolher a imagem no FD abre a minha outra janela (JnFoto),

[code]public class JnFoto extends JFrame implements ActionListener {

private Container thisContentPane;
private Image imfoto;

public JnFoto() {
    setTitle("Foto");
	thisContentPane = this.getContentPane();
    thisContentPane.setLayout(null);

    
    this.setSize(200, 200);
    // panel.add(imfoto);
    this.show();        

}
    public void paint(Graphics g){
       	JLabel lbl = new JLabel("Olá");
    	JnPrincipal princ  = new JnPrincipal();
    	super.paint(g);
    	if(imfoto != null){		
    		Dimension apl = getSize();
    		imfoto = imfoto.getScaledInstance(
    				
    		this.getWidth(), this.getHeight(), 10);
    					
    		MediaTracker media = new MediaTracker(this);
            media.addImage(imfoto, 0);
            try {
                media.waitForID(0);
            } catch (InterruptedException ie) {
            }
            g.drawImage(imfoto, 0, 280, 150, 150, this);     
            this.imfoto = princ.imfoto;
           repaint(); // Será q se comentar o repaint() tbem funciona?!
           
    		}
    }[/code]

Pq num ta abrindo a IMAGEM nela??
a tela aparece em BRANCO…
Alguem ajudaaa aeee…
Vlw.

Vc precisa iniciar a imagem para DEPOIS fazer show() na janela

Então no meu ActionPerfomr…
antes do this.show();

eu tenho que chamar a imagem??
Mas como que eu faço isso???
tenhu q chamar o Metodo Paint??

Cara, tava olhando seu código com calma e acho q te falei besteira…
fd é o seu Filedialog né!

Então a imagem não aparece porque ela não acabou de carregar… Tipo, seu progrma começa a carregar a imagem e continua a execução, não espera q a imagem esteja totalmente carregada…
Pra resovler isso vc precisa usar uma classe chamada MediaTracker

Dá uma pesquisada sobre MediaTracker no google que tem bastante coisa…

Abraço!

Vixiii, vou ter que coloca mais um MediaTracker, pq no metodo paint já tem um …
vc pode então me dizer onde é que tenho q coloca esse outro ??
Obrigado viu cara…
:smiley:

logo após a linha

imfoto = tk.getImage(lbcaminho.getText());

Testa ai e diz se funcionou :slight_smile:

Aí…eu coloquei o método paint depois, pra não fazer um new MediaTracker…
tipo, o que ta falatando agora é fazer com que ela abra na outra janela, pq eu testei aki, e ela abre na janela principal, só naum abre na outra…

deixei assim depois do tk.

[code]public class JnPrincipal extends JFrame implements ActionListener {
//ConectBanco bd = new ConectBanco();

PicturePanel pp = new PicturePanel();
private JTabbedPane tabs;
Image imfoto;
private JButton btAnt;
private JButton btProx;
private JButton btAbrir;
private Toolkit tk = Toolkit.getDefaultToolkit();
private FileDialog fd = new FileDialog(this, "Selecione a Imagem: ");
private JLabel lbcaminho = new JLabel();
private JLabel lbimagem = new JLabel(); 

public JnPrincipal(){
	super("Janela Principal");
//	this.setResizable(false);
	//ABA 1
	
	
	 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	         Dimension frameSize = getSize();
	         this.setLocation(new Point((screenSize.width - frameSize.width) / 5,
	                 (screenSize.height - frameSize.width) / 5));
	         

	tabs = new JTabbedPane();
	JPanel panel = new JPanel();
	ImageIcon icon = new ImageIcon("diam-verm.gif");
	JLabel lbnome = new JLabel("Nome: ");
		JTextField tfnome = new JTextField(20);
	JLabel lbcidade = new JLabel("Cidade: ");
		JTextField tfcidade = new JTextField(30);
	JLabel lbcontato = new JLabel("Contato: ");
		JTextField tfcontato = new JTextField(30);
	JLabel lbrg = new JLabel("RG: ");
		JTextField tfrg = new JTextField(10);
	JLabel lbfone = new JLabel("Telefone: ");
		JTextField tffone = new JTextField(11);
	JLabel lbemail = new JLabel("E-mail: ");
		JTextField tfemail = new JTextField(30);
	JLabel lbend = new JLabel("Endereço: ");
		JTextField tfend = new JTextField(30);
	JLabel lbfoto = new JLabel("Foto: ");
	
	//ImageIcon iifoto = new ImageIcon(imfoto);
	//lbcaminho = new JLabel(iifoto);
	

			
	/*
	 response.setContentType("image/png");
	 OutputStream os = response.getOutputStream();
	 ImageIO.write(buffer, "png", os);
	 os.close();  

*/

	//====ADD===
	panel.add(lbnome);
	panel.add(tfnome);
	panel.add(lbcidade);
	panel.add(tfcidade);
	panel.add(lbcontato);
	panel.add(tfcontato);	
	panel.add(lbrg);
	panel.add(tfrg);
	panel.add(lbfone);
	panel.add(tffone);
	panel.add(lbend);
	panel.add(tfend);
	panel.add(lbemail);
	panel.add(tfemail);
	panel.add(lbfoto);	
	panel.add(btAbrir = new JButton("Abrir"),"West");
	panel.add(lbcaminho);
	panel.checkImage(imfoto, 150, 150, this);		
	
	
	btAbrir.addActionListener(this);
	//addWindowListener(new CloseAndExit());
		
	//ta.setLineWrap(true); ta.setWrapStyleWord(true);
	tabs.addTab("Entrada", new ImageIcon("diam-azul.gif"), panel);
	
	//ABA 2	
	JPanel panel2 = new JPanel();
	panel2.setBackground(Color.white);
	tabs.addTab("Saída", new ImageIcon("diam-lilas.gif"), panel2);
	//ABA 3
	panel = new JPanel();
	panel.add(new JLabel("Teste"));
	tabs.addTab("Relatorio", new ImageIcon("diam-azul.gif"), panel);
	//ABA 4
	JPanel panel4 = new JPanel();
	tabs.addTab("Localizar", new ImageIcon("diam-verde.gif"), panel4);
	getContentPane().add(tabs, "Center");
	//Painel de COntrole
	JPanel p1 = new JPanel(), p2 = new JPanel(new GridLayout(1,1,1,1));
	p2.add(btAnt = new JButton("Anterior"));
	p2.add(btProx = new JButton("Próximo"));
	p1.add(p2);
	getContentPane().add(p1, "North");
	btAnt.addActionListener(this);
	btProx.addActionListener(this);
	setSize(400,400);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
}

public void actionPerformed(ActionEvent e) {

	  //	PicturePanel pp = new PicturePanel();
   	    fd.show();
	  	if(fd.getFile()!= null){
	  			lbcaminho.setText(fd.getDirectory()+fd.getFile());
	  			imfoto = tk.getImage(lbcaminho.getText());}

}
public void paint(Graphics g){
JnPrincipal princ = new JnPrincipal();
super.paint(g);
if(imfoto != null){
Dimension apl = getSize();
imfoto = imfoto.getScaledInstance(

	  		    		this.getWidth(), this.getHeight(), 10);
	  		    					
	  		    		MediaTracker media = new MediaTracker(this);
	  		            media.addImage(imfoto, 0);
	  		            try {
	  		                media.waitForID(0);
	  		            } catch (InterruptedException ie) {
	  		            }
	  		           
	  		      
	  			new JnFoto().show();
	  				  				  		 			 
	  	}		 
	   	}

	
public static void main(String[] args){
new JnPrincipal().show();
		
}

// TODO Auto-generated method stub

	}[/code]

Isso aí é todo o código da Janela Principal…
se eu colocar essas duas linhas a imagem aparece nela:

g.drawImage(imfoto, 0, 280, 150, 150, this); this.imfoto = princ.imfoto;

aí quando eu tiro, não aparece em nenhuma das duas…hehe

éee…só falta msm, add a imagem na outra janela,pq chamar já chamou neh!!!

ainda naum consegui…
alguem tem mais alguma dica ae??
=/
vlw galera