1. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
GUÍA DE USO DE LABORATORIOS
ESTUDIANTE: Haro Jesus – Morocho Johnny – Oscullo Carlos
SEMESTRE: Séptimo PARALELO: “B”
PRÁCTICA #: 12
FECHA: 21/01/2020
TEMA: FORMULARIO (Juego del ahorcado)
OBJETIVO:
Realizar un programa que me permita simular el juego del ahorcado, utilizando la sentencia
FOR, IF y la creación de formulario.
RESULTADOS DE APRENDIZAJE
Los estudiantes desarrollarán la habilidad de crear y utilizar formularios.
ACTIVIDADES:
1. Realizar un programa que me permita simular el juego del ahorcado, utilizando la
sentencia FOR, IF y la creación de formulario.
DESARROLLO DEL CONTENIDO
1. Realizar un programa que me permita simular el juego del ahorcado,
utilizando la sentencia FOR, IF y la creación de formulario.
package ahorcado;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ahorcado extends javax.swing.JFrame {
//Visor de imagen
String imagenes[] = {
"C:UsersLab6_PC07Desktopiconiconahorcado_0.jpg",
2. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
"C:UsersLab6_PC07Desktopiconiconahorcado_1.jpg",
"C:UsersLab6_PC07Desktopiconiconahorcado_2.jpg",
"C:UsersLab6_PC07Desktopiconiconahorcado_3.jpg",
"C:UsersLab6_PC07Desktopiconiconahorcado_4.jpg",
"C:UsersLab6_PC07Desktopiconiconahorcado_5.jpg",
"C:UsersLab6_PC07Desktopiconiconahorcado_6.jpg"
};
int indice = 0;
private JPanelcontentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ahorcado frame = new ahorcado();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public ahorcado() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 616, 463);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5,5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblVisor = new JLabel("");
ImageIcon imagen = new
ImageIcon("C:UsersLab6_PC07Desktopiconiconahorcado_0.jpg");
lblVisor.setIcon(imagen);
lblVisor.setBorder(new LineBorder(new Color(0, 0, 0), 4, true));
lblVisor.setBounds(319, 11, 271, 402);
contentPane.add(lblVisor);
JLabel rayas = new JLabel("_ _ _ _ _ _ _ _");
rayas.setForeground(Color.WHITE);
rayas.setBounds(53, 43, 187, 14);
contentPane.add(rayas);
JLabel etq1 = new JLabel("P");
etq1.setForeground(Color.WHITE);
etq1.setBounds(53, 43, 13, 14);
3. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
contentPane.add(etq1);
JLabel etq2 = new JLabel("A");
etq2.setForeground(Color.WHITE);
etq2.setBounds(65, 43, 13, 14);
contentPane.add(etq2);
JLabel etq3 = new JLabel("L");
etq3.setForeground(Color.WHITE);
etq3.setBounds(76, 43, 13, 14);
contentPane.add(etq3);
JLabel etq4 = new JLabel("A");
etq4.setForeground(Color.WHITE);
etq4.setBounds(88, 43, 13, 14);
contentPane.add(etq4);
JLabel etq5 = new JLabel("B");
etq5.setForeground(Color.WHITE);
etq5.setBounds(99, 43, 13, 14);
contentPane.add(etq5);
JLabel etq6 = new JLabel("R");
etq6.setForeground(Color.WHITE);
etq6.setBounds(111, 43, 13, 14);
contentPane.add(etq6);
JLabel etq7 = new JLabel("A");
etq7.setForeground(Color.WHITE);
etq7.setBounds(122, 43, 13, 14);
contentPane.add(etq7);
JLabel etq8 = new JLabel("S");
etq8.setForeground(Color.WHITE);
etq8.setBounds(131, 43, 13, 14);
contentPane.add(etq8);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setIcon(new
ImageIcon("C:UsersLab6_PC07Desktopiconiconetiqueta1.jpg"));
lblNewLabel_1.setBounds(41, 34, 199, 34);
contentPane.add(lblNewLabel_1);
JLabel lblTeclado = new JLabel("Teclado");
lblTeclado.setBounds(41, 80, 46, 14);
contentPane.add(lblTeclado);
JButton btnNewButton = new JButton("INICIAR");
btnNewButton.addActionListener(new ActionListener() {
4. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
public void actionPerformed(ActionEvent e) {
LetE="";
LetL="";
LetF="";
LetA="";
LetN="";
LetT="";
etq1.setText("");
etq2.setText("");
etq3.setText("");
etq4.setText("");
etq5.setText("");
etq6.setText("");
etq7.setText("");
etq8.setText("");
lblVisor.setIcon(imagen);
indice = 0;
aciertos = 0;
fails = 0;
}
});
btnNewButton.setBounds(26, 362, 89, 23);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("SALIR");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnNewButton_1.setBounds(176, 362, 89, 23);
contentPane.add(btnNewButton_1);
JButton btnA = new JButton("A");
btnA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetA += "A";
etq5.setText(LetA);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
5. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
btnA.setBounds(41, 94, 45, 39);
contentPane.add(btnA);
JButton btnB = new JButton("B");
btnB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnB.setBounds(85, 94, 45, 39);
contentPane.add(btnB);
JButton btnC = new JButton("C");
btnC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnC.setBounds(130, 94, 45, 39);
contentPane.add(btnC);
JButton btnD = new JButton("D");
btnD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnD.setBounds(176, 94, 45, 39);
contentPane.add(btnD);
JButton btnE = new JButton("E");
6. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
btnE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetE += "E";
etq1.setText(LetE);
etq3.setText(LetE);
etq8.setText(LetE);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
btnE.setBounds(225, 94, 45, 39);
contentPane.add(btnE);
JButton btnA_1 = new JButton("F");
btnA_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetF += "F";
etq4.setText(LetF);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
btnA_1.setBounds(42, 138, 45, 39);
contentPane.add(btnA_1);
JButton btnB_1 = new JButton("G");
btnB_1.addActionListener(new ActionListener() {
7. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnB_1.setBounds(86, 138, 45, 39);
contentPane.add(btnB_1);
JButton btnC_1 = new JButton("H");
btnC_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnC_1.setBounds(131, 138, 45, 39);
contentPane.add(btnC_1);
JButton btnD_1 = new JButton("I");
btnD_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnD_1.setBounds(177, 138, 45, 39);
contentPane.add(btnD_1);
JButton btnE_1 = new JButton("J");
btnE_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnE_1.setBounds(226, 138, 45, 39);
contentPane.add(btnE_1);
JButton btnA_2 = new JButton("K");
btnA_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
8. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnA_2.setBounds(42, 180, 45, 39);
contentPane.add(btnA_2);
JButton btnB_2 = new JButton("L");
btnB_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetL += "L";
etq2.setText(LetL);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
btnB_2.setBounds(86, 180, 45, 39);
contentPane.add(btnB_2);
JButton btnC_2 = new JButton("M");
btnC_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnC_2.setBounds(131, 180, 45, 41);
contentPane.add(btnC_2);
JButton btnD_2 = new JButton("N");
btnD_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetN += "N";
9. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
etq6.setText(LetN);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
btnD_2.setBounds(177, 180, 45, 39);
contentPane.add(btnD_2);
JButton btnE_2 = new JButton("O");
btnE_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnE_2.setBounds(226, 180, 45, 39);
contentPane.add(btnE_2);
JButton btnA_3 = new JButton("P");
btnA_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnA_3.setBounds(42, 226, 45, 39);
contentPane.add(btnA_3);
JButton btnB_3 = new JButton("Q");
btnB_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
10. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
}
});
btnB_3.setBounds(86, 226, 45, 39);
contentPane.add(btnB_3);
JButton btnC_3 = new JButton("R");
btnC_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnC_3.setBounds(131, 226, 45, 39);
contentPane.add(btnC_3);
JButton btnD_3 = new JButton("S");
btnD_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnD_3.setBounds(177, 226, 45, 39);
contentPane.add(btnD_3);
JButton btnE_3 = new JButton("T");
btnE_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice < 6) {
LetT += "T";
etq7.setText(LetT);
aciertos = aciertos+1;
if (aciertos==6) {
JOptionPane.showMessageDialog(null,
"Ganaste!");
} else {
JOptionPane.showMessageDialog(null,
"Encontraste una letra");
}
} else {
}
}
});
11. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
btnE_3.setBounds(226, 226, 45, 39);
contentPane.add(btnE_3);
JButton btnA_4 = new JButton("U");
btnA_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnA_4.setBounds(41, 267, 45, 39);
contentPane.add(btnA_4);
JButton btnB_4 = new JButton("V");
btnB_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnB_4.setBounds(85, 267, 45, 39);
contentPane.add(btnB_4);
JButton btnC_4 = new JButton("W");
btnC_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnC_4.setBounds(130, 267, 47, 39);
contentPane.add(btnC_4);
JButton btnD_4 = new JButton("X");
btnD_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnD_4.setBounds(176, 267, 45, 39);
12. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
contentPane.add(btnD_4);
JButton btnE_4 = new JButton("Y");
btnE_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnE_4.setBounds(225, 267, 45, 39);
contentPane.add(btnE_4);
JButton btnA_4_1 = new JButton("Z");
btnA_4_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnA_4_1.setBounds(41, 312, 45, 39);
contentPane.add(btnA_4_1);
JButton btnA_4_1_1 = new JButton("u00D1");
btnA_4_1_1.setActionCommand("u00D1");
btnA_4_1_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(indice == 6) indice=6;
else indice++;
ImageIcon Imagen = new ImageIcon(imagenes[indice]);
lblVisor.setIcon(Imagen);
}
});
btnA_4_1_1.setBounds(225, 312, 45, 39);
contentPane.add(btnA_4_1_1);
}
int aciertos = 0;
int fails = 0;
String LetE="";
String LetL="";
String LetF="";
String LetA="";
String LetN="";
String LetT="";
13. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
}
f.) _______________ f.) ______________ f.) _______________
14. UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD FILOSOFÍA, LETRAS Y CIENCIAS DE LA EDUCACIÓN
PEDAGOGÍA DE LAS CIENCIAS EXPERIMENTALES -
INFORMÁTICA
Periodo Académico: Septiembre 2019 - Febrero 2020
Sr. Haro Jesus Sr. Oscullo Carlos Sr. Morocho Johnny
ESTUDIANTE ESTUDIANTE ESTUDIANTE
f.) ______________
MSc. Zapata Víctor
DOCENTE