Results 1 to 2 of 2
  1. #1
    kendel is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Default Using jActionPerformed Vs jMouseClicked

    I put a System.out.println() to check both cases and it seems the jClicked never gets called when I made a menu Item, so I had to use ActionPerformed...

    Right now it does not work correctly, maybe someone can give me advice..
    I am connecting to a COM Port and I made a button to change to COM port # and update, but right now the number does not change when I click the button....

    I tried making an oldValue and newValue but it doesn't seem to work out well....

    Java Code:
    public class ReadThread extends Thread 
    {
        private boolean sw1;
        private boolean sw2;
        private boolean sw3;
        private boolean sw4;
        private String comValue = "COM1";
        private String newComValue;
        private String oldComValue;
        
       @Override
        public void run()
        {
            CommPortIdentifier portId1;      
            InputStream inputStream;
            SerialPort serialPort1;
            try
            {        
                portId1 = CommPortIdentifier.getPortIdentifier(comValue);
                serialPort1 = (SerialPort) portId1.open("ComControl", 2000);
                serialPort1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
                
                inputStream = serialPort1.getInputStream();
                
                int x = inputStream.read();
                while(true)
                {
                    if(x == 0)
                    {
                        sw1 = true;
                    }
                    if(x == 1)
                    {
                        sw1 = false;
                    }
                    if(x == 2)
                    {
                        sw2 = true;
                    }
                    if(x == 3)
                    {
                        sw2 = false;
                    }
                    if(x == 4)
                    {
                        sw3 = true;
                    }
                    if(x == 5)
                    {
                        sw3 = false;
                    }
                    if(x == 6)
                    {
                        sw4 = true;
                    }
                    if(x == 7)
                    {
                        sw4 = false;
                    }
                    x = inputStream.read();
    
                    if(comValue.equalsIgnoreCase(newComValue) == false)
                    {
                        portId1 = CommPortIdentifier.getPortIdentifier(newComValue);
                        serialPort1 = (SerialPort) portId1.open("ComControl", 2000);
                        serialPort1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    
                        inputStream = serialPort1.getInputStream();
    
                        oldComValue = newComValue;
                    }
    
               }
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        
        public boolean getSW1()
        {
            return sw1;
        }
        
        public boolean getSW2()
        {
            return sw2;
        }
        
        public boolean getSW3()
        {
            return sw3;
        }
        
        public boolean getSW4()
        {
            return sw4;
        }
        
        public void setComPort(String COM)
        {
            oldComValue = comValue;
            newComValue = COM;
            comValue = newComValue;
        }
    
        public String getComPort()
        {
            return comValue;
        }
        
       
    }
    Java Code:
    <*MAIN*>
    
    private void jcom4MenuActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        rT.setComPort("COM4");
        System.out.println("COM4");
    }
    
    private void jcom3MenuActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        rT.setComPort("COM3");
        System.out.println("COM3");
    }
    
    private void jcom1MenuActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        rT.setComPort("COM1");
        System.out.println("COM1");
    }

  2. #2
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    this problem isn't about NetBeans IDE.. so i suggest you to post in "Advanced java" or "AWT/Swing" section..

    however IMHO you can resolve many situations with ActionPerformed.. because it usually includes a listener for mouseClicked evt.. i don't know well your situation so you should specify better where's your problem and where the ActionPerformed event doesn't fire up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •