Java - como puedo agregar una imagen a un jlabel que esta dentro de un segundo jpanel

 
Vista:

como puedo agregar una imagen a un jlabel que esta dentro de un segundo jpanel

Publicado por eliza (2 intervenciones) el 12/07/2012 16:18:35
Hola a todos, de antemano muchas gracias por su ayuda. Soy nueva en programacion y me he encontrado con un problema al crear dos jpanel , bueno en el panel principal pude agregarle una imagen pero en el otro jpanel no se puede lo he intentado de todas las maneras posibles y nada. Bueno lo que tengo q hacer es ponerle una imagen de fondo en el segundo jpanel y en otros mas que tengo que crear ..... aqui les mando mi codigo haber si me dan una ayudita por favor ... se los agradeceria mucho.
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;

public class PagoVentas1 extends JApplet implements ActionListener {
JButton boton, boton2, boton3, boton4, boton5, boton6, boton7;
JLabel lblImagen, lblImagen2, lblImagen3, lbltitulo, lbltitulo2, lbltitulo3, lbltexto1, lbltexto2, lbltexto3, imagenes;
Label lbltitulo4, lbltitulo5, lbltexto4, lbltexto5, lbltexto6, lbltexto7;
JPanel pnl1, pnl2, pnl3;
Label lblceleste, lblceleste2;
JTextArea txtexto, txtresul, texto1;
JScrollPane scp;
JScrollPane scp3;

JScrollPane scp1;

public void init() {


setSize(1020,800);

pnl2=new JPanel();
pnl2.setBackground(new Color(34,20,100,40));
pnl2.setLayout(null);
pnl2.setVisible(false);
pnl2.setBounds(0,0,1200,800);
getContentPane().add(pnl2);

pnl1= new JPanel();
pnl1.setBounds(0,0,1200,800);
pnl1.setVisible(true);
pnl1.setBackground( new Color(100,15,150));
pnl1.setLayout(null);
getContentPane().add(pnl1);

pnl3= new JPanel();
pnl3.setBounds(0,0,1200,800);
pnl3.setVisible(false);
pnl3.setLayout(null);
pnl3.setBackground(new Color(34,20,100,40));
getContentPane().add(pnl3);

boton=new JButton("Link 1");
boton.setBounds(300,450,145,20);
boton.setBackground(new Color(255, 150, 190));
boton.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton.setForeground(new Color(150,120,255));
boton.addActionListener(this);
pnl2.add(boton);

boton2=new JButton("Link 2");
boton2.setBounds(300,490,145,20);
boton2.setBackground(new Color(255, 150, 190));
boton2.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton2.setForeground(new Color(150,120,255));
pnl2.add(boton2);
boton2.addActionListener(this);

boton3=new JButton("Link 3");
boton3.setBounds(300,530,145,20);
boton3.setBackground(new Color(255, 150, 190));
boton3.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton3.setForeground(new Color(150,120,255));
pnl2.add(boton3);
boton3.addActionListener(this);

boton4=new JButton("CURRICULUM VITAE");
boton4.setBounds(300,530,155,20);
boton4.setBackground(new Color(255, 150, 190));
boton4.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton4.setForeground(new Color(150,120,255));
pnl1.add(boton4);
boton4.addActionListener(this);

boton5=new JButton("Atras");
boton5.setBounds(800,600,145,20);
boton5.setBackground(new Color(255, 150, 190));
boton5.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton5.setForeground(new Color(150,120,255));
pnl2.add(boton5);
boton5.addActionListener(this);

boton6=new JButton("Preferencias");
boton6.setBounds(300,600,145,20);
boton6.setBackground(new Color(255, 150, 190));
boton6.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton6.setForeground(new Color(150,120,255));
pnl1.add(boton6);
boton6.addActionListener(this);

boton7=new JButton("Atras");
boton7.setBounds(100,200,145,20);
boton7.setBackground(new Color(255, 150, 190));
boton7.setFont(new Font("Britannic Bold",Font.ITALIC,14 ));
boton7.setForeground(new Color(150,120,255));
pnl3.add(boton7);
boton7.addActionListener(this);



lbltitulo=new JLabel("TODO");
lbltitulo.setBounds(50,30,550,60);
lbltitulo.setForeground(new Color(150,120,255));
lbltitulo.setFont(new Font("COMIC SANS MS", Font.BOLD,70));
pnl1.add(lbltitulo);

lbltitulo2=new JLabel("SOBRE");
lbltitulo2.setBounds(50,90,550,60);
lbltitulo2.setForeground(new Color(150,120,255));
lbltitulo2.setFont(new Font("COMIC SANS MS", Font.BOLD,70));
pnl1.add(lbltitulo2);

lbltitulo3=new JLabel("ELIZA");
lbltitulo3.setBounds(50,160,550,60);
lbltitulo3.setForeground(new Color(150,120,255));
lbltitulo3.setFont(new Font("COMIC SANS MS", Font.BOLD,70));
pnl1.add(lbltitulo3);

lbltitulo4=new Label("CURRICULUM VITAE");
lbltitulo4.setBackground(new Color(150,120,255));
lbltitulo4.setBounds(200,10,600,100);
lbltitulo4.setForeground(new Color(255, 150, 190));
lbltitulo4.setFont(new Font("COMIC SANS MS", Font.BOLD,70));
pnl2.add(lbltitulo4);



lbltexto1=new JLabel("Hola soy Eliza, tengo 21 años y estoy en la universidad.");
lbltexto1.setBounds(225,300,1550,100);
lbltexto1.setForeground(new Color(150,120,255));
lbltexto1.setFont(new Font("COMIC SANS MS", Font.BOLD,20));
pnl1.add(lbltexto1);

lbltexto2=new JLabel("He abierto es miniblog para quienes quieran conocerme y tambien");
lbltexto2.setBounds(225,320,1550,100);
lbltexto2.setForeground(new Color(150,120,255));
lbltexto2.setFont(new Font("COMIC SANS MS", Font.BOLD,20));
pnl1.add(lbltexto2);

lbltexto3=new JLabel("puedan conocer mas de mi, de mi vida y comenzamos aqui:");
lbltexto3.setBounds(225,340,1550,100);
lbltexto3.setForeground(new Color(150,120,255));
lbltexto3.setFont(new Font("COMIC SANS MS", Font.BOLD,20));
pnl1.add(lbltexto3);

texto1= new JTextArea("DATOS PERSONALES"+"\nNombres y Apellidos: Elizabeth Cinthia Huaracha Aguilar"
+"\nEstado Civil: Soltera"+"\nDomicilio: Atte urb.'Los Sauces' Lt.15"+"\nMovil:994735628 DNI:47184545 Edad: 21"
+"\n"+"\nINFORMACION ACADEMICA"+"\nNivel Alcanzado: Estudiante Universitaria"+"\nCentro de Estudios:UNIVERSIDAD PERUANA LOS ANDES"
+"\n"+"\nCONOCIMIENTOS"+"\n-Nivel Basico en JAVA"+"\n-Diseño Grafico"+"\n-OFFICE"+"\n-Ensamblaje y Reparacion de PC"
+"\n"+"\nEXPERIENCIA LABORAL"+"\n-Cajera en tienda"+"\n-Atencion al cliente");
scp1=new JScrollPane(texto1);
scp1.setBounds(20,100,1000,350);
texto1.setBackground(new Color(150,120,255));
texto1.setFont(new Font("ARIAL", Font.BOLD,14));
texto1.setForeground(new Color(255, 150, 190));
texto1.setEditable(false);
pnl2.add(scp1);

imagenes= new JLabel();
scp3=new JScrollPane(imagenes);
scp3.setBackground(new Color(150,120,255));
scp3.setBounds(20,100,500,280);
imagenes.setIcon(new ImageIcon(getClass().getResource("yosoy.jpg")));
pnl2.add(scp3);

lblceleste=new Label();
lblceleste.setBounds(0,0,2000,800);
lblceleste.setBackground(new Color(150,120,255));
pnl2.add(lblceleste);

lblceleste2=new Label();
lblceleste2.setBounds(0,0,2000,800);
lblceleste2.setBackground(new Color(150,120,255));
pnl3.add(lblceleste2);

lblImagen2=new JLabel();
lblImagen2.setBounds(700,60,300,250);
lblImagen2.setIcon(new ImageIcon(getClass().getResource("yosoy.jpg")));
pnl1.add(lblImagen2);

lblImagen=new JLabel();
lblImagen.setBounds(0,0,2000,800);
lblImagen.setIcon(new ImageIcon(getClass().getResource("cadena.jpg")));
pnl1.add(lblImagen);



txtresul= new JTextArea();
scp=new JScrollPane(txtresul);
scp.setBounds(40,380,670,280);
txtresul.setBackground(Color.YELLOW);
scp.setFont(new Font("Comic Sams MS", Font.BOLD,14));
txtresul.setForeground(Color.blue );
pnl1.add(scp);

}
public void actionPerformed(ActionEvent e) {

if(e.getSource().equals(boton)){
try
{
URL u=new URL("http://www.lawebdelprogramador.com");
getAppletContext().showDocument(u);
}

catch(MalformedURLException ex)
{
System.err.println(ex);
}
}

if(e.getSource().equals(boton2)){
try
{
URL a=new URL("http://www.javatutoriales.com");
getAppletContext().showDocument(a);
}

catch(MalformedURLException ex)
{
System.err.println(ex);
}
}

if(e.getSource().equals(boton3)){
try
{
URL m=new URL("http://www.lawebdelprogramador.com");
getAppletContext().showDocument(m);
}

catch(MalformedURLException ex)
{
System.err.println(ex);
}
}

if(e.getSource()==boton4){

pnl2.setVisible(true);
pnl1.setVisible(false);

}

if(e.getSource()==boton5){

pnl2.setVisible(false);
pnl1.setVisible(true);

}

if(e.getSource()==boton6){

pnl3.setVisible(true);
pnl1.setVisible(false);

}

if(e.getSource()==boton7){

pnl3.setVisible(false);
pnl1.setVisible(true);

}

}



}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder