Advertisement
Guest User

WordSearchnew

a guest
Jan 8th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.94 KB | None | 0 0
  1. package paquete;
  2.  
  3.  
  4.  
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Rectangle;
  8. import java.awt.event.*;
  9. import javax.swing.*;
  10. import java.awt.Font;
  11.  
  12.  
  13. public class WordSearch extends JFrame implements ActionListener {
  14. int c=0,i=0;
  15. String desc;
  16.  
  17. private JLabel[][] texto = new JLabel[8][11];
  18. private JLabel texto1,texto2,texto3;
  19. private JTextField caja; // caja de texto, para insertar datos
  20. private JButton boton,boton1,boton2,boton3,boton4,boton5,boton6,boton7,boton8,boton9,boton10,boton11; // boton con una determinada accion
  21. public WordSearch() {
  22. super(); // usamos el contructor de la clase padre JFrame
  23. configurarVentana(); // configuramos la ventana
  24. inicializarComponentes(); // inicializamos los atributos o componentes
  25. }
  26. private void configurarVentana() {
  27. this.setTitle("Sopa de Letras"); // colocamos titulo a la ventana
  28. this.setSize(800, 600); // colocamos tamanio a la ventana (ancho, alto)
  29. this.setLocationRelativeTo(null); // centramos la ventana en la pantalla
  30. getContentPane().setLayout(null); // no usamos ningun layout, solo asi podremos dar posiciones a los componentes
  31. this.setResizable(false); // hacemos que la ventana no sea redimiensionable
  32. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // hacemos que cuando se cierre la ventana termina todo proceso
  33. }
  34. public void inicializarComponentes() {
  35.  
  36. // creamos los componentes
  37.  
  38.  
  39. texto1 = new JLabel();
  40. texto2 = new JLabel();
  41.  
  42. texto3 = new JLabel();
  43.  
  44.  
  45. caja = new JTextField();
  46.  
  47. boton = new JButton();
  48. boton1 = new JButton();
  49. boton2 = new JButton();
  50. boton3 = new JButton();
  51. boton4 = new JButton();
  52. boton5 = new JButton();
  53. boton6 = new JButton();
  54. boton7 = new JButton();
  55. boton8 = new JButton();
  56. boton9 = new JButton();
  57. boton10 = new JButton();
  58. boton11 = new JButton();
  59.  
  60.  
  61. // configuramos los componentes
  62.  
  63.  
  64.  
  65. for(int i = 0; i < texto.length; i++) {
  66. for(int j=0; j<11;j++){
  67. texto[i][j] = new JLabel(); //Llenamos el array de etiquetas
  68. texto[i][j].setBounds(new Rectangle((j+1)*65, (i+1)*30, 25, 25));
  69. texto[i][j].setFont(new Font("Tahoma", Font.BOLD, 15));
  70. texto[i][j].setForeground(Color.YELLOW);
  71.  
  72. getContentPane().add(texto[i][j]);
  73. }
  74. }
  75.  
  76.  
  77.  
  78.  
  79. texto[0][0].setText("J");
  80. texto[0][1].setText("N");
  81. texto[0][2].setText("A");
  82. texto[0][3].setText("J");
  83. texto[0][4].setText("O");
  84. texto[0][5].setText("F");
  85. texto[0][6].setText("F");
  86. texto[0][7].setText("R");
  87. texto[0][8].setText("E");
  88. texto[0][9].setText("Y");
  89. texto[0][10].setText("A");
  90.  
  91. texto[1][0].setText("J");
  92. texto[1][1].setText("O");
  93. texto[1][2].setText("N");
  94. texto[1][3].setText("R");
  95. texto[1][4].setText("S");
  96. texto[1][5].setText("O");
  97. texto[1][6].setText("F");
  98. texto[1][7].setText("E");
  99. texto[1][8].setText("T");
  100. texto[1][9].setText("A");
  101. texto[1][10].setText("N");
  102.  
  103. texto[2][0].setText("A");
  104. texto[2][1].setText("I");
  105. texto[2][2].setText("S");
  106. texto[2][3].setText("I");
  107. texto[2][4].setText("E");
  108. texto[2][5].setText("A");
  109. texto[2][6].setText("T");
  110. texto[2][7].setText("R");
  111. texto[2][8].setText("S");
  112. texto[2][9].setText("T");
  113. texto[2][10].setText("E");
  114.  
  115. texto[3][0].setText("I");
  116. texto[3][1].setText("R");
  117. texto[3][2].setText("B");
  118. texto[3][3].setText("S");
  119. texto[3][4].setText("Y");
  120. texto[3][5].setText("R");
  121. texto[3][6].setText("E");
  122. texto[3][7].setText("N");
  123. texto[3][8].setText("E");
  124. texto[3][9].setText("A");
  125. texto[3][10].setText("D");
  126.  
  127. texto[4][0].setText("M");
  128. texto[4][1].setText("Y");
  129. texto[4][2].setText("O");
  130. texto[4][3].setText("R");
  131. texto[4][4].setText("E");
  132. texto[4][5].setText("D");
  133. texto[4][6].setText("A");
  134. texto[4][7].setText("R");
  135. texto[4][8].setText("R");
  136. texto[4][9].setText("Y");
  137. texto[4][10].setText("N");
  138.  
  139. texto[5][0].setText("E");
  140. texto[5][1].setText("T");
  141. texto[5][2].setText("A");
  142. texto[5][3].setText("B");
  143. texto[5][4].setText("R");
  144. texto[5][5].setText("S");
  145. texto[5][6].setText("N");
  146. texto[5][7].setText("A");
  147. texto[5][8].setText("J");
  148. texto[5][9].setText("O");
  149. texto[5][10].setText("F");
  150.  
  151. texto[6][0].setText("T");
  152. texto[6][1].setText("Y");
  153. texto[6][2].setText("O");
  154. texto[6][3].setText("D");
  155. texto[6][4].setText("A");
  156. texto[6][5].setText("E");
  157. texto[6][6].setText("S");
  158. texto[6][7].setText("N");
  159. texto[6][8].setText("D");
  160. texto[6][9].setText("E");
  161. texto[6][10].setText("S");
  162.  
  163. texto[7][0].setText("S");
  164. texto[7][1].setText("R");
  165. texto[7][2].setText("E");
  166. texto[7][3].setText("S");
  167. texto[7][4].setText("T");
  168. texto[7][5].setText("I");
  169. texto[7][6].setText("E");
  170. texto[7][7].setText("S");
  171. texto[7][8].setText("R");
  172. texto[7][9].setText("E");
  173. texto[7][10].setText("C");
  174.  
  175. texto1.setText("CHARACTER KNOWN AS MOTHER OF DRAGONS");
  176. texto1.setBounds(60, 325, 500, 25);
  177. texto1.setForeground(Color.GREEN);
  178. texto1.setFont(new Font("Tahoma", Font.BOLD, 14));
  179.  
  180. texto2.setText("THANK YOU FOR PLAYING ");
  181. texto2.setBounds(580, 325, 500, 25);
  182. texto2.setForeground(Color.GREEN);
  183. texto2.setFont(new Font("Tahoma", Font.BOLD, 14));
  184. texto2.setVisible(false);
  185.  
  186.  
  187.  
  188. texto3.setBounds(60, 325, 500, 25);
  189. texto3.setForeground(Color.GREEN);
  190. texto3.setFont(new Font("Tahoma", Font.BOLD, 14));
  191. texto3.setVisible(false);
  192.  
  193. caja.setBounds(300, 470, 130, 25); // colocamos posicion y tamanio a la caja (x, y, ancho, alto)
  194.  
  195.  
  196. boton.setText("CHECK"); // colocamos un texto al boton
  197. boton.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  198. boton.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  199.  
  200.  
  201. boton1.setText("CHECK"); // colocamos un texto al boton
  202. boton1.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  203. boton1.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  204. boton1.setVisible(false);
  205.  
  206. boton2.setText("CHECK"); // colocamos un texto al boton
  207. boton2.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  208. boton2.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  209. boton2.setVisible(false);
  210.  
  211. boton3.setText("CHECK"); // colocamos un texto al boton
  212. boton3.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  213. boton3.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  214. boton3.setVisible(false);
  215.  
  216. boton4.setText("CHECK"); // colocamos un texto al boton
  217. boton4.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  218. boton4.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  219. boton4.setVisible(false);
  220.  
  221. boton5.setText("CHECK"); // colocamos un texto al boton
  222. boton5.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  223. boton5.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  224. boton5.setVisible(false);
  225.  
  226. boton6.setText("CHECK"); // colocamos un texto al boton
  227. boton6.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  228. boton6.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  229. boton6.setVisible(false);
  230.  
  231. boton7.setText("CHECK"); // colocamos un texto al boton
  232. boton7.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  233. boton7.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  234. boton7.setVisible(false);
  235.  
  236. boton8.setText("CHECK"); // colocamos un texto al boton
  237. boton8.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  238. boton8.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  239. boton8.setVisible(false);
  240.  
  241. boton9.setText("CHECK"); // colocamos un texto al boton
  242. boton9.setBounds(300, 500, 130, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  243. boton9.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  244. boton9.setVisible(false);
  245.  
  246. boton10.setText("PLAY AGAIN"); // colocamos un texto al boton
  247. boton10.setBounds(60, 530, 150, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  248. boton10.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  249. boton10.setVisible(false);
  250.  
  251. boton11.setText("FINISH"); // colocamos un texto al boton
  252. boton11.setBounds(580, 530, 150, 30); // colocamos posicion y tamanio al boton (x, y, ancho, alto)
  253. boton11.addActionListener(this); // hacemos que el boton tenga una accion y esa accion estara en esta clase
  254. boton11.setVisible(false);
  255.  
  256.  
  257. // adicionamos los componentes a la ventana
  258.  
  259. getContentPane().add(texto1);
  260. getContentPane().add(texto2);
  261.  
  262. getContentPane().add(texto3);
  263.  
  264. getContentPane().add(caja);
  265.  
  266. getContentPane().add(boton);
  267. getContentPane().add(boton1);
  268. getContentPane().add(boton2);
  269. getContentPane().add(boton3);
  270. getContentPane().add(boton4);
  271. getContentPane().add(boton5);
  272. getContentPane().add(boton6);
  273. getContentPane().add(boton7);
  274. getContentPane().add(boton8);
  275. getContentPane().add(boton9);
  276. getContentPane().add(boton10);
  277. getContentPane().add(boton11);
  278.  
  279. JLabel label = new JLabel("");
  280. label.setIcon(new ImageIcon(WordSearch.class.getResource("/paquete/got1.jpg")));
  281. label.setBounds(0, 0, 798, 600);
  282. getContentPane().add(label);
  283.  
  284. }
  285.  
  286. @Override
  287. public void actionPerformed(ActionEvent e) {
  288.  
  289. String intento = caja.getText();// obtenemos el contenido de la caja de texto
  290. if(e.getSource()==boton){
  291. if(intento.equalsIgnoreCase("DAENERYS")){
  292. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  293.  
  294. for(int k=3;k<11;k++){
  295. texto[3][k].setForeground(Color.RED);
  296. }
  297. c++;
  298. }else{
  299. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  300. }
  301. boton.setVisible(false);
  302. boton1.setVisible(true);
  303. texto1.setText("LORD OF WINTERFELL");
  304. caja.setText("");
  305. }
  306.  
  307. String intento1=caja.getText();
  308. if(e.getSource()==boton1){
  309. if(intento1.equalsIgnoreCase("NED")){
  310. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  311. for(int l=1;l<4;l++){
  312. texto[l][10].setForeground(Color.RED);
  313. }
  314. c++;
  315. }else{
  316. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  317. }
  318. boton1.setVisible(false);
  319. boton2.setVisible(true);
  320. texto1.setText("CHARACTER KNOWN AS KINGSLAYER");
  321. caja.setText("");
  322. }
  323.  
  324. String intento2=caja.getText();
  325. if(e.getSource()==boton2){
  326. if(intento2.equalsIgnoreCase("JAIME")){
  327. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  328. for(int m=1;m<6;m++)
  329. texto[m][0].setForeground(Color.RED);
  330. c++;
  331. }else{
  332. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  333. }
  334. boton2.setVisible(false);
  335. boton3.setVisible(true);
  336. texto1.setText("NED STARK'S ELDEST DAUGHTER");
  337. caja.setText("");
  338. }
  339.  
  340. String intento3=caja.getText();
  341. if(e.getSource()==boton3){
  342. int j=10;
  343. if(intento3.equalsIgnoreCase("SANSA")){
  344. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  345. for(int i=1; i<6;i++){
  346. j=j-1;
  347. texto[i][j].setForeground(Color.RED);
  348. }
  349. c++;
  350. }else{
  351. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  352. }
  353. boton3.setVisible(false);
  354. boton4.setVisible(true);
  355. texto1.setText("INITIAL KING OF THE SEVEN KINDOMS");
  356. caja.setText("");
  357. }
  358.  
  359. String intento4=caja.getText();
  360. if(e.getSource()==boton4){
  361. int j=8;
  362. if(intento4.equalsIgnoreCase("ROBERT")){
  363. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  364. for(int i=1; i<7;i++){
  365. j=j-1;
  366. texto[j][i].setForeground(Color.RED);
  367. }
  368. c++;
  369. }else{
  370. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  371. }
  372. boton4.setVisible(false);
  373. boton5.setVisible(true);
  374. texto1.setText("CHARACTER KNOWN AS NED STARK'S BASTARD SON");
  375. caja.setText("");
  376. }
  377.  
  378. String intento5=caja.getText();
  379. if(e.getSource()==boton5){
  380. if(intento5.equalsIgnoreCase("JON")){
  381. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  382. for(int n=0;n<3;n++){
  383. texto[1][n].setForeground(Color.RED);
  384. }
  385. c++;
  386. }else{
  387. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  388. }
  389. boton5.setVisible(false);
  390. boton6.setVisible(true);
  391. texto1.setText("ROBERT BARATHEON'S WIFE");
  392. caja.setText("");
  393. }
  394.  
  395. String intento6=caja.getText();
  396. if(e.getSource()==boton6){
  397. if(intento6.equalsIgnoreCase("CERSEI")){
  398. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  399. for(int p=5;p<11;p++){
  400. texto[7][p].setForeground(Color.RED);
  401. }
  402. c++;
  403. }else{
  404. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  405. }
  406. boton6.setVisible(false);
  407. boton7.setVisible(true);
  408. texto1.setText("NED STARK'S YOUNGER DAUGHTER");
  409. caja.setText("");
  410. }
  411.  
  412. String intento7=caja.getText();
  413. if(e.getSource()==boton7){
  414. int j=6;
  415. if(intento7.equalsIgnoreCase("ARYA")){
  416. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  417. for(int i=2; i<6;i++){
  418. j=j-1;
  419. texto[j][i].setForeground(Color.RED);
  420. }
  421. c++;
  422. }else{
  423. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  424. }
  425. boton7.setVisible(false);
  426. boton8.setVisible(true);
  427. texto1.setText("CERSEI LANNISTER'S ELDEST SON");
  428. caja.setText("");
  429. }
  430.  
  431. String intento8=caja.getText();
  432. if(e.getSource()==boton8){
  433. if(intento8.equalsIgnoreCase("JOFFREY")){
  434. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  435. for(int s=3; s<10; s++){
  436. texto[0][s].setForeground(Color.RED);
  437. }
  438.  
  439.  
  440. c++;
  441. }else{
  442. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  443. }
  444. boton8.setVisible(false);
  445. boton9.setVisible(true);
  446. texto1.setText("CHARACTER KNOWN AS HALFMAN");
  447. caja.setText("");
  448. }
  449.  
  450. String intento9=caja.getText();
  451. if(e.getSource()==boton9){
  452. if(intento9.equalsIgnoreCase("TYRION")){
  453. JOptionPane.showMessageDialog(this, "CORRECT"); // mostramos un mensaje (frame, mensaje)
  454. for(int r=0;r<6;r++){
  455. texto[r][1].setForeground(Color.RED);
  456. }
  457. c++;
  458. }else{
  459. JOptionPane.showMessageDialog(this, "INCORRECT"); // mostramos un mensaje (frame, mensaje)
  460. }
  461. boton9.setVisible(false);
  462. caja.setVisible(false);
  463. if(c>9){
  464. desc=" PERFECT SCORE! CONGRATS!!!! ";
  465. }else{
  466. if(c>7 && c<10){
  467. desc=" EXCELLENT! GREAT JOB ";
  468. }else{
  469. if(c>5 && c<8){
  470. desc=" GOOD JOB. KEEW IT UP";
  471. }else{
  472. desc= " BETTER LUCK NEXT TIME";
  473. }
  474. }
  475. }
  476. boton10.setVisible(true);
  477. boton11.setVisible(true);
  478. texto3.setVisible(true);
  479. texto3.setText("YOUR SCORE WAS: "+c+"\t"+desc);
  480. texto1.setVisible(false);
  481. texto2.setVisible(true);
  482.  
  483. }
  484.  
  485. if(e.getSource()==boton10){
  486. caja.setVisible(true);
  487. caja.setText("");
  488. boton.setVisible(true);
  489. boton10.setVisible(false);
  490. boton11.setVisible(false);
  491. texto1.setVisible(true);
  492. texto1.setText("CHARACTER KNOWN AS MOTHER OF DRAGONS");
  493. texto2.setVisible(false);
  494.  
  495. texto3.setVisible(false);
  496.  
  497. for(int t = 0; t < 8; t++) {
  498. for(int u=0; u<11;u++){
  499. texto[t][u].setForeground(Color.YELLOW);
  500. }
  501. }
  502. c=0;
  503. }
  504. if(e.getSource()==boton11){
  505. System.exit(0);;
  506. }
  507. }
  508. public static void main(String[] args) {
  509. WordSearch V = new WordSearch(); // creamos una ventana
  510. V.setVisible(true); // hacemos visible la ventana creada
  511. }
  512. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement