B4J Question [SOLVED] Call mysub inside b4j with inlinejava

XorAndOr

Active Member
Licensed User
Hello everyone, I am using the library PI4J with B4j and the interface with buttons for inline java, now I would like when press button for inline java called my sub inside b4j.
From b4j everything works ok.
thank you

B4X:
'Non-UI application (console application)
#Region  Project Attributes
   #CommandLineArgs:
   #MergeLibraries: True
#End Region

Sub Process_Globals
    Private joInlineJava As JavaObject = Me
    Private controller As GpioController 
'   Private Pin29 As GpioPinDigitalInput   
    Private Pin29 As GpioPinDigitalOutput   
  
End Sub

Sub AppStart (Args() As String)
   
    Log("App Startet " & DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now))
   
    controller.Initialize
   
    Pin29.Initialize(29, True) 'GpioPinDigitalOutput   (True=Output)  (False=Input)

   
    Log("Monitoring Pin29 state")    
   
   
'    Pin29.State = True '  <--------------------  WITH B4J work ok
   
   
    joInlineJava.RunMethod("MyFrame", Null)

    StartMessageLoop
   
End Sub




Sub MySub()    ' <------------------------ how I call MySub with Inlinejava ?
   
    Pin29.State = True    
   
End Sub





'*****************************************************

#If JAVA
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//****************************************************
  

public static void MyFrame() {       
       
        final JPanel panel = new JPanel();   
        final JLabel label = new JLabel("");
        panel.add(label);   
       
        final JFrame frame = new JFrame("Pannello Finestra");   
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.add(panel);
        frame.setSize(600, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setResizable(false);
    
        final JButton okButton = new JButton("OK");
        panel.add(okButton);       
       
        //...............................................................       
       
        okButton.addActionListener(new ActionListener() {
       
        public void actionPerformed(ActionEvent evento1) {       
       
        // ... Event when pin change to high
                   
               
               
               
                // HERE CODE CALL MYSUB INTO B4J ?????
               
               
               
               
                JOptionPane.showMessageDialog(null, "Pin 29 high");               
                           
        }   
    });
       
         
}       
       

//****************************************************


#End If
 

XorAndOr

Active Member
Licensed User
Upvote 0
Top