Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
51 views6 pages

Tarea # 11 GridBagLayout

This document contains code for a Java program that creates a graphical user interface (GUI) using the GridBagLayout. It defines classes and methods to initialize components like buttons and frames, set attributes of the GridBagConstraints, add the components to the frame using the constraints, and launch the GUI. The code provides an example of using GridBagLayout to distribute buttons across the interface in a grid-like fashion.

Uploaded by

Jesus Gaytan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

Tarea # 11 GridBagLayout

This document contains code for a Java program that creates a graphical user interface (GUI) using the GridBagLayout. It defines classes and methods to initialize components like buttons and frames, set attributes of the GridBagConstraints, add the components to the frame using the constraints, and launch the GUI. The code provides an example of using GridBagLayout to distribute buttons across the interface in a grid-like fashion.

Uploaded by

Jesus Gaytan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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
Crea una interfaz gráfica donde muestres el uso del GridbagLayout y donde coloques una
serie de botones distribuidos.
Clase Main con interfaz
package GridBagLayout;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class GBL {


private JFrame ventana;
private JPanel panel;
private JButton bot1, bot2, bot3, bot4, bot5,
bot6, bot7, bot8, bot9, bot10;
private GridBagConstraints gbc1, gbc2, gbc3, gbc4, gbc5,
gbc6, gbc7, gbc8, gbc9, gbc10;
//constructor inicializa los componentes
public GBL() {
ventana = new JFrame("Uso de GridBagLayout");
gbc1 = new GridBagConstraints();
gbc2 = new GridBagConstraints();
gbc3 = new GridBagConstraints();
gbc4 = new GridBagConstraints();
gbc5 = new GridBagConstraints();
gbc6 = new GridBagConstraints();
gbc7 = new GridBagConstraints();
gbc8 = new GridBagConstraints();
gbc9 = new GridBagConstraints();
gbc10 = new GridBagConstraints();
bot1 = new JButton("boton 1");
bot2 = new JButton("boton 2");
bot3 = new JButton("boton 3");
bot4 = new JButton("boton 4");
bot5 = new JButton("boton 5");
bot6 = new JButton("boton 6");
bot7 = new JButton("boton 7");
bot8 = new JButton("boton 8");
bot9 = new JButton("boton 9");
bot10 = new JButton("boton 10");

this.atributos();
this.armado();
this.lanzar_IGU();
}
//Atributos de los componentes
public void atributos() {
ventana.setSize(400, 200);
ventana.setResizable(true);
ventana.setLayout(new GridBagLayout());
gbc1.fill = GridBagConstraints.HORIZONTAL;
gbc1.gridx = 0;
gbc1.weighty = 0;
gbc1.gridy = 0;
gbc2.fill = GridBagConstraints.HORIZONTAL;
gbc2.gridx = 1;
gbc2.weighty = 0;
gbc2.gridy = 0;
gbc3.fill = GridBagConstraints.HORIZONTAL;
gbc3.gridx = 2;
gbc3.weighty = 0;
gbc3.gridy = 0;
gbc4.fill = GridBagConstraints.HORIZONTAL;
gbc4.gridx = 3;
gbc4.weighty = 0;
gbc4.gridy = 0;
gbc5.fill = GridBagConstraints.HORIZONTAL;
gbc5.gridx = 0;
gbc5.weightx = 1;
gbc5.gridwidth = 4;
gbc5.gridy = 1;
gbc6.fill = GridBagConstraints.HORIZONTAL;
gbc6.gridx = 0;
gbc6.weightx = 1;
gbc6.gridwidth = 3;
gbc6.gridy = 2;
gbc7.fill = GridBagConstraints.HORIZONTAL;
gbc7.gridx = 3;
gbc7.weightx = 1;
gbc7.gridy = 2;
gbc8.fill = GridBagConstraints.BOTH;
gbc8.gridwidth = 1;
gbc8.weightx = 1;
gbc8.weighty = 1;
gbc8.gridheight = 2;
gbc8.gridx = 0;
gbc8.gridy = 3;
gbc9.fill = GridBagConstraints.HORIZONTAL;
gbc9.gridx = 1;
gbc9.weightx = 1;
gbc9.gridwidth = 3;
gbc9.gridy = 3;
gbc10.fill = GridBagConstraints.BOTH;
gbc10.gridx = 1;
gbc10.gridwidth = 3;
gbc10.weightx = 1;
gbc10.gridy = 4;
}
//Armar la interfaz
public void armado() {
ventana.add(bot1, gbc1);
ventana.add(bot2, gbc2);
ventana.add(bot3, gbc3);
ventana.add(bot4, gbc4);
ventana.add(bot5, gbc5);
ventana.add(bot6, gbc6);
ventana.add(bot7, gbc7);
ventana.add(bot8, gbc8);
ventana.add(bot9, gbc9);
ventana.add(bot10, gbc10);
}
//Lanzar la interfaz
public void lanzar_IGU() {
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setLocationRelativeTo(null);
ventana.setVisible(true);
}
public static void main(String[] args) {
new GBL();
}
}

Captura de pantalla del funcionamiento del programa

You might also like