Link JButtons to DigitalO (Swing)

Hello Everyone,

I am a beginner with the URCap Swing Programming and require a help with this. I have to create Jbuttons and Radio Buttons on the Program node display and integrate it to Tool digital IO’s using swing programming method.

I have created the JButtons and Radio buttons included the actionListeners too. Now i am unable to link the DigitalIO using actionListener. I am not able to get the right way to declare the digitalIO or use it inside the ActionListener just to turn ON or OFF. I did refer to [com.ur.urcap.sample.manipulateIO.tar.gz] and used similar comand lines still not able to get it right. Can anybody help me with it or Refer me to a sample program which would help me?

Thanks for the time

program node view:
button.addActionListener(new ActionListener(){
@Ovveride
public void actionPerformed(ActionEvent e){
provider.get().yourMethod();}});

Program Node Contrribution:
public void yourMethod(){
DigitalIO output=getDigitalIO(tool_out[0]):
if(output.getValue()==false){
output.setValue(true);
}else{
output.setValue(false);
}

this is a little example of how it works generally

}

Firstly thanks a lot for the quick reply. I tried your solution and got these errors
tool_out[0] - cannot be resolved to a variable, so i changed to the way i declared the DigitalIO
private DigitalIO tool_in1;
then there is error with getDigitalIO - “The method getDigitalIO(DigitalIO) is undefined for the type JButtonProgramNodeContribution”. So should i create a method DigitalIO? Very sorry if it was a basic question.

Thank you

To get your IO in your contribution:

    private final String TOOL_IO_KEY = "tool_in[0]";
    DigitalIO toolIO0;
    Collection<IO> ios = apiProvider.getProgramAPI().getIOModel().getIOs(IOFilterFactory.toolFilter());
    Iterator<IO> it = ios.iterator();
    while (it.hasNext()) {
        IO nextIO = it.next();
        if (nextIO.getName().contains(TOOL_IO_KEY)) {
            toolIO0 = nextIO;
            break;
        }
    }

having toolIO0 you can fire a setter and getter to actually fire the IO with your button e.g.

public void setToolIO(boolean signal){
    toolIO0.setValue(signal);
}

In your view:

    ioBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            provider.get().setToolIO(true);
        }
    });
DigitalIO getDigitalIO(String defaultName){
	Collection<DigitalIO> IOcollection = apiProvider.getInstallationAPI().getIOModel().getIOs(DigitalIO.class);
	int IO_count = IOcollection.size();
	if(IO_count > 0){
		Iterator<DigitalIO> IO_itr = IOcollection.iterator();
		while(IO_itr.hasNext()){
			DigitalIO thisIO = IO_itr.next();
			String thisDefaultName = thisIO.getDefaultName();

			if(thisDefaultName.equals(defaultName)){
				return thisIO;
			}
		}
	}
	return null;
}

You can use this one

Thanks a lot for taking the time to help me :slight_smile:

Thanks a lot, the code worked. Had a little things to change. Thanks again for the effort :slight_smile: :slight_smile: