程序描述:人们使用 jsliders 输入用户分数,然后在游戏结束时点击 Check Scores 按钮,它会告诉你谁获得了第一、第二、第三等。
我不确定的是如何让程序告诉我得分最高的球员姓名。我把它排序了,它告诉你实际的分数,只是没有名字。
我本质上是在寻找这个:
firstplace.setText(firstplacename + " got first place with a score of " + Integer.toString(first));
编码:
/* * 要更改此模板,请选择工具 | 模板 * 并在编辑器中打开模板。 */ 包装怪异; 导入 java.lang.reflect.Array; 导入 java.util.Arrays; /** * * @作者安德鲁 */ 公共类 FunglishFrame 扩展 javax.swing.JFrame { /** * 创建新表单 FunglishFrame */ 公共 FunglishFrame() { 初始化组件(); } /** * 从构造函数中调用此方法以初始化表单。 * 警告:请勿修改此代码。这个方法的内容总是 * 由表单编辑器重新生成。 */ @SuppressWarnings("未选中") 私人无效jButton1ActionPerformed(java.awt.event.ActionEvent evt){ 字符串 player1name = player1.getText(); jTabbedPane1.setTitleAt(0, player1name); 字符串 player2name = player2.getText(); jTabbedPane1.setTitleAt(1, player2name); 字符串 player3name = player3.getText(); jTabbedPane1.setTitleAt(2, player3name); 字符串 player4name = player4.getText(); jTabbedPane1.setTitleAt(3, player4name); 字符串 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); } 私人无效jSlider15StateChanged(javax.swing.event.ChangeEvent evt){ int value15 = jSlider15.getValue(); slidernumber15.setText(Integer.toString(value15)); } 私人无效jSlider14StateChanged(javax.swing.event.ChangeEvent evt){ int value14 = jSlider14.getValue(); slidernumber14.setText(Integer.toString(value14)); } 私人无效jSlider13StateChanged(javax.swing.event.ChangeEvent evt){ int value13 = jSlider13.getValue(); slidernumber13.setText(Integer.toString(value13)); } 私人无效jSlider12StateChanged(javax.swing.event.ChangeEvent evt){ int value12 = jSlider12.getValue(); slidernumber12.setText(Integer.toString(value12)); } 私人无效jSlider11StateChanged(javax.swing.event.ChangeEvent evt){ int value11 = jSlider11.getValue(); slidernumber11.setText(Integer.toString(value11)); } 私人无效jSlider5StateChanged(javax.swing.event.ChangeEvent evt){ int value5 = jSlider5.getValue(); slidernumber5.setText(Integer.toString(value5)); } 私人无效jSlider4StateChanged(javax.swing.event.ChangeEvent evt){ int value4 = jSlider4.getValue(); slidernumber4.setText(Integer.toString(value4)); } 私人无效jSlider3StateChanged(javax.swing.event.ChangeEvent evt){ int value3 = jSlider3.getValue(); slidernumber3.setText(Integer.toString(value3)); } 私人无效jSlider2StateChanged(javax.swing.event.ChangeEvent evt){ int value2 = jSlider2.getValue(); slidernumber2.setText(Integer.toString(value2)); } 私人无效jSlider1StateChanged(javax.swing.event.ChangeEvent evt){ int value1 = jSlider1.getValue(); slidernumber1.setText(Integer.toString(value1)); } 私人无效jSlider6StateChanged(javax.swing.event.ChangeEvent evt){ int value6 = jSlider6.getValue(); slidernumber6.setText(Integer.toString(value6)); } 私人无效jSlider7StateChanged(javax.swing.event.ChangeEvent evt){ int value7 = jSlider7.getValue(); slidernumber7.setText(Integer.toString(value7)); } 私人无效jSlider8StateChanged(javax.swing.event.ChangeEvent evt){ int value8 = jSlider8.getValue(); slidernumber8.setText(Integer.toString(value8)); } 私人无效jSlider9StateChanged(javax.swing.event.ChangeEvent evt){ int value9 = jSlider9.getValue(); slidernumber9.setText(Integer.toString(value9)); } 私人无效jSlider10StateChanged(javax.swing.event.ChangeEvent evt){ int value10 = jSlider10.getValue(); slidernumber10.setText(Integer.toString(value10)); } 私人无效jSlider16StateChanged(javax.swing.event.ChangeEvent evt){ int value16 = jSlider16.getValue(); slidernumber16.setText(Integer.toString(value16)); } 私人无效 jSlider17StateChanged(javax.swing.event.ChangeEvent evt){ int value17 = jSlider17.getValue(); slidernumber17.setText(Integer.toString(value17)); } 私人无效jSlider18StateChanged(javax.swing.event.ChangeEvent evt){ int value18 = jSlider18.getValue(); slidernumber18.setText(Integer.toString(value18)); } 私人无效jSlider19StateChanged(javax.swing.event.ChangeEvent evt){ int value19 = jSlider19.getValue(); slidernumber19.setText(Integer.toString(value19)); } 私人无效jSlider20StateChanged(javax.swing.event.ChangeEvent evt){ int value20 = jSlider20.getValue(); slidernumber20.setText(Integer.toString(value20)); } 私人无效jSlider21StateChanged(javax.swing.event.ChangeEvent evt){ int value21 = jSlider21.getValue(); slidernumber21.setText(Integer.toString(value21)); } 私人无效jSlider22StateChanged(javax.swing.event.ChangeEvent evt){ int value22 = jSlider22.getValue(); slidernumber22.setText(Integer.toString(value22)); } 私人无效jSlider23StateChanged(javax.swing.event.ChangeEvent evt){ int value23 = jSlider23.getValue(); slidernumber23.setText(Integer.toString(value23)); } 私人无效jSlider24StateChanged(javax.swing.event.ChangeEvent evt){ int value24 = jSlider24.getValue(); slidernumber24.setText(Integer.toString(value24)); } 私人无效jSlider25StateChanged(javax.swing.event.ChangeEvent evt){ int value25 = jSlider25.getValue(); slidernumber25.setText(Integer.toString(value25)); } 私人无效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[] 分数 = {player1score,player2score,player3score,player4score,player5score}; Arrays.sort(scores); int first = Array.getInt(scores,4); int second = Array.getInt(scores,3); int 第三 = Array.getInt(scores,2); int 第四 = Array.getInt(scores,1); int 第五 = 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)); } // 变量声明 - 不要修改 私有 javax.swing.JLabel 第五名; 私有 javax.swing.JLabel 第一名; 私有 javax.swing.JLabel 第四名; 私有 javax.swing.JButton jButton1; 私有 javax.swing.JButton jButton2; 私有 javax.swing.JLabel jLabel1; 私有 javax.swing.JPanel jPanel1; 私有 javax.swing.JPanel jPanel2; 私有 javax.swing.JPanel jPanel3; 私有 javax.swing.JPanel jPanel4; 私有 javax.swing.JPanel jPanel5; 私有 javax.swing.JPanel jPanel6; 私有 javax.swing.JSlider jSlider1; 私有 javax.swing.JSlider jSlider10; 私有 javax.swing.JSlider jSlider11; 私有 javax.swing.JSlider jSlider12; 私有 javax.swing.JSlider jSlider13; 私有 javax.swing.JSlider jSlider14; 私有 javax.swing.JSlider jSlider15; 私有 javax.swing.JSlider jSlider16; 私有 javax.swing.JSlider jSlider17; 私有 javax.swing.JSlider jSlider18; 私有 javax.swing.JSlider jSlider19; 私有 javax.swing.JSlider jSlider2; 私有 javax.swing.JSlider jSlider20; 私有 javax.swing.JSlider jSlider21; 私有 javax.swing.JSlider jSlider22; 私有 javax.swing.JSlider jSlider23; 私有 javax.swing.JSlider jSlider24; 私有 javax.swing.JSlider jSlider25; 私有 javax.swing.JSlider jSlider3; 私有 javax.swing.JSlider jSlider4; 私有 javax.swing.JSlider jSlider5; 私有 javax.swing.JSlider jSlider6; 私有 javax.swing.JSlider jSlider7; 私有 javax.swing.JSlider jSlider8; 私有 javax.swing.JSlider jSlider9; 私有 javax.swing.JTabbedPane jTabbedPane1; 私有 javax.swing.JTextField player1; 私有 javax.swing.JTextField player2; 私有 javax.swing.JTextField player3; 私有 javax.swing.JTextField player4; 私有 javax.swing.JTextField player5; 私有 javax.swing.JLabel 点名1; 私有 javax.swing.JLabel pointsname10; 私有 javax.swing.JLabel pointsname11; 私有 javax.swing.JLabel pointsname12; 私有 javax.swing.JLabel pointsname13; 私有 javax.swing.JLabel pointsname14; 私有 javax.swing.JLabel pointsname15; 私有 javax.swing.JLabel pointsname16; 私有 javax.swing.JLabel pointsname17; 私有 javax.swing.JLabel pointsname18; 私有 javax.swing.JLabel pointsname19; 私有 javax.swing.JLabel 点名2; 私有 javax.swing.JLabel 点名20; 私有 javax.swing.JLabel 点名21; 私有 javax.swing.JLabel pointsname22; 私有 javax.swing.JLabel pointsname23; 私有 javax.swing.JLabel pointsname24; 私有 javax.swing.JLabel pointsname25; 私有 javax.swing.JLabel 点名3; 私有 javax.swing.JLabel 点名4; 私有 javax.swing.JLabel 点名5; 私有 javax.swing.JLabel 点名6; 私有 javax.swing.JLabel 点名7; 私有 javax.swing.JLabel 点名8; 私有 javax.swing.JLabel pointsname9; 私有 javax.swing.JLabel 第二名; 私有 javax.swing.JLabel 滑块编号1; 私有 javax.swing.JLabel 滑块编号 10; 私有 javax.swing.JLabel 滑块编号 11; 私有 javax.swing.JLabel 滑块编号 12; 私有 javax.swing.JLabel 滑块编号 13; 私有 javax.swing.JLabel 滑块编号 14; 私有 javax.swing.JLabel 滑块编号 15; 私有 javax.swing.JLabel 滑块编号 16; 私有 javax.swing.JLabel 滑块编号17; 私有 javax.swing.JLabel 滑块编号18; 私有 javax.swing.JLabel 滑块编号 19; 私有 javax.swing.JLabel 滑块编号2; 私有 javax.swing.JLabel 滑块编号20; 私有 javax.swing.JLabel 滑块编号 21; 私有 javax.swing.JLabel 滑块编号22; 私有 javax.swing.JLabel 滑块编号23; 私有 javax.swing.JLabel 滑块编号 24; 私有 javax.swing.JLabel 滑块编号 25; 私有 javax.swing.JLabel 滑块编号3; 私有 javax.swing.JLabel 滑块编号4; 私有 javax.swing.JLabel 滑块编号5; 私有 javax.swing.JLabel 滑块编号6; 私有 javax.swing.JLabel 滑块编号7; 私有 javax.swing.JLabel 滑块编号8; 私有 javax.swing.JLabel 滑块编号9; 私有 javax.swing.JLabel 第三名; // 变量声明结束 }