This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

JudgingGUI

By: a guest on Feb 6th, 2013  |  syntax: Java  |  size: 2.59 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.*;
  6.  
  7.  
  8. public class JudgingGUI extends JFrame {
  9.         private JLabel [] judgeName;
  10.         private JTextField [] judgeScore;
  11.         private JLabel contestantName;
  12.         private JTextField name;
  13.         private JButton computeScore;
  14.         private JButton reset;
  15.         private JLabel scoreLabel;
  16.         private JTextField totalScore;
  17.         private judging judges;
  18.         int n=8;
  19.        
  20.         private final int FRAME_WIDTH = 450;
  21.     private final int FRAME_HEIGHT = 200;
  22.  
  23.         public JudgingGUI(int n){
  24.                 super("Judging Scores");
  25.                 setSize(FRAME_WIDTH,FRAME_HEIGHT);
  26.         setLayout(new FlowLayout());
  27.        
  28.        
  29.        
  30.         contestantName = new JLabel ("Contestant Name: ");
  31.         //contestantName.setHorizontalAlignment(SwingConstants.CENTER);
  32.         add(contestantName);
  33.         name = new JTextField(20);
  34.         //name.setHorizontalAlignment(SwingConstants.CENTER);
  35.         add(name);
  36.        
  37.         judgeName = new JLabel[n];
  38.         for (int i=0; i < n; i++){
  39.                 judgeName[i] = new JLabel ("Judge " + (i+1));
  40.                 add(judgeName[i]);             
  41.         }
  42.        
  43.         judgeScore = new JTextField[n];
  44.         for (int j=0; j<n;j++){
  45.                 judgeScore[j] = new JTextField(4);
  46.                 add(judgeScore[j]);
  47.         }
  48.        
  49.         computeScore = new JButton("Compute Score");
  50.         add(computeScore);
  51.          
  52.        
  53.         scoreLabel = new JLabel("Contestant's Score: ");
  54.         add(scoreLabel);
  55.        
  56.         totalScore = new JTextField(5);
  57.         totalScore.setEditable(false);
  58.         add(totalScore);
  59.        
  60.         reset = new JButton("Reset");
  61.         add(reset);
  62.        
  63.         HandlerClass handler = new HandlerClass();
  64.         ResetHandler resetH = new ResetHandler();
  65.         computeScore.addActionListener(handler);
  66.         reset.addActionListener(resetH);
  67.         }
  68.        
  69.         private class HandlerClass implements ActionListener{
  70.                 public void actionPerformed(ActionEvent e){
  71.                         double scores [] = new double[judgeScore.length];
  72.                        
  73.                         for (int i=0; i<judgeScore.length;i++){
  74.                                 scores[i]=Double.parseDouble(judgeScore[i].getText());
  75.                                 if( scores[i]> 10 || scores[i] < 1 ){
  76.                                         JOptionPane.showMessageDialog(null, "The score entered for Judge " + (i+1) + " was not a number bewteen 1 and 10. Try again.");
  77.                                         continue;
  78.                                 }
  79.                         }
  80.                         judging.setScores(scores);
  81.                         judging.calculateScore();
  82.                         double result = judging.getScores();
  83.                        
  84.                 }
  85.                
  86.         }
  87.        
  88.         private class ResetHandler implements ActionListener{
  89.                 public void actionPerformed(ActionEvent e){
  90.                        
  91.                 }      
  92.         }
  93. }
clone this paste RAW Paste Data