Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a c++ console application and I am trying to create a GUI for it, but I am lost in all the APIs, so I decided do create instead a Java GUI and send control messages back and forth using TCP. So far it works like a charm, but there is one thing I can't get to work. I need to enable/disable some buttons depending on the state of the c++ app, so my idea is to have a loop which checks for incoming messages, and then updates an integer variable. There would then be ideally two ways to update the buttons:

1 - to have a loop check the int variable and update the button state
2 - to have the variable change trigger an event, and use a listener to
update the button

The GUI was created using Netbeans gui builder, so the jButtons are private and write protected.

Is there a way to implement this?

Here's the code
public class Telis extends javax.swing.JFrame{

    static Socket echoSocket = null;
    static PrintWriter out = null;
    static BufferedReader in = null;
    static String userInput;
    static Integer input;

    /** Creates new form */
    public Telis() {

                /**
                 initialze socket here
                **/

        initComponents();//I removed the implementation of init components, to reduce message length, basically it sets up the view
    }


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        out.println("#EFC0");
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        out.println("#EFC1");
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        out.println("#EFC2");
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        out.println("#EFC3");
    }

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
        out.println("#EFC4");
    }

    private void jButton1PropertyChange(java.beans.PropertyChangeEvent evt) {

    }

    public static void main(String args[]) {

        try {
            out.close();
            in.close();
            echoSocket.close();
        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Telis().setVisible(true);
            }
        });
        while(true){
                   try{
                       userInput = in.readLine();
                       input = userInput.charAt(0) - 48;
                   }catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        }
        }
    }


    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    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.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration
}
Posted
Comments
Richard MacCutchan 22-Jul-10 11:50am    
" I have a c++ console application and I am trying to create a GUI for it".

Console applications do not have GUI interfaces, you should create a Windows application.
figassis 22-Jul-10 11:59am    
It is a windows console application. I'm probably not using the correct term, but its essencially a .exe program wich is run from the windows command line.

1 solution

It should be simple.

In the class Telis you have the memeber variables for each of the buttons so when the input is received you can update the buttons thus:
Java
jButton1.setEnabled(true || false);
 
Share this answer
 
Comments
Richard MacCutchan 3-Nov-10 11:06am    
So that's always true then. :)
Nagy Vilmos 3-Nov-10 16:54pm    
@Richard - It's an example. ;-))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900