Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. Random rand= new Random();
  2. int min=3 ;
  3. int max=10;
  4. int longest,shorter1,shorter2;
  5. int i;
  6. int input1;
  7.  
  8.  
  9.  
  10. /**
  11. * Creates new form U3A3_gerald_smithGui
  12. */
  13. public U3A3_gerald_smithGui() {
  14. initComponents();
  15. }
  16.  
  17. /**
  18. * This method is called from within the constructor to initialize the form.
  19. * WARNING: Do NOT modify this code. The content of this method is always
  20. * regenerated by the Form Editor.
  21. */
  22. @SuppressWarnings("unchecked")
  23. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  24. private void initComponents() {
  25.  
  26. titleLabel = new javax.swing.JLabel();
  27. questionLabel = new javax.swing.JLabel();
  28. userInput = new javax.swing.JTextField();
  29. calculateButton = new javax.swing.JButton();
  30. jScrollPane2 = new javax.swing.JScrollPane();
  31. displayText2 = new javax.swing.JTextArea();
  32. jLabel1 = new javax.swing.JLabel();
  33. goButton = new javax.swing.JButton();
  34. jScrollPane1 = new javax.swing.JScrollPane();
  35. displayText1 = new javax.swing.JTextArea();
  36.  
  37. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  38.  
  39. titleLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  40. titleLabel.setText("Triangles");
  41.  
  42. questionLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  43. questionLabel.setText("How many triangles would you like?");
  44.  
  45. userInput.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(102, 255, 204)));
  46. userInput.addActionListener(new java.awt.event.ActionListener() {
  47. public void actionPerformed(java.awt.event.ActionEvent evt) {
  48. userInputActionPerformed(evt);
  49. }
  50. });
  51.  
  52. calculateButton.setText("Calculate");
  53.  
  54. displayText2.setColumns(20);
  55. displayText2.setRows(5);
  56. displayText2.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(102, 255, 204)));
  57. jScrollPane2.setViewportView(displayText2);
  58.  
  59. jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  60. jLabel1.setText("What kind of triangles are they? ");
  61.  
  62. goButton.setText("Go");
  63. goButton.addActionListener(new java.awt.event.ActionListener() {
  64. public void actionPerformed(java.awt.event.ActionEvent evt) {
  65. goButtonActionPerformed(evt);
  66. }
  67. });
  68.  
  69. displayText1.setColumns(20);
  70. displayText1.setRows(5);
  71. jScrollPane1.setViewportView(displayText1);
  72.  
  73. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  74. getContentPane().setLayout(layout);
  75. layout.setHorizontalGroup(
  76. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  77. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  78. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  79. .addGroup(layout.createSequentialGroup()
  80. .addGap(0, 80, Short.MAX_VALUE)
  81. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  82. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  83. .addComponent(jLabel1)
  84. .addGap(18, 18, 18))
  85. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  86. .addComponent(calculateButton)
  87. .addGap(102, 102, 102))))
  88. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  89. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  90. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  91. .addGap(28, 28, 28)))
  92. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  93. .addGroup(layout.createSequentialGroup()
  94. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95. .addGroup(layout.createSequentialGroup()
  96. .addGap(146, 146, 146)
  97. .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
  98. .addGroup(layout.createSequentialGroup()
  99. .addGap(76, 76, 76)
  100. .addComponent(questionLabel))
  101. .addGroup(layout.createSequentialGroup()
  102. .addGap(156, 156, 156)
  103. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104. .addComponent(goButton)
  105. .addComponent(userInput, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))))
  106. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  107. );
  108. layout.setVerticalGroup(
  109. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addGroup(layout.createSequentialGroup()
  111. .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
  112. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  113. .addComponent(questionLabel)
  114. .addGap(22, 22, 22)
  115. .addComponent(userInput, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
  116. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  117. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  118. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
  119. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
  120. .addContainerGap(105, Short.MAX_VALUE))
  121. .addGroup(layout.createSequentialGroup()
  122. .addGap(28, 28, 28)
  123. .addComponent(goButton)
  124. .addGap(37, 37, 37)
  125. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  126. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  127. .addComponent(calculateButton)
  128. .addGap(41, 41, 41)
  129. .addComponent(jLabel1)
  130. .addGap(42, 42, 42))))
  131. );
  132.  
  133. pack();
  134. }// </editor-fold>
  135.  
  136. private void userInputActionPerformed(java.awt.event.ActionEvent evt) {
  137. // TODO add your handling code here:
  138. }
  139.  
  140. @SuppressWarnings("empty-statement")
  141. private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
  142. String input = (String)userInput.getText();
  143. int input1 = Integer.parseInt(input);
  144. int side1=rand.nextInt(max-min+1)+min;
  145. int side2=rand.nextInt(max-min+1)+min;
  146. int side3=rand.nextInt(max-min+1)+min;
  147. String outputString="The sides are,"+"n";
  148. for(int i=1;i<=input1;i++);{
  149. outputString=outputString+side1+","+side2+","+side3;
  150. }
  151.  
  152. displayText1.setText(outputString);
  153.  
  154.  
  155.  
  156. if (side1>=side2&&side1>=side3){
  157. longest=side1;
  158. shorter1=side2;
  159. shorter2=side3;
  160. }else if(side2>=side3&&side2>=side1){
  161. longest=side2;
  162. shorter1=side1;
  163. shorter2=side3;
  164. } else{
  165. longest=side3;
  166. shorter1=side1;
  167. shorter2=side2;
  168.  
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. }
  183.  
  184. /**
  185. * @param args the command line arguments
  186. */
  187. public static void main(String args[]) {
  188. /* Set the Nimbus look and feel */
  189. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  190. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  191. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  192. */
  193. try {
  194. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  195. if ("Nimbus".equals(info.getName())) {
  196. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  197. break;
  198. }
  199. }
  200. } catch (ClassNotFoundException ex) {
  201. java.util.logging.Logger.getLogger(U3A3_gerald_smithGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  202. } catch (InstantiationException ex) {
  203. java.util.logging.Logger.getLogger(U3A3_gerald_smithGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  204. } catch (IllegalAccessException ex) {
  205. java.util.logging.Logger.getLogger(U3A3_gerald_smithGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  206. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  207. java.util.logging.Logger.getLogger(U3A3_gerald_smithGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  208. }
  209. //</editor-fold>
  210.  
  211. /* Create and display the form */
  212. java.awt.EventQueue.invokeLater(new Runnable() {
  213. public void run() {
  214. new U3A3_gerald_smithGui().setVisible(true);
  215. }
  216. });
  217. }
  218.  
  219. // Variables declaration - do not modify
  220. private javax.swing.JButton calculateButton;
  221. private javax.swing.JTextArea displayText1;
  222. private javax.swing.JTextArea displayText2;
  223. private javax.swing.JButton goButton;
  224. private javax.swing.JLabel jLabel1;
  225. private javax.swing.JScrollPane jScrollPane1;
  226. private javax.swing.JScrollPane jScrollPane2;
  227. private javax.swing.JLabel questionLabel;
  228. private javax.swing.JLabel titleLabel;
  229. private javax.swing.JTextField userInput;
  230. // End of variables declaration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement