程序描述:人们使用jsliders输入用户分数,然后在游戏结束时点击按钮检查分数,它会告诉你谁得了第一、第二、第三等分数。
我不确定的是如何让程序告诉我得分最高的球员姓名。我把它分类了,它告诉你实际的分数,只是没有名字。
我基本上是在寻找:
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 }
也许可以通过覆盖比较方法来对分数进行排序,以将最高分数排在列表的顶部。我在这方面的知识有限,但这可能会有所帮助。
我正在做一个关于模拟正在处理的CPU工作的项目。基本上,用户将输入一个工作,该工作的长度将被处理,优先级键(从-20到19,从-20开始以获得更高的优先级)。到目前为止,我已经让所有这些工作,除了程序正确终止。基本上,当我的优先级队列中的所有作业都被处理完时,我需要程序终止。当每个作业被处理时,它将从长度中减去,直到它为0。当它为0时,它将从优先级队列中移除。当没有剩余的作业(优先级队列是空的)时
在第二个while循环(在用户选择抛硬币模拟器选项之后),当用户选择0时,我遇到了问题,程序没有像我希望的那样返回到主菜单,而是停止了,没有循环回到主菜单,让用户选择另一个选项。 有什么办法解决这个问题吗?我不能使用多个方法,因为这是我正在做的一个项目的要求。我已经被困在这一个部分很长时间了,现在(一个星期),并将感激地感谢任何指针或方向。 下面是当用户运行抛硬币模拟器后选择零时我的程序的样子。
我正在开发一个应用程序,它有rest API调用和4个选项卡,使用页面滑动选项卡条,但我的问题是,当我从左向右移动选项卡时,显示页面已经太晚了,并点击了5到8秒为什么?这里我用的是碎片。我的应用程序很像what’s应用程序。 提前谢谢`
我有一个程序正在显示结果的条形图。我想等到用户关闭条形图,继续下一行代码,询问他们是否要为该图输入新信息。 正在发生的是,柱状图的场景将打开,但什么也不会显示,并且JOptionPane立即弹出问题。如果我点击“否”,则显示图表,但程序结束。如果我点击“是”,程序将返回到前面的对话框窗口,但在其他对话框结束之前不会显示图表。 我想等待提示用户,直到他们关闭条形图。在这一点上,我是如此的沮丧,以至于
问题内容: 我应该把包裹放在哪里,以便可以被另一个包裹导入? 问题答案: 设置您的GOPATH。将软件包foo源放入GOPATH / src / optional-whatever / foo / *。go中,并在代码中使用 你 并不 需要显式地安装foo,那么去工具是一个构建工具,它会做自动的为你需要的时候。
当我按住一个按钮时,我很难让我的程序不断发送字符串。我将按钮设置为自动重复,但它仅在按钮释放时发送,而不是在按住时发送。然而,当按住时,计数器会添加应该发送消息的次数。我迷路了。 主窗口。cpp公司 主窗口。h类 根据@dtech建议添加代码 释放按钮后,Arduino中的串行监视器显示发送的所有内容,机器人移动