Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package paquete;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Rectangle;
- import java.awt.event.*;
- import javax.swing.*;
- import java.awt.Font;
- public class WordSearch extends JFrame implements ActionListener {
- int c=0,i=0;
- String desc;
- private JLabel[][] texto = new JLabel[8][11];
- private JLabel texto1,texto2,texto3;
- private JTextField caja; // caja de texto, para insertar datos
- private JButton boton,boton1,boton2,boton3,boton4,boton5,boton6,boton7,boton8,boton9,boton10,boton11; // boton con una determinada accion
- public WordSearch() {
- super(); // usamos el contructor de la clase padre JFrame
- configurarVentana(); // configuramos la ventana
- inicializarComponentes(); // inicializamos los atributos o componentes
- }
- private void configurarVentana() {
- this.setTitle("Sopa de Letras"); // colocamos titulo a la ventana
- this.setSize(800, 600); // colocamos tamanio a la ventana (ancho, alto)
- this.setLocationRelativeTo(null); // centramos la ventana en la pantalla
- getContentPane().setLayout(null); // no usamos ningun layout, solo asi podremos dar posiciones a los componentes
- this.setResizable(false); // hacemos que la ventana no sea redimiensionable
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // hacemos que cuando se cierre la ventana termina todo proceso
- }
- public void inicializarComponentes() {
- // creamos los componentes
- texto1 = new JLabel();
- texto2 = new JLabel();
- texto3 = new JLabel();
- caja = new JTextField();
- boton = new JButton();
- boton1 = new JButton();
- boton2 = new JButton();
- boton3 = new JButton();
- boton4 = new JButton();
- boton5 = new JButton();
- boton6 = new JButton();
- boton7 = new JButton();
- boton8 = new JButton();
- boton9 = new JButton();
- boton10 = new JButton();
- boton11 = new JButton();
- // configuramos los componentes
- for(int i = 0; i < texto.length; i++) {
- for(int j=0; j<11;j++){
- texto[i][j] = new JLabel(); //Llenamos el array de etiquetas
- texto[i][j].setBounds(new Rectangle((j+1)*65, (i+1)*30, 25, 25));
- texto[i][j].setFont(new Font("Tahoma", Font.BOLD, 15));
- texto[i][j].setForeground(Color.YELLOW);
- getContentPane().add(texto[i][j]);
- }
- }
- texto[0][0].setText("J");
- texto[0][1].setText("N");
- texto[0][2].setText("A");
- texto[0][3].setText("J");
- texto[0][4].setText("O");
- texto[0][5].setText("F");
- texto[0][6].setText("F");
- texto[0][7].setText("R");
- texto[0][8].setText("E");
- texto[0][9].setText("Y");
- texto[0][10].setText("A");
- texto[1][0].setText("J");
- texto[1][1].setText("O");
- texto[1][2].setText("N");
- texto[1][3].setText("R");
- texto[1][4].setText("S");
- texto[1][5].setText("O");
- texto[1][6].setText("F");
- texto[1][7].setText("E");
- texto[1][8].setText("T");
- texto[1][9].setText("A");
- texto[1][10].setText("N");
- texto[2][0].setText("A");
- texto[2][1].setText("I");
- texto[2][2].setText("S");
- texto[2][3].setText("I");
- texto[2][4].setText("E");
- texto[2][5].setText("A");
- texto[2][6].setText("T");
- texto[2][7].setText("R");
- texto[2][8].setText("S");
- texto[2][9].setText("T");
- texto[2][10].setText("E");
- texto[3][0].setText("I");
- texto[3][1].setText("R");
- texto[3][2].setText("B");
- texto[3][3].setText("S");
- texto[3][4].setText("Y");
- texto[3][5].setText("R");
- texto[3][6].setText("E");
- texto[3][7].setText("N");
- texto[3][8].setText("E");
- texto[3][9].setText("A");
- texto[3][10].setText("D");
- texto[4][0].setText("M");
- texto[4][1].setText("Y");
- texto[4][2].setText("O");
- texto[4][3].setText("R");
- texto[4][4].setText("E");
- texto[4][5].setText("D");
- texto[4][6].setText("A");
- texto[4][7].setText("R");
- texto[4][8].setText("R");
- texto[4][9].setText("Y");
- texto[4][10].setText("N");
- texto[5][0].setText("E");
- texto[5][1].setText("T");
- texto[5][2].setText("A");
- texto[5][3].setText("B");
- texto[5][4].setText("R");
- texto[5][5].setText("S");
- texto[5][6].setText("N");
- texto[5][7].setText("A");
- texto[5][8].setText("J");
- texto[5][9].setText("O");
- texto[5][10].setText("F");
- texto[6][0].setText("T");
- texto[6][1].setText("Y");
- texto[6][2].setText("O");
- texto[6][3].setText("D");
- texto[6][4].setText("A");
- texto[6][5].setText("E");
- texto[6][6].setText("S");
- texto[6][7].setText("N");
- texto[6][8].setText("D");
- texto[6][9].setText("E");
- texto[6][10].setText("S");
- texto[7][0].setText("S");
- texto[7][1].setText("R");
- texto[7][2].setText("E");
- texto[7][3].setText("S");
- texto[7][4].setText("T");
- texto[7][5].setText("I");
- texto[7][6].setText("E");
- texto[7][7].setText("S");
- texto[7][8].setText("R");
- texto[7][9].setText("E");
- texto[7][10].setText("C");
- texto1.setText("CHARACTER KNOWN AS MOTHER OF DRAGONS");
- texto1.setBounds(60, 325, 500, 25);
- texto1.setForeground(Color.GREEN);
- texto1.setFont(new Font("Tahoma", Font.BOLD, 14));
- texto2.setText("THANK YOU FOR PLAYING ");
- texto2.setBounds(580, 325, 500, 25);
- texto2.setForeground(Color.GREEN);
- texto2.setFont(new Font("Tahoma", Font.BOLD, 14));
- texto2.setVisible(false);
- texto3.setBounds(60, 325, 500, 25);
- texto3.setForeground(Color.GREEN);
- texto3.setFont(new Font("Tahoma", Font.BOLD, 14));
- texto3.setVisible(false);
- caja.setBounds(300, 470, 130, 25); // colocamos posicion y tamanio a la caja (x, y, ancho, alto)
- boton.setText("CHECK"); // colocamos un texto al boton
- boton.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton1.setText("CHECK"); // colocamos un texto al boton
- boton1.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton1.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton1.setVisible(false);
- boton2.setText("CHECK"); // colocamos un texto al boton
- boton2.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton2.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton2.setVisible(false);
- boton3.setText("CHECK"); // colocamos un texto al boton
- boton3.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton3.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton3.setVisible(false);
- boton4.setText("CHECK"); // colocamos un texto al boton
- boton4.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton4.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton4.setVisible(false);
- boton5.setText("CHECK"); // colocamos un texto al boton
- boton5.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton5.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton5.setVisible(false);
- boton6.setText("CHECK"); // colocamos un texto al boton
- boton6.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton6.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton6.setVisible(false);
- boton7.setText("CHECK"); // colocamos un texto al boton
- boton7.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton7.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton7.setVisible(false);
- boton8.setText("CHECK"); // colocamos un texto al boton
- boton8.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton8.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton8.setVisible(false);
- boton9.setText("CHECK"); // colocamos un texto al boton
- boton9.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton9.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton9.setVisible(false);
- boton10.setText("PLAY AGAIN"); // colocamos un texto al boton
- boton10.setBounds(60, 530, 150, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton10.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton10.setVisible(false);
- boton11.setText("FINISH"); // colocamos un texto al boton
- boton11.setBounds(580, 530, 150, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
- boton11.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
- boton11.setVisible(false);
- // adicionamos los componentes a la ventana
- getContentPane().add(texto1);
- getContentPane().add(texto2);
- getContentPane().add(texto3);
- getContentPane().add(caja);
- getContentPane().add(boton);
- getContentPane().add(boton1);
- getContentPane().add(boton2);
- getContentPane().add(boton3);
- getContentPane().add(boton4);
- getContentPane().add(boton5);
- getContentPane().add(boton6);
- getContentPane().add(boton7);
- getContentPane().add(boton8);
- getContentPane().add(boton9);
- getContentPane().add(boton10);
- getContentPane().add(boton11);
- JLabel label = new JLabel("");
- label.setIcon(new ImageIcon(WordSearch.class.getResource("/paquete/got1.jpg")));
- label.setBounds(0, 0, 798, 600);
- getContentPane().add(label);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- String intento = caja.getText();// obtenemos el contenido de la caja de texto
- if(e.getSource()==boton){
- if(intento.equalsIgnoreCase("DAENERYS")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int k=3;k<11;k++){
- texto[3][k].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton.setVisible(false);
- boton1.setVisible(true);
- texto1.setText("LORD OF WINTERFELL");
- caja.setText("");
- }
- String intento1=caja.getText();
- if(e.getSource()==boton1){
- if(intento1.equalsIgnoreCase("NED")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int l=1;l<4;l++){
- texto[l][10].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton1.setVisible(false);
- boton2.setVisible(true);
- texto1.setText("CHARACTER KNOWN AS KINGSLAYER");
- caja.setText("");
- }
- String intento2=caja.getText();
- if(e.getSource()==boton2){
- if(intento2.equalsIgnoreCase("JAIME")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int m=1;m<6;m++)
- texto[m][0].setForeground(Color.RED);
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton2.setVisible(false);
- boton3.setVisible(true);
- texto1.setText("NED STARK'S ELDEST DAUGHTER");
- caja.setText("");
- }
- String intento3=caja.getText();
- if(e.getSource()==boton3){
- int j=10;
- if(intento3.equalsIgnoreCase("SANSA")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int i=1; i<6;i++){
- j=j-1;
- texto[i][j].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton3.setVisible(false);
- boton4.setVisible(true);
- texto1.setText("INITIAL KING OF THE SEVEN KINDOMS");
- caja.setText("");
- }
- String intento4=caja.getText();
- if(e.getSource()==boton4){
- int j=8;
- if(intento4.equalsIgnoreCase("ROBERT")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int i=1; i<7;i++){
- j=j-1;
- texto[j][i].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton4.setVisible(false);
- boton5.setVisible(true);
- texto1.setText("CHARACTER KNOWN AS NED STARK'S BASTARD SON");
- caja.setText("");
- }
- String intento5=caja.getText();
- if(e.getSource()==boton5){
- if(intento5.equalsIgnoreCase("JON")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int n=0;n<3;n++){
- texto[1][n].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton5.setVisible(false);
- boton6.setVisible(true);
- texto1.setText("ROBERT BARATHEON'S WIFE");
- caja.setText("");
- }
- String intento6=caja.getText();
- if(e.getSource()==boton6){
- if(intento6.equalsIgnoreCase("CERSEI")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int p=5;p<11;p++){
- texto[7][p].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton6.setVisible(false);
- boton7.setVisible(true);
- texto1.setText("NED STARK'S YOUNGER DAUGHTER");
- caja.setText("");
- }
- String intento7=caja.getText();
- if(e.getSource()==boton7){
- int j=6;
- if(intento7.equalsIgnoreCase("ARYA")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int i=2; i<6;i++){
- j=j-1;
- texto[j][i].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton7.setVisible(false);
- boton8.setVisible(true);
- texto1.setText("CERSEI LANNISTER'S ELDEST SON");
- caja.setText("");
- }
- String intento8=caja.getText();
- if(e.getSource()==boton8){
- if(intento8.equalsIgnoreCase("JOFFREY")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int s=3; s<10; s++){
- texto[0][s].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton8.setVisible(false);
- boton9.setVisible(true);
- texto1.setText("CHARACTER KNOWN AS HALFMAN");
- caja.setText("");
- }
- String intento9=caja.getText();
- if(e.getSource()==boton9){
- if(intento9.equalsIgnoreCase("TYRION")){
- JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
- for(int r=0;r<6;r++){
- texto[r][1].setForeground(Color.RED);
- }
- c++;
- }else{
- JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
- }
- boton9.setVisible(false);
- caja.setVisible(false);
- if(c>9){
- desc=" PERFECT SCORE! CONGRATS!!!! ";
- }else{
- if(c>7 && c<10){
- desc=" EXCELLENT! GREAT JOB ";
- }else{
- if(c>5 && c<8){
- desc=" GOOD JOB. KEEW IT UP";
- }else{
- desc= " BETTER LUCK NEXT TIME";
- }
- }
- }
- boton10.setVisible(true);
- boton11.setVisible(true);
- texto3.setVisible(true);
- texto3.setText("YOUR SCORE WAS: "+c+"\t"+desc);
- texto1.setVisible(false);
- texto2.setVisible(true);
- }
- if(e.getSource()==boton10){
- caja.setVisible(true);
- caja.setText("");
- boton.setVisible(true);
- boton10.setVisible(false);
- boton11.setVisible(false);
- texto1.setVisible(true);
- texto1.setText("CHARACTER KNOWN AS MOTHER OF DRAGONS");
- texto2.setVisible(false);
- texto3.setVisible(false);
- for(int t = 0; t < 8; t++) {
- for(int u=0; u<11;u++){
- texto[t][u].setForeground(Color.YELLOW);
- }
- }
- c=0;
- }
- if(e.getSource()==boton11){
- System.exit(0);;
- }
- }
- public static void main(String[] args) {
- WordSearch V = new WordSearch(); // creamos una ventana
- V.setVisible(true); // hacemos visible la ventana creada
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement