简体   繁体   中英

How to change the background color for these buttons one by one when I click check all connections

Click Here to Show the application snip pic

I want to set the background color in order to the connection status but one by one. I do it but the background of all of them changes after the checking. how can I do it?!!

The Check all action performed

private void checkAllActionPerformed(java.awt.event.ActionEvent evt) {                                         

    this.cairobtnActionPerformed(evt);
    this.gizabtnActionPerformed(evt);
    this.alexbtnActionPerformed(evt);
    this.zagbtnActionPerformed(evt);
    this.asutbtnActionPerformed(evt);
    this.tantabtnActionPerformed(evt);
    this.kenabtnActionPerformed(evt);
    this.mansbtnActionPerformed(evt);
    this.meniabtnActionPerformed(evt);

}     

The action performed of cairobtn

private void cairobtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
    if (isSocketAliveUitlitybyCrunchify(IP String, port number)) {
        cairobtn.setBackground(Color.GREEN);
    } else {
        cairobtn.setBackground(Color.RED);
    }
}

Unfortunately, it's almost impossible to answer your question. There is no way to reproduce anything here. If you want people to help you here, you have to provide a working sample that reproduces the error you see. Please see https://stackoverflow.com/help/mcve

However, the error is likely to come from the method isSocketAliveUitlitybyCrunchify which either doesn't behave as you expect it to do or doen't get the expected arguments (each of which is impossible to verify with the provided information)

Side notes:

  1. Your java syntax is doubtful. The line:

     if (isSocketAliveUitlitybyCrunchify(IP String, port number)) { 

    is clearly not java syntax (see arguments)

  2. Also, if all your methods *btnActionPerformed performs exactly the same action, I'd advise you to make one method btnActionPerformed(ActionEvent, Button) and call it with each button. Plus, you can pack your buttons in an array or a Collection to better the code.

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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