Más contenido relacionado
Más de Nana Rodrigez (20)
P2
- 1. IngenieríaenAnimación Digital
y EfectosVisuales
Asignatura: ProgramaciónOrientadaaObjetos
Profesor: ISC.LizbethHernándezOlán
UnidadIII HERENCIA Fecha: Abril28-2017
Practica DemoLabel Página 1 de2
No.Control 16081834 NombredelAlumno RodriguezEsquivel,AnaKaren
1.EnunciadodelProblema.
Creauniconoapartirdeunaimagen,parapodercolocarlaenunobjetoJLabel.
2.CódigoFuente:
//RodriguezEsquivel,AnaKaren Práctica2 16081834
//Fig9.19:DemoLabel.java
//Demuestraelusodeetiquetas.
importjava.awt.BorderLayout;
importjavax.swing.ImageIcon;
importjavax.swing.JLabel;
importjavax.swing.JFrame;
publicclassDemoLabel
{
publicstaticvoidmain(Stringargs[])
{
//Creaunaetiquetacontextosolamente
JLabeletiquetaNorte=newJLabel("Norte");
//creauniconoapartirdeunaimagen,parapodercolocarlaenunobjetoJLabel
ImageIconetiquetaIcono=newImageIcon("SPACE.jpg");
//creaunaetiquetaconuniconoenvezdetexto
JLabeletiquetaCentro=newJLabel(etiquetaIcono);
//creaotraetiquetaconunicono
JLabeletiquetaSur=newJLabel(etiquetaIcono);
//establecelaetiquetaparamostrartexto(asícomounicono)
etiquetaSur.setText("Sur");
//creaunmarcoparacontenerlasetiquetas
JFrameaplicacion=newJFrame();
aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//agregalasetiquetasalmarco;elsegundoargumentoespecifica
//enquépartedelmarcosevaaagregarlaetiqueta
aplicacion.add(etiquetaNorte,BorderLayout.NORTH);
aplicacion.add(etiquetaCentro,BorderLayout.CENTER);
aplicacion.add(etiquetaSur,BorderLayout.SOUTH);
aplicacion.setSize(300,300);//estableceeltamañodelmarco
aplicacion.setVisible(true);//muestraelmarco
}//findemain
}//findelaclaseDemoLabel