Quando precisei mostrar imagens fiz um label sem texto que possuia um ícone.
Icon icon = new ImageIcon("/caminho/para/imagem");
JLabel label = new JLabel();
label.setIcon(icon);
On Sat, Jun 6, 2009 at 12:48 PM, Luan <[email protected]> wrote:
>
> Galera, não consigo fazer a imagem aparecer de jeito nenhum, aparece
> akela string teste no meio da tela, mas nada de imagem, se eu tento
> fazer algo como como fillrect aparece um retangulo certinho, mas
> qualquer coisa com draw, como drawoval ou drawimage n da certo, alguem
> me ajuda? segue o codigo:
>
> package adm;
>
> import java.awt.Color;
> import java.awt.Graphics;
> import java.awt.Image;
> import java.awt.MediaTracker;
> import java.awt.Toolkit;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.IOException;
>
> import javax.imageio.ImageIO;
> import javax.swing.JButton;
> import javax.swing.JFrame;
> import javax.swing.JOptionPane;
> import javax.swing.JPanel;
> import javax.swing.JScrollBar;
> import javax.swing.JScrollPane;
>
> public class Caracteristicas_Comprador extends JFrame{
>
> JFrame janela = new JFrame("Janela teste");
> JPanel painel = new JPanel();
> JScrollPane scroll = new JScrollPane(painel);
> Graphics graphs;
> String string = "Teste!";
> BufferedImage imagem;
>
> public Caracteristicas_Comprador() {
>
> this.montajanela();
> this.escreve();
> this.carregaImagem();
> }
>
> private void montajanela() {
>
> janela.add(scroll);
> janela.setSize(800,640);
> janela.setVisible(true);
> janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>
> graphs = painel.getGraphics();
> }
>
> private void escreve() {
>
> while(true){
> graphs.setColor(new Color (0,0,0));
> graphs.drawString(string, janela.getWidth()/2,
> janela.getHeight()/
> 2);
> }
> }
>
> private void carregaImagem() {
> try {
> imagem = ImageIO.read(new File("C:\\img1.png"));
> } catch (IOException e) {
> e.printStackTrace();
> }
> graphs.drawImage(imagem, 50, 50, this);
> }
> }
>
> Obrigado
> >
>
--
Flávio Coutinho da Costa
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Comp
2 - Geral" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/comp2-geral?hl=en
-~----------~----~----~----~------~----~------~--~---