Word Puzzle Game | Java Program Implementation
Letter arrangement games are generally used as a source of educational purpose.In a letter arrangement game, the goal is to form words out of given letters.these games generally test vocabulary skill as well as lateral thinking skills.
Implementation requirement :
- NetBeans IDE
- Basic knowledge of core java
Implementation idea :
STEP 1 : basically idea is used to create one dimentional JLabel and one dimentional Array of JButton which as shown in below picture:
NOTE :
- Size of JLabel and JButton always same.
- What should be size of JLabel and JButton-- suppose you have a collection of words like {"GAME" , "MONDAY" , "SUN" , "HELP"}.in this collection of words "MONDAY" has maximum letter in it.so the size of JLabel and JButton is always based on the word's maximum letter.
Explaination :
- In this project,"MONDAY" has maximim letter among the collection of words.that's why we initialize 6 JLabel and JButton
STEP 2 : Suppose you have a word = "MONDAY",then Place each letter of MONDAY on JButton randomly.
STEP 3 : On click any JButton,text on that button is copy or set on the JLabel which as picture shown below i.e text on button = label's text
1. In NetBeans IDE,
- click File option from menu-bar
- then select New Project
- after that one popup window open--in that select Java option from Categories and select Java Application option and click on Next button
2. After clicking on Next Button,
- Again one popup window appears ,in that you have to write project Name.
- In that popup window there is a CheckBox which name is create Main Class deselect it.
3. After creating project file,
- Create JFrame in the Project which is as picture shown below.

- After click on JFrame Form,one popup window appears in that you have to write Class name as well as package name.
4. After creating JFrame Class,
4.2 Drag and drop panel into Frame,
- Set Border --LineBorder and thickness 2
- Set Background color -- White
5. After setting properties of Panel, Now take JLabel and JButton From Palette
5.1 For JLabel set properties :
- Set Border -- LineBorder and thickness 2
- Set Text--Empty
- Set Border -- LineBorder and thickness 2
- Set Text--Empty
- Take one more JLabel And set Text ="Move : 12" As Shown in below Picture

6. Add action listener to the each jbutton
- Now Right click on a JButton,and select Events --> Action --> ActionPerformed.
7. Up to this only Form design part,we completed Now we have to write code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | package letterarrangement; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; public class LetterArrangement extends javax.swing.JFrame { //Variables declration String[] numberOfWords = {"SUN" , "GAME" , "MONDAY" , "HELP" , "TO" }; /* 1. First we define Words,which should have letter less and equal to 6 2. why 6? 2. 1 because we initilize only 6 JButton and JLabel in Form Design part 3. if you want more then 6 letter's word than should be initilaze that much label and button in Form Design */ int totalNumberOfWords = 5; //5 words present in numberOfWords Array String word; //takes one word from numberOfWords[] int letter_present_in_word; //how many letter in word suppose word="TO" then letter_present_in_word = 2 boolean ClickButton1 = true; // from ClickButton1 to ClickButton6 it keep track of Button Click boolean ClickButton2 = true; // ClickButton1 Track on JButton1 and ClickButton2 track on JButoon2 and so on. boolean ClickButton3 = true; // when it true , for example ClickButton1 = true then text on JButton1 is copy to JLabel's text boolean ClickButton4 = true; // when it false , for example ClickButton1 = false then it just set text of JLabel empty. boolean ClickButton5 = true; boolean ClickButton6 = true; int moves=12; // Total moves for each Letter Arrangement is 12,Click on any Button Value of moves Decrement /* 1. LetterArrangement() constructor generated by System. 2. randomWordsFromNumberOfWords() using this method we get a particular word from numberOfWords[] for example word = "MONDAY" 3. setVisibleBoxes() using this method we can visible number of boxes,the number of boxes should be equal to word's letter. 3.1 suppose word = "HELP" then only visibility of number of boxes = 4 only 3.2 suppose word = "MONDAY" then only visibility of number of boxes = 6 only 4. setValuesOnBox() using this method,we can place word's letter randomly on JButton[] */ public LetterArrangement() { initComponents(); randomWordsFromNumberOfWords(); setVisibleBoxes(); setValuesOnBox(); } /* 1. this method helps to choose perticular word from Array of numberOfWords[] 2. every time when randomWordsFromNumberOfWords() calls totalNumberOfWords should be Decrement 3. every word from numberOfWord[] should be not repeated 4. if All word from numberOfWord[] traverse then player has 2 options first is player can start Game again and second is player can Exit Game.*/ public void randomWordsFromNumberOfWords() { if(totalNumberOfWords > 0) { int random_words = (int)(Math.random() * totalNumberOfWords); word = numberOfWords[random_words]; if(random_words < totalNumberOfWords-1) numberOfWords[random_words] = numberOfWords[totalNumberOfWords-1]; totalNumberOfWords--; letter_present_in_word = word.length(); //for example,suppose random word if MONDAY , then letter_present_in_word is 6 } else //All word from numberOfWord[] is traverse then player either choose restart game or exit game. { int result = JOptionPane.showOptionDialog(this, "DO YOU WANT TO PLAY GAME AGAIN","WORD_PUZZLE" , JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE, null, null, null); if(result == JOptionPane.OK_OPTION) { this.setVisible(false); LetterArrangement LA= new LetterArrangement(); LA.setVisible(true); } else System.exit(0); } } /* 1. this methods helps to visibility of boxes i.e JLabel and JButton 2. Suppose word = "HELP" then only 4 Boxes Visible as a output i.e JLabel and JButton */ public void setVisibleBoxes() { for(int i=0 ; i < letter_present_in_word;i++) { switch(i) { case 0 : jLabel1.setVisible(true); break; case 1 : jLabel2.setVisible(true); jLabel3.setVisible(false); jLabel4.setVisible(false); jLabel5.setVisible(false); jLabel6.setVisible(false); jButton2.setVisible(true); jButton3.setVisible(false); jButton4.setVisible(false); jButton5.setVisible(false); jButton6.setVisible(false); break; case 2 : jLabel3.setVisible(true); jLabel4.setVisible(false); jLabel5.setVisible(false); jLabel6.setVisible(false); jButton3.setVisible(true); jButton4.setVisible(false); jButton5.setVisible(false); jButton6.setVisible(false); break; case 3 : jLabel4.setVisible(true); jLabel5.setVisible(false); jLabel6.setVisible(false); jButton4.setVisible(true); jButton5.setVisible(false); jButton6.setVisible(false); break; case 4 : jLabel5.setVisible(true); jLabel6.setVisible(false); jButton5.setVisible(true); jButton6.setVisible(false); break; case 5 : jLabel6.setVisible(true); jButton6.setVisible(true); } } } /* 1. this method helps--place words's letter randomly on each button i.e{jButton1,jButton2,jButton3,jButton4,jButton5,jButton6} 2. for example,word = "MONDAY" then each letter from word place on button[] i.e {jButton1,jButton2,jButton3,jButton4,jButton5,jButton6} */ public void setValuesOnBox() { JButton[] collectionOfButton={jButton1,jButton2,jButton3,jButton4,jButton5,jButton6}; int copyOfnumberofEachChar = letter_present_in_word; char[] wordChar = word.toCharArray(); //put string into arrayOFCharacter like word = "MONDAY" into wordchar[]=['M','O','N','D','A','Y']; for(int m=0 ; m < letter_present_in_word ; m++) { int random_letter=(int)(Math.random()*copyOfnumberofEachChar); collectionOfButton[m].setText(String.valueOf(wordChar[random_letter])); if(random_letter < (copyOfnumberofEachChar-1)) { wordChar[random_letter] = wordChar[copyOfnumberofEachChar-1]; } copyOfnumberofEachChar--; } } /* 1. this method helps, set text on JLabel ,iff JLabel's text is Empty i.e JLabel1 = "" 2. when click on any button,suppose player click on jbutton1 after clicking on JButton1 the text on that button is copy to Label 3. for Example--JButton1 has text "M",whenever player click on JButton1,then at JLabel i.e{JLabel1,JLabel2,JLabel2,JLabel4,JLabel5,JLabel6} any one which has a empty text ,then letter "M" is Place on that JLabel i.e JLabel.setText(JButton1.getText) 4. this method also helps,Counting Number of moves 5. player has only 12 move for each game 6. if number of moves = 0, then player has 2 option first is try again and second is exit from game. */ public void setValuesOnLabel(JButton b) { if(moves > 0) //every time moves decrement { if(jLabel1.getText() == "") { jLabel1.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } else if(jLabel2.getText() == "") { jLabel2.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } else if(jLabel3.getText() == "") { jLabel3.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } else if(jLabel4.getText() == "") { jLabel4.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } else if(jLabel5.getText() == "") { jLabel5.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } else if(jLabel6.getText() == "") { jLabel6.setText(b.getText()); jLabel7.setText("MOVE : "+(--moves)); } } else //this block indicates when moves = 0,player can be exit from game or can be try again same puzzle { int result = JOptionPane.showOptionDialog(this, "TRY AGAIN","" , JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE, null, null, null); if(result == JOptionPane.OK_OPTION) { jLabel7.setText("MOVE : 12 "); resetAllValuesFromLabel(); ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; moves = 12; } else System.exit(0); } } // this method helps,put empty text on Label , whenever from ClickButton1 to ClickButton6 is equal to false public void reverseletter(JButton b) { if(b.getText() == jLabel1.getText()) jLabel1.setText(""); else if(b.getText() == jLabel2.getText()) jLabel2.setText(""); else if(b.getText() == jLabel3.getText()) jLabel3.setText(""); else if(b.getText() == jLabel4.getText()) jLabel4.setText(""); else if(b.getText() == jLabel5.getText()) jLabel5.setText(""); else if(b.getText() == jLabel6.getText()) jLabel6.setText(""); } /* 1. This method helps,Checking Winning Possibility 2. When letter arrage in correct position , winningCondition return 1 anotherwise it return 0 */ public int winningCondition() { boolean f=true; JLabel[] j={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6}; for(int i=0 ; i < letter_present_in_word ; i++) { if(!(j[i].getText().equals(String.valueOf(word.charAt(i))))) { f=false; return 0; } } if(f == true) { JOptionPane.showMessageDialog(this, "YOU WIN"); resetAllValuesFromLabel(); randomWordsFromNumberOfWords(); setVisibleBoxes(); setValuesOnBox(); return 1; } return 0; } /* 1. After winning game we have to set JLabel text empty i.e JLabel1 = "" 2. so method helps to remove letter from JLabel. */ public void resetAllValuesFromLabel() { JLabel[] j={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6}; for(int i=0 ; i < letter_present_in_word ;i++) j[i].setText(""); jLabel7.setText("MOVE : 12"); moves=12; } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel7.setText("MOVE : 12"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(48, 48, 48) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, 0) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0))) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap(71, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(28, 28, 28) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(46, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(71, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(28, 28, 28) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(30, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton1) //if ClickButton1 = true then set text on JLabel { setValuesOnLabel(jButton1); ClickButton1=false; if(winningCondition() == 1) //When all letter arrange in correct position , winningCondition method return 1 { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton1=true; reverseletter(jButton1); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton2) { setValuesOnLabel(jButton2); ClickButton2=false; if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton2=true; reverseletter(jButton2); } } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton3) { setValuesOnLabel(jButton3); ClickButton3=false; if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton3=true; reverseletter(jButton3); } } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton4) { setValuesOnLabel(jButton4); ClickButton4=false; if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton4=true; reverseletter(jButton4); } } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton5) { setValuesOnLabel(jButton5); ClickButton5=false; if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton5=true; reverseletter(jButton5); if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { if(ClickButton6) { setValuesOnLabel(jButton6); ClickButton6=false; if(winningCondition() == 1) { ClickButton1=true; ClickButton2=true; ClickButton3=true; ClickButton4=true; ClickButton5=true; ClickButton6=true; } } else { ClickButton6=true; reverseletter(jButton6); } } //System generated Code Don't write anything in that public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(LetterArrangement.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(LetterArrangement.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(LetterArrangement.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(LetterArrangement.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new LetterArrangement().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JPanel jPanel1; // End of variables declaration } |
For more reference ::





Comments
Post a Comment