NOMBRE:
José de Jesús Gaytán Ramírez
MAESTRO(A):
Ing. Luis Eduardo Gutiérrez Ayala
MATERIA:
Tópicos Avanzados de Programación (TAP)
SEMESTRE:
4to
CARRERA:
Sistemas Computacionales
HORA:
Martes y jueves 10:30-12:15
Viernes 11:20-12:10
AULA:
C-C-LC1
Redacción del problema
Realizar un código que muestre una interfaz grafica con la distribucion de Border Layout en
el JFrame y también en el Panel central. Coloque imágenes en las áreas norte, sur, este y
oeste del Jframe.
En el panel Central que también tiene la distribución de Border, colocar etiquetas con los
nombres de sus áreas correspondientes. P.e. en el borde ubicado al norte colocar la
etiqueta "NORT".
Código fuente
clase
package paka;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Locale;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Igu {
private JFrame ventana;
private JPanel panelN, panelS, panelE, panelO, panelC;
private JLabel lbl_norte, lbl_sur, lbl_este, lbl_oeste;
private JLabel etiqN, etiqS, etiqE, etiqO;
private ImageIcon fondoN, fondoS, fondoE, fondoO;
private Icon iconN, iconS, iconE, iconO;
//constructor inicializa los componentes
public Igu() {
ventana = new JFrame("Interfaz con uso de BorderLayout");
panelN = new JPanel();
panelS = new JPanel();
panelE = new JPanel();
panelO = new JPanel();
panelC = new JPanel();
lbl_norte = new JLabel("NORTE");
lbl_sur = new JLabel("SUR");
lbl_este = new JLabel("ESTE");
lbl_oeste = new JLabel("OESTE");
etiqN = new JLabel();
fondoN = new ImageIcon("/G:/TAP/topicos1/src/paka/imagenes/norte.jpg");
iconN = new ImageIcon(fondoN.getImage().getScaledInstance(200, 100, 0)) {};
etiqN.setIcon(iconN);
etiqS = new JLabel();
fondoS = new ImageIcon("/G:/TAP/topicos1/src/paka/imagenes/sur.jpg");
iconS = new ImageIcon(fondoS.getImage().getScaledInstance(200, 100, 0));
etiqS.setIcon(iconS);
etiqE = new JLabel();
fondoE = new ImageIcon("/G:/TAP/topicos1/src/paka/imagenes/este.jpg");
iconE = new ImageIcon(fondoE.getImage().getScaledInstance(200, 100, 0));
etiqE.setIcon(iconE);
etiqO = new JLabel();
fondoO = new ImageIcon("/G:/TAP/topicos1/src/paka/imagenes/oeste.jpg");
iconO = new ImageIcon(fondoO.getImage().getScaledInstance(200, 100, 0));
etiqO.setIcon(iconO);
this.atributos();
this.armado();
this.escuchas();
this.lanzar_IGU();
}
//Atributos de los componentes
public void atributos(){
ventana.setSize(800, 400);
ventana.setResizable(true);
ventana.setLayout(new BorderLayout(5, 5));
panelN.setBackground(Color.green);
panelS.setBackground(Color.red);
panelE.setBackground(Color.red);
panelO.setBackground(Color.green);
panelC.setBackground(Color.yellow);
panelC.setLayout(new BorderLayout(5, 5));
lbl_norte.setForeground(Color.DARK_GRAY);
lbl_sur.setForeground(Color.darkGray);
lbl_este.setForeground(Color.darkGray);
lbl_oeste.setForeground(Color.darkGray);
}
//Armar la interfaz
public void armado(){
ventana.add(panelN, BorderLayout.NORTH);
ventana.add(panelS, BorderLayout.SOUTH);
ventana.add(panelE, BorderLayout.EAST);
ventana.add(panelO, BorderLayout.WEST);
ventana.add(panelC, BorderLayout.CENTER);
panelN.add(etiqN);
panelS.add(etiqS);
panelE.add(etiqE);
panelO.add(etiqO);
panelC.add(lbl_norte, BorderLayout.NORTH);
panelC.add(lbl_sur, BorderLayout.SOUTH);
panelC.add(lbl_este, BorderLayout.EAST);
panelC.add(lbl_oeste, BorderLayout.WEST);
}
//Asignar los escuchas
public void escuchas(){
//vacio
}
//Lanzar la interfaz
public void lanzar_IGU(){
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setLocationRelativeTo(null);
ventana.setVisible(true);
}
}
Clase Main
package paka;
public class PruebaIgu {
public static void main(String[] args) {
Igu ventana1 = new Igu();
}
}
Captura de pantalla del funcionamiento del código