Created
April 23, 2022 22:29
-
-
Save DavidBernalGonzalez/4a392ce9c7b59c85fe80651710b7b601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package interfaces; | |
public class Main { | |
public static void main(String[] args) { | |
MiJFrame miJFrame = new MiJFrame(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package interfaces; | |
import java.awt.BorderLayout; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
public class MiJFrame extends JFrame{ | |
private static final long serialVersionUID = 1L; | |
MiJFrame(){ | |
setTitle("Layout in action: BorderLayout"); | |
setSize(300,300); | |
setVisible(true); | |
setLayout(new BorderLayout()); | |
// Creamos un contenedor de elementos | |
JPanel jpanelTop = new JPanel(); | |
JPanel jpanelSouth = new JPanel(); | |
JPanel jpanelWest = new JPanel(); | |
JPanel jpanelEast = new JPanel(); | |
JPanel jpanelCenter = new JPanel(); | |
// Creo los elementos que vamos a añadir | |
JButton btn1 = new JButton("Btn 1"); | |
JButton btn2 = new JButton("Btn 2"); | |
JButton btn3 = new JButton("Btn 3"); | |
JButton btn4 = new JButton("Btn 4"); | |
JButton btn5 = new JButton("Btn 5"); | |
//Añado los elementos a los contenedores | |
jpanelTop.add(btn1); | |
jpanelEast.add(btn2); | |
jpanelCenter.add(btn3); | |
jpanelWest.add(btn4); | |
jpanelSouth.add(btn5); | |
//Posiciono los elementos en el JFrame | |
add(jpanelTop, BorderLayout.NORTH); | |
add(jpanelEast, BorderLayout.EAST); | |
add(jpanelCenter, BorderLayout.CENTER); | |
add(jpanelWest, BorderLayout.WEST); | |
add(jpanelSouth, BorderLayout.SOUTH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment