Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. import javax.swing.* ;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.util.*;
  5.  
  6. import javax.swing.JButton;
  7.  
  8. public class board extends JFrame implements ActionListener
  9. {
  10. String[][][] word = mysql.getqa();
  11. JButton[] items= new JButton[36];
  12. JButton test;
  13. int countdown = 30;
  14. Random rand = new Random();
  15. int[] cat = new int[6];
  16.  
  17. ImageIcon slot;
  18. ImageIcon none = new ImageIcon("");
  19. ImageIcon one = new ImageIcon("h:/phonebook/a1.gif");
  20. ImageIcon two = new ImageIcon("h:/phonebook/a2.gif");
  21. ImageIcon thr = new ImageIcon("h:/phonebook/a3.gif");
  22. ImageIcon fou = new ImageIcon("h:/phonebook/a4.gif");
  23. ImageIcon fiv = new ImageIcon("h:/phonebook/a5.gif");
  24.  
  25. public board() //constructor
  26. {
  27. cat[0] = rand.nextInt(word.length-1);
  28. cat[1] = rand.nextInt(word.length-1);
  29. cat[2] = rand.nextInt(word.length-1);
  30. cat[3] = rand.nextInt(word.length-1);
  31. cat[4] = rand.nextInt(word.length-1);
  32. cat[5] = rand.nextInt(word.length-1);
  33.  
  34. System.out.print(cat[0] +" "+ cat[1]+" "+ cat[2]+" "+ cat[3]+" "+ cat[4]+" "+cat[5]+"\r\n");
  35.  
  36. while(cat[1]==cat[0]||cat[1]==cat[5]||cat[1]==cat[2]||cat[1]==cat[3]||cat[1]==cat[4]||
  37. cat[2]==cat[0]||cat[2]==cat[1]||cat[2]==cat[5]||cat[2]==cat[3]||cat[2]==cat[4]||
  38. cat[3]==cat[0]||cat[3]==cat[1]||cat[3]==cat[2]||cat[3]==cat[5]||cat[3]==cat[4]||
  39. cat[4]==cat[0]||cat[4]==cat[1]||cat[4]==cat[2]||cat[4]==cat[3]||cat[4]==cat[5]||
  40. cat[5]==cat[0]||cat[5]==cat[1]||cat[5]==cat[2]||cat[5]==cat[3]||cat[5]==cat[4])
  41. {
  42. if( cat[1] == 0 && cat[1]==cat[0]||cat[1]==cat[5]||cat[1]==cat[2]||cat[1]==cat[3]||cat[1]==cat[4])
  43. cat[1]= rand.nextInt(word.length-1);
  44. if( cat[2] == 0&&cat[2]==cat[0]||cat[2]==cat[1]||cat[2]==cat[5]||cat[2]==cat[3]||cat[2]==cat[4])
  45. cat[2]= rand.nextInt(word.length-1);
  46. if( cat[3] == 0&&cat[3]==cat[0]||cat[3]==cat[1]||cat[3]==cat[2]||cat[3]==cat[5]||cat[3]==cat[4])
  47. cat[3]= rand.nextInt(word.length-1);
  48. if( cat[4] == 0&&cat[4]==cat[0]||cat[4]==cat[1]||cat[4]==cat[2]||cat[4]==cat[3]||cat[4]==cat[5])
  49. cat[4]= rand.nextInt(word.length-1);
  50. if( cat[5] == 0&&cat[5]==cat[0]||cat[5]==cat[1]||cat[5]==cat[2]||cat[5]==cat[3]||cat[5]==cat[4])
  51. cat[5]= rand.nextInt(word.length-1);
  52.  
  53. }
  54. cat[0]=cat[0]+1;
  55. cat[1]=cat[1]+1;
  56. cat[2]=cat[2]+1;
  57. cat[3]=cat[3]+1;
  58. cat[4]=cat[4]+1;
  59. cat[5]=cat[5]+1;
  60.  
  61. System.out.print(cat[0] +" "+ cat[1]+" "+ cat[2]+" "+ cat[3]+" "+ cat[4]+" "+cat[5]+"");
  62.  
  63. getContentPane().setLayout(new GridLayout(6,6));
  64.  
  65.  
  66.  
  67. slot = new ImageIcon("");
  68. Font font= new Font("Arial", Font.BOLD, 20);
  69. for (int i=0; i<items.length; i++)
  70. {
  71. if(i>=0&&i<=5)
  72. {
  73. items[i]=new JButton(""+ word[cat[i]][0][0]); //categories
  74. items[i].setBackground(Color.blue);
  75. items[i].setForeground(Color.white);
  76. items[i].setFont(font);
  77. }
  78. if(i>5&&i<=11)
  79. {
  80. items[i]=new JButton(one);
  81. items[i].setActionCommand(""+ i);
  82. items[i].setBackground(Color.blue);
  83. items[i].setForeground(Color.white);
  84. items[i].setFont(font);
  85. }
  86. else if(i>11&&i<=17)
  87. {
  88. items[i]=new JButton(two);
  89. items[i].setActionCommand(""+ i);
  90. items[i].setBackground(Color.blue);
  91. items[i].setForeground(Color.white);
  92. items[i].setFont(font);
  93. }
  94. else if(i>17&&i<=23)
  95. {
  96. items[i]=new JButton(thr);
  97. items[i].setActionCommand(""+ i);
  98. items[i].setBackground(Color.blue);
  99. items[i].setForeground(Color.white);
  100. items[i].setFont(font);
  101. }
  102. else if(i>23&&i<=29)
  103. {
  104. items[i]=new JButton(fou);
  105. items[i].setActionCommand(""+ i);
  106. items[i].setBackground(Color.blue);
  107. items[i].setForeground(Color.white);
  108. items[i].setFont(font);
  109. }
  110. else if(i>29&&i<=35)
  111. {
  112. items[i]=new JButton(fiv);
  113. items[i].setActionCommand(""+ i);
  114. items[i].setBackground(Color.blue);
  115. items[i].setForeground(Color.white);
  116. items[i].setFont(font);
  117. }
  118. getContentPane().add( items[i] );
  119. items[i].addActionListener( (ActionListener) this );
  120. }
  121. }
  122. public void actionPerformed( ActionEvent evt)
  123. {
  124. for(int n=0;n<36;n++)
  125. {
  126.  
  127. if(evt.getActionCommand().equals("" + (n)))
  128. {
  129. if(n>5&&n<=11)//100 [0]
  130. {
  131. Object[] options = { "Answer"};
  132. JOptionPane.showOptionDialog(null, ""+ word[cat[n-6]][1][0], "" + word[n-6][0][0],
  133. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,one, options, options[0]);
  134. items[n].removeActionListener(this);
  135. items[n].setIcon(none);
  136. countdown--;
  137. }
  138. else if(n>11&&n<=17)//200 [1]
  139. {
  140. Object[] options = { "Answer"};
  141. JOptionPane.showOptionDialog(null, ""+ word[cat[n-12]][1][1], "" + word[n-12][0][0],
  142. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,two, options, options[0]);
  143. items[n].removeActionListener(this);
  144. items[n].setIcon(none);
  145. countdown--;
  146. }
  147. else if(n>17&&n<=23)//300 [2]
  148. {
  149. Object[] options = { "Answer"};
  150. JOptionPane.showOptionDialog(null, ""+ word[cat[n-18]][1][2], "" + word[n-18][0][0],
  151. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,thr, options, options[0]);
  152. items[n].removeActionListener(this);
  153. items[n].setIcon(none);
  154. countdown--;
  155. }
  156. else if(n>23&&n<=29)//400 [3]
  157. {
  158. Object[] options = { "Answer"};
  159. JOptionPane.showOptionDialog(null, ""+ word[cat[n-24]][1][3], "" + word[n-24][0][0],
  160. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,fou, options, options[0]);
  161. items[n].removeActionListener(this);
  162. items[n].setIcon(none);
  163. countdown--;
  164. }
  165. else if(n>29&&n<=35)//500 [4]
  166. {
  167. Object[] options = { "Answer"};
  168. JOptionPane.showOptionDialog(null, ""+ word[cat[n-30]][1][4], "" + word[n-30][0][0],
  169. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,fiv, options, options[0]);
  170. items[n].removeActionListener(this);
  171. items[n].setIcon(none);
  172. countdown--;
  173. }
  174.  
  175. if (countdown == 0)//needs to figure out what to do as a final jeopdary question
  176. {
  177. Object[] options = { "Final Jeopdary"};
  178. JOptionPane.showOptionDialog(null, "Some Uber hard Question", "Uber Leet Question",
  179. JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,fiv, options, options[0]);
  180.  
  181. }
  182.  
  183. }
  184. }
  185. }
  186. }
Add Comment
Please, Sign In to add comment