Sunteți pe pagina 1din 3

/*ESTRUCTURA PROYECTO*/

/*INTERFAZ */

//GUI-->INTERFAZ o Formularios

/*

AWT --> Abstract Windows Toolkit

SWING -->Biblíoteca gráfica para java

DISEÑADOR --> tipo de proyecto

*/

package interfaz;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*; //traemos todos los paquetes de la librería

public class Interfaz {

//para trabajar con un objeto ventana debemos

//crear un objeto jframe

JFrame jf = new JFrame();

//agregar elemento u objetos que utilizaremos

//posteriomente en nuestra solución

JButton jb = new JButton("Texto");

JLabel etiqueta = new JLabel("Texto del Label");


//constructor

Interfaz(){

//hacemos un constructor para una instancia

//de nuestra ventana y sus propiedades básicas

jf.setTitle("Mi Primer Formulario Java");

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jf.setSize(300, 400);

jf.setVisible(true); //por defecto es no visible o sea falso

jf.setResizable(false);//no se ajusta el tamaño de la ventana

//acción para el botón

jb.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) {

Interfaz2 form2 = new Interfaz2();

});

//un organizador de elementos

FlowLayout f1 = new FlowLayout();

jf.setLayout(f1);

jf.add(etiqueta);

jf.add(jb);

public static void main(String[] args) {

//instancia del formulario

Interfaz form = new Interfaz();

}
/*INTERFAZ 2 */

package interfaz;

import java.awt.FlowLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

public class Interfaz2 extends JFrame{

JButton jb = new JButton("Texto Botón");

//constructor

Interfaz2(){

this.setTitle("Otro Formulario Java");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setSize(400, 300);

this.setVisible(true);

this.setResizable(false);

this.setLayout(new FlowLayout());

this.add(jb);

S-ar putea să vă placă și