1. INFORME
ESTUDIANTE: GONZALO FARINANGO M. SEMESTRE: SEGUNDO
PARALELO: C PRÁCTICA:19
TEMA:
Desarrollo de nuestro primer programa
OBJETIVO:
-Conocer el desarrollo de un programa en “Eclipse”, para este desarrollo
tendremos que comprender lo que son los formularios en Windows builder.
RESULTADOS DE APRENDIZAJE
-Comprensión de la aplicación de Eclipse.
-Uso correcto del código que aplicaremos en Eclipse.
-Aprender el uso correcto de los formularios
ACTIVIDADES:
-Realizar un programa en el que ingrese 1 label que contenga una imagen, 3
botones, uno que me permita ocultar la imagen, otro que visibilice la imagen y
otro para salir del formulario
DESARROLLO DE CONTENIDOS
1. Abrir ECLIPSE.
UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD DE FILOSOFIA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
CARRERA DE LA PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES
DE LA INFORMÁTICA
2. 2. Seleccionar la dirección en la que queramos guardar nuestro proyecto, en
este caso lo vamos a guardar en Escritorio (Desktop).
3. Creamos un proyecto nuevo de Java.
4. Le ponemos un nombre a nuestro proyecto y le damos clic en Finish.
3. 5. Dentro de nuestro nuevo proyecto crearemos un JFrame, le pondremos
cualquier título.
6. Al crear un JFrame nos aparecerá el siguiente código, aquí podemos empezar a
programar
7. Debemos ir a Design para entrar al formulario
4. 8. Una vez que ingresemos al formulario podemos hacer las modificaciones que
necesitemos
9. Pondremos 1 label que contenga una imagen , y 4 botones, uno que diga cambiar
visible, otro que diga ocultar, otro de regresar y otro de salir
10. En el botón de visible ingresaremos el siguiente código, el cual nos va a permitir
visibilizar la imagen.
JButton btnNewButton = new JButton("VISIBLE");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblNewLabel.setVisible(true);
}
11. En el botón de ocultar ingresaremos el siguiente código, el cual nos va a permitir
ocultar la imagen
JButton btnNewButton_1 = new JButton("OCULTAR");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblNewLabel.setVisible(false);
}
12. En el botón de salir ingresaremos el siguiente código, el cual nos va a permitir
Salir del formulario.
JButton btnNewButton_1 = new JButton("SALIR");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
5. System.exit(WIDTH);
}
13. En el botón de regresar ingresaremos el siguiente código, el cual nos va a permitir
Salir del formulario.
JButton btnNewButton_3 = new JButton("REGRESAR");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Form4 verForm4=new Form4 ();
verForm4.setVisible(true);
Form2.this.dispose();
12. Por último utilizaremos el botón para correr el programa.
13.- Si damos clic ocultar, se nos ocultará la imagen
14.- Si le damos visible, se nos aparecerá la imagen
14.- Si le damos click en SALIR se saldrá del programa
6. 11.- Por último, dejaré la línea de código que utilicé. En el proyecto operación
utilicé el siguiente código:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
public class form3 extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
form3 frame = new form3();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public form3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(Color.CYAN);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(new
ImageIcon("C:UsersmiltoDesktopUCE_SEGUNDO SEMESTRESELLOS
UNIVERSITARIOS EN PNGEscudo_de_la_Universidad_Central_del_Ecuador.png"));
lblNewLabel.setBounds(88, 11, 200, 125);
contentPane.add(lblNewLabel);
JButton btnNewButton = new JButton("VISIBLE");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblNewLabel.setVisible(true);
}
});
btnNewButton.setBounds(10, 147, 89, 23);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("OCULTAR");