Foro de elhacker.net

Programación => Java => Mensaje iniciado por: CAPN en 27 Septiembre 2012, 22:02 pm



Título: mostrar una imagen con un botón en java
Publicado por: CAPN en 27 Septiembre 2012, 22:02 pm
la idea es que ingrese al textfield un numero y me muestre una imagen
lo que ingrese "12" debe ser el nombre de la imagen para que cargue pero no se como implementarse lo al código que tengo gracias por la ayuda


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
public class texto  extends JApplet implements ActionListener
{
    JTextField t1;
    String t2="111";
   
    JLabel l1;
    JButton b1;
     
    private Image img;
    private ImageIcon img2;

   
    public void init()
    {
        Container c=getContentPane();
        c.setLayout(new FlowLayout());
        l1=new JLabel("INGRECE NUEMRO DE IDENTIFICACION ");
        t1=new JTextField(30);
        b1=new JButton("Enviar");
     
        c.add(l1);
        c.add(t1);
        c.add(b1);
        b1.addActionListener(this);
       
        img = getImage( getDocumentBase(),"tux.png");
        img2 = new ImageIcon("src/tux.png");
           
          


    }//init
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==b1)
        {
            l1.setText(t1.getText());
        }
    }
   
 public void paint(Graphics g){
    
 
    
g.drawImage(img, 0, 0, this);

g.drawImage(img, 0, 120, getWidth(),getHeight() - 120, this);
 
img2.paintIcon(this, g, 180, 0);

}
 }   
   
   
   
}