我怎样才能让我的程序找到得分最高的人?

时间:2013-01-31 00:10:15

标签: arrays input

程序描述:人们使用jsliders输入用户分数,然后在游戏结束时点击Check Scores按钮,它会告诉你谁获得了第一个第二个等等。

我不确定的是如何让程序告诉我获得最高分的球员名称。我把它排序了,它告诉你实际得分只是没有它的名字。

我基本上是在寻找这个:

firstplace.setText(firstplacename + " got first place with a score of " + Integer.toString(first));

代码:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package funglish;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 *
 * @author Andrew
 */
public class FunglishFrame extends javax.swing.JFrame {

    /**
     * Creates new form FunglishFrame
     */
    public FunglishFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")                     

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String player1name = player1.getText();
        jTabbedPane1.setTitleAt(0, player1name);

        String player2name = player2.getText();
        jTabbedPane1.setTitleAt(1, player2name);

        String player3name = player3.getText();
        jTabbedPane1.setTitleAt(2, player3name);

        String player4name = player4.getText();
        jTabbedPane1.setTitleAt(3, player4name);

        String player5name = player5.getText();
        jTabbedPane1.setTitleAt(4, player5name);

        pointsname1.setText(player1name);
        pointsname2.setText(player2name);
        pointsname3.setText(player3name);
        pointsname4.setText(player4name);
        pointsname5.setText(player5name);
        pointsname6.setText(player1name);
        pointsname7.setText(player2name);
        pointsname8.setText(player3name);
        pointsname9.setText(player4name);
        pointsname10.setText(player5name);
        pointsname14.setText(player1name);
        pointsname13.setText(player2name);
        pointsname15.setText(player3name);
        pointsname12.setText(player4name);
        pointsname11.setText(player5name);
        pointsname16.setText(player1name);
        pointsname17.setText(player2name);
        pointsname18.setText(player3name);
        pointsname19.setText(player4name);
        pointsname20.setText(player5name);
        pointsname21.setText(player1name);
        pointsname22.setText(player2name);
        pointsname23.setText(player3name);
        pointsname24.setText(player4name);
        pointsname25.setText(player5name);

    }                                        

    private void jSlider15StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value15 = jSlider15.getValue();
        slidernumber15.setText(Integer.toString(value15));
    }                                      

    private void jSlider14StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value14 = jSlider14.getValue();
        slidernumber14.setText(Integer.toString(value14));
    }                                      

    private void jSlider13StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value13 = jSlider13.getValue();
        slidernumber13.setText(Integer.toString(value13));
    }                                      

    private void jSlider12StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value12 = jSlider12.getValue();
        slidernumber12.setText(Integer.toString(value12));
    }                                      

    private void jSlider11StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value11 = jSlider11.getValue();
        slidernumber11.setText(Integer.toString(value11));
    }                                      

    private void jSlider5StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value5 = jSlider5.getValue();
        slidernumber5.setText(Integer.toString(value5));
    }                                     

    private void jSlider4StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value4 = jSlider4.getValue();
        slidernumber4.setText(Integer.toString(value4));
    }                                     

    private void jSlider3StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value3 = jSlider3.getValue();
        slidernumber3.setText(Integer.toString(value3));
    }                                     

    private void jSlider2StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value2 = jSlider2.getValue();
        slidernumber2.setText(Integer.toString(value2));
    }                                     

    private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value1 = jSlider1.getValue();
        slidernumber1.setText(Integer.toString(value1));
    }                                     

    private void jSlider6StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value6 = jSlider6.getValue();
        slidernumber6.setText(Integer.toString(value6));
    }                                     

    private void jSlider7StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value7 = jSlider7.getValue();
        slidernumber7.setText(Integer.toString(value7));
    }                                     

    private void jSlider8StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value8 = jSlider8.getValue();
        slidernumber8.setText(Integer.toString(value8));
    }                                     

    private void jSlider9StateChanged(javax.swing.event.ChangeEvent evt) {                                      
        int value9 = jSlider9.getValue();
        slidernumber9.setText(Integer.toString(value9));
    }                                     

    private void jSlider10StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value10 = jSlider10.getValue();
        slidernumber10.setText(Integer.toString(value10));
    }                                      

    private void jSlider16StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value16 = jSlider16.getValue();
        slidernumber16.setText(Integer.toString(value16));
    }                                      

    private void jSlider17StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value17 = jSlider17.getValue();
        slidernumber17.setText(Integer.toString(value17));
    }                                      

    private void jSlider18StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value18 = jSlider18.getValue();
        slidernumber18.setText(Integer.toString(value18));
    }                                      

    private void jSlider19StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value19 = jSlider19.getValue();
        slidernumber19.setText(Integer.toString(value19));
    }                                      

    private void jSlider20StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value20 = jSlider20.getValue();
        slidernumber20.setText(Integer.toString(value20));
    }                                      

    private void jSlider21StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value21 = jSlider21.getValue();
        slidernumber21.setText(Integer.toString(value21));
    }                                      

    private void jSlider22StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value22 = jSlider22.getValue();
        slidernumber22.setText(Integer.toString(value22));
    }                                      

    private void jSlider23StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value23 = jSlider23.getValue();
        slidernumber23.setText(Integer.toString(value23));
    }                                      

    private void jSlider24StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value24 = jSlider24.getValue();
        slidernumber24.setText(Integer.toString(value24));
    }                                      

    private void jSlider25StateChanged(javax.swing.event.ChangeEvent evt) {                                       
        int value25 = jSlider25.getValue();
        slidernumber25.setText(Integer.toString(value25));
    }                                      

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int a1 = jSlider1.getValue();
        int a2 = jSlider6.getValue();
        int a3 = jSlider14.getValue();
        int a4 = jSlider16.getValue();
        int a5 = jSlider21.getValue();

        int b1 = jSlider2.getValue();
        int b2 = jSlider7.getValue();
        int b3 = jSlider13.getValue();
        int b4 = jSlider17.getValue();
        int b5 = jSlider22.getValue();

        int c1 = jSlider3.getValue();
        int c2 = jSlider8.getValue();
        int c3 = jSlider15.getValue();
        int c4 = jSlider18.getValue();
        int c5 = jSlider23.getValue();

        int d1 = jSlider4.getValue();
        int d2 = jSlider9.getValue();
        int d3 = jSlider12.getValue();
        int d4 = jSlider19.getValue();
        int d5 = jSlider24.getValue();

        int e1 = jSlider5.getValue();
        int e2 = jSlider10.getValue();
        int e3 = jSlider11.getValue();
        int e4 = jSlider20.getValue();
        int e5 = jSlider25.getValue();

        int player1score = a1 + a2 + a3 + a4 + a5;
        int player2score = b1 + b2 + b3 + b4 + b5;
        int player3score = c1 + c2 + c3 + c4 + c5;
        int player4score = d1 + d2 + d3 + d4 + d5;
        int player5score = e1 + e2 + e3 + e4 + e5;

        int[] scores = {player1score,player2score,player3score,player4score,player5score};  

        Arrays.sort(scores);

        int first = Array.getInt(scores,4);
        int second = Array.getInt(scores,3);
        int third = Array.getInt(scores,2);
        int fourth = Array.getInt(scores,1);
        int fifth = Array.getInt(scores,0);

        firstplace.setText(Integer.toString(first));
        secondplace.setText(Integer.toString(second));
        thirdplace.setText(Integer.toString(third));
        fourthplace.setText(Integer.toString(fourth));
        fifthplace.setText(Integer.toString(fifth));
    }                                        

    // Variables declaration - do not modify                     
    private javax.swing.JLabel fifthplace;
    private javax.swing.JLabel firstplace;
    private javax.swing.JLabel fourthplace;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JSlider jSlider10;
    private javax.swing.JSlider jSlider11;
    private javax.swing.JSlider jSlider12;
    private javax.swing.JSlider jSlider13;
    private javax.swing.JSlider jSlider14;
    private javax.swing.JSlider jSlider15;
    private javax.swing.JSlider jSlider16;
    private javax.swing.JSlider jSlider17;
    private javax.swing.JSlider jSlider18;
    private javax.swing.JSlider jSlider19;
    private javax.swing.JSlider jSlider2;
    private javax.swing.JSlider jSlider20;
    private javax.swing.JSlider jSlider21;
    private javax.swing.JSlider jSlider22;
    private javax.swing.JSlider jSlider23;
    private javax.swing.JSlider jSlider24;
    private javax.swing.JSlider jSlider25;
    private javax.swing.JSlider jSlider3;
    private javax.swing.JSlider jSlider4;
    private javax.swing.JSlider jSlider5;
    private javax.swing.JSlider jSlider6;
    private javax.swing.JSlider jSlider7;
    private javax.swing.JSlider jSlider8;
    private javax.swing.JSlider jSlider9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField player1;
    private javax.swing.JTextField player2;
    private javax.swing.JTextField player3;
    private javax.swing.JTextField player4;
    private javax.swing.JTextField player5;
    private javax.swing.JLabel pointsname1;
    private javax.swing.JLabel pointsname10;
    private javax.swing.JLabel pointsname11;
    private javax.swing.JLabel pointsname12;
    private javax.swing.JLabel pointsname13;
    private javax.swing.JLabel pointsname14;
    private javax.swing.JLabel pointsname15;
    private javax.swing.JLabel pointsname16;
    private javax.swing.JLabel pointsname17;
    private javax.swing.JLabel pointsname18;
    private javax.swing.JLabel pointsname19;
    private javax.swing.JLabel pointsname2;
    private javax.swing.JLabel pointsname20;
    private javax.swing.JLabel pointsname21;
    private javax.swing.JLabel pointsname22;
    private javax.swing.JLabel pointsname23;
    private javax.swing.JLabel pointsname24;
    private javax.swing.JLabel pointsname25;
    private javax.swing.JLabel pointsname3;
    private javax.swing.JLabel pointsname4;
    private javax.swing.JLabel pointsname5;
    private javax.swing.JLabel pointsname6;
    private javax.swing.JLabel pointsname7;
    private javax.swing.JLabel pointsname8;
    private javax.swing.JLabel pointsname9;
    private javax.swing.JLabel secondplace;
    private javax.swing.JLabel slidernumber1;
    private javax.swing.JLabel slidernumber10;
    private javax.swing.JLabel slidernumber11;
    private javax.swing.JLabel slidernumber12;
    private javax.swing.JLabel slidernumber13;
    private javax.swing.JLabel slidernumber14;
    private javax.swing.JLabel slidernumber15;
    private javax.swing.JLabel slidernumber16;
    private javax.swing.JLabel slidernumber17;
    private javax.swing.JLabel slidernumber18;
    private javax.swing.JLabel slidernumber19;
    private javax.swing.JLabel slidernumber2;
    private javax.swing.JLabel slidernumber20;
    private javax.swing.JLabel slidernumber21;
    private javax.swing.JLabel slidernumber22;
    private javax.swing.JLabel slidernumber23;
    private javax.swing.JLabel slidernumber24;
    private javax.swing.JLabel slidernumber25;
    private javax.swing.JLabel slidernumber3;
    private javax.swing.JLabel slidernumber4;
    private javax.swing.JLabel slidernumber5;
    private javax.swing.JLabel slidernumber6;
    private javax.swing.JLabel slidernumber7;
    private javax.swing.JLabel slidernumber8;
    private javax.swing.JLabel slidernumber9;
    private javax.swing.JLabel thirdplace;
    // End of variables declaration                   
}

1 个答案:

答案 0 :(得分:0)

或许可以通过重写比较方法来对分数进行排序,以获得最高分数到列表顶部。我对此的了解有限,但这可能有所帮助。