Advertisement
Guest User

Untitled

a guest
Jul 1st, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.text.*;
  5. import java.awt.Color;
  6.  
  7. public class GradeCalculator extends JFrame
  8. {
  9.  
  10. JLabel gradeJLabel;
  11. JTextField gradeJTextField;
  12.  
  13. JLabel clickstartJLabel;
  14.  
  15. JButton enterJButton;
  16. JButton clearJButton;
  17. JButton closeJButton;
  18.  
  19. JTextField comentaryJTextField;
  20.  
  21.  
  22. String testscores;
  23. int numberOfScores;
  24.  
  25. double priceValues;
  26.  
  27. int grade;
  28. int counter;
  29. int gradeAccumulator;
  30.  
  31.  
  32. public GradeCalculator()
  33. {
  34. createUserInterface();
  35. }
  36.  
  37. public void createUserInterface()
  38. {
  39. Container contentPane = getContentPane();
  40. contentPane.setBackground(Color.WHITE);
  41. contentPane.setLayout(null);
  42.  
  43. gradeJLabel = new JLabel();
  44. gradeJLabel.setBounds(50, 50, 150, 20);
  45. gradeJLabel.setFont(new Font("Default", Font.PLAIN, 12));
  46. gradeJLabel.setText("Grade:");
  47. gradeJLabel.setForeground(Color.BLACK);
  48. gradeJLabel.setHorizontalAlignment(JLabel.CENTER);
  49. contentPane.add(gradeJLabel);
  50.  
  51. gradeJTextField = new JTextField();
  52. gradeJTextField.setBounds(200, 50, 50, 20);
  53. gradeJTextField.setFont(new Font("Default", Font.PLAIN, 12));
  54. gradeJTextField.setHorizontalAlignment(JTextField.CENTER);
  55. gradeJTextField.setForeground(Color.BLACK);
  56. gradeJTextField.setBackground(Color.WHITE);
  57. gradeJTextField.setEditable(false);
  58. contentPane.add(gradeJTextField);
  59.  
  60. comentaryJTextField = new JTextField();
  61. comentaryJTextField.setBounds(200, 100, 50, 20);
  62. comentaryJTextField.setFont(new Font("Default", Font.PLAIN, 12));
  63. comentaryJTextField.setHorizontalAlignment(JTextField.CENTER);
  64. comentaryJTextField.setForeground(Color.BLACK);
  65. comentaryJTextField.setBackground(Color.WHITE);
  66. comentaryJTextField.setEditable(false);
  67. contentPane.add(comentaryJTextField);
  68.  
  69. clickstartJLabel = new JLabel();
  70. clickstartJLabel.setBounds(100, 200, 150, 20);
  71. clickstartJLabel.setFont(new Font("Default", Font.PLAIN, 12));
  72. clickstartJLabel.setText("Click Start to Begin!");
  73. clickstartJLabel.setForeground(Color.BLACK);
  74. clickstartJLabel.setHorizontalAlignment(JLabel.CENTER);
  75. contentPane.add(clickstartJLabel);
  76.  
  77. enterJButton = new JButton();
  78. enterJButton.setBounds(20, 300, 100, 20);
  79. enterJButton.setFont(new Font("Default", Font.PLAIN, 12));
  80. enterJButton.setText("Enter");
  81. enterJButton.setForeground(Color.BLACK);
  82. enterJButton.setBackground(Color.WHITE);
  83. contentPane.add(enterJButton);
  84. enterJButton.addActionListener(
  85.  
  86. new ActionListener()
  87. {
  88. public void actionPerformed(ActionEvent event)
  89. {
  90. enterJButtonActionPerformed(event);
  91. }
  92. }
  93. );
  94.  
  95. clearJButton = new JButton();
  96. clearJButton.setBounds(140, 300, 100, 20);
  97. clearJButton.setFont(new Font("Default", Font.PLAIN, 12));
  98. clearJButton.setText("Clear");
  99. clearJButton.setForeground(Color.BLACK);
  100. clearJButton.setBackground(Color.WHITE);
  101. contentPane.add(clearJButton);
  102. clearJButton.addActionListener(
  103.  
  104. new ActionListener()
  105. {
  106. public void actionPerformed(ActionEvent event)
  107. {
  108. clearJButtonActionPerformed(event);
  109. }
  110. }
  111. );
  112.  
  113. closeJButton = new JButton();
  114. closeJButton.setBounds(260, 300, 100, 20);
  115. closeJButton.setFont(new Font("Default", Font.PLAIN, 12));
  116. closeJButton.setText("Close");
  117. closeJButton.setForeground(Color.BLACK);
  118. closeJButton.setBackground(Color.WHITE);
  119. contentPane.add(closeJButton);
  120. closeJButton.addActionListener(
  121.  
  122. new ActionListener()
  123. {
  124. public void actionPerformed(ActionEvent event)
  125. {
  126. closeJButtonActionPerformed(event);
  127. }
  128. }
  129. );
  130.  
  131.  
  132. setTitle("Grade Calculator");
  133. setSize(400, 400);
  134. setVisible(true);
  135. }
  136.  
  137. /* main method */
  138. public static void main(String[] args)
  139. {
  140. GradeCalculator application = new GradeCalculator();
  141. application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  142. }
  143.  
  144. public void enterJButtonActionPerformed(ActionEvent event)
  145. {
  146. getnumberoftests();
  147. }
  148.  
  149. public void getnumberoftests()
  150. {
  151. testscores = JOptionPane.showInputDialog("Enter Number of Grades");
  152. numberOfScores = Integer.parseInt(testscores);
  153. gettestscores();
  154. }
  155.  
  156. public void gettestscores()
  157. {
  158. for(counter = 0; counter < numberOfScores; counter++)
  159. {
  160. testscores = JOptionPane.showInputDialog("Enter Scores");
  161. priceValues = Integer.parseInt(testscores);
  162. gradeAccumulator += priceValues;
  163. }
  164.  
  165. calculateAverage();
  166. }
  167.  
  168. public void calculateAverage()
  169. {
  170. grade = gradeAccumulator / numberOfScores;
  171.  
  172. }
  173.  
  174.  
  175. public void checkgrade()
  176. {
  177.  
  178.  
  179. if(grade < 64)
  180. {
  181. comentaryJTextField.setText("F");
  182. }
  183. else if(grade < 69)
  184. {
  185. comentaryJTextField.setText("D");
  186.  
  187. }
  188. else if(grade < 79)
  189.  
  190. {
  191. comentaryJTextField.setText("C");
  192.  
  193. }
  194. else if(grade < 89)
  195.  
  196. {
  197. comentaryJTextField.setText("B");
  198.  
  199. }
  200.  
  201. else {
  202.  
  203. comentaryJTextField.setText("A");
  204.  
  205. }
  206.  
  207. }
  208.  
  209. public void clearJButtonActionPerformed(ActionEvent event)
  210. {
  211. gradeJTextField.setText("");
  212. }
  213.  
  214. public void closeJButtonActionPerformed(ActionEvent event)
  215. {
  216. GradeCalculator.this.dispose();
  217. }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement