简体   繁体   English

Java摆动按钮动作

[英]java swing button action

I'm begginer on java.I want to desing a craps game by using java swing(GUI). 我是Java的初学者,我想使用Java swing(GUI)设计一款掷骰子游戏。 I got the algorithm of the game but i have a problem with GUI design.I have 4 label and textbox for rolling results and summations and one button for rolling eg 我有游戏的算法,但是我在GUI设计上有问题。我有4个标签和文本框用于滚动结果和求和,以及一个用于滚动的按钮,例如

label1: 4-5 textBox1: 9 label1:4-5 textBox1:9
label2: 3-3 textbox2: 6 label2:3-3 textbox2:6
button 纽扣
I want to do like this: when i click the button first time, label1 and textbox1 change; 我想这样做:第一次单击按钮时,label1和textbox1更改; i click again, label2 and textbox2 change. 我再次单击,label2和textbox2更改。 How can I do it like in this order? 我该如何按此顺序操作?
Here is the GUI of my project: https://i.stack.imgur.com/vwNom.png 这是我的项目的GUI: https : //i.stack.imgur.com/vwNom.png

 int  n = rand.nextInt(6) + 1;
 int  n1 = rand.nextInt(6) + 1;
 private void buttonActionPerformed(java.awt.event.ActionEvent evt) {                                       


            jLabel1.setText(Integer.toString(n) + "-" + Integer.toString(n1));
            jTextField1.setText(Integer.toString(n+n1));}
int n = rand.nextInt(6) + 1;
int n1 = rand.nextInt(6) + 1;
boolean label2 = false;

private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
    if (!label2) {
        jLabel1.setText(Integer.toString(n) + "-" + Integer.toString(n1));
        jTextField1.setText(Integer.toString(n + n1));
        label2=true;
    } else if (label2) {
        jLabel2.setText(Integer.toString(n) + "-" + Integer.toString(n1));
        jTextField2.setText(Integer.toString(n + n1));
        label2=false;
    }
}

the boolean flag should work correctly. 布尔标志应正常工作。 now it should first edit label 1 and then label 2 and after that again label 1 现在它应该首先编辑标签1,然后编辑标签2,然后再编辑标签1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM