I have the horrible thought that this might not make it through the list software intact, so I have BCC’ed René and KP… A Simplistic Example of NetRexx/Eclipse/Swing/WindowBuilder Prerequisites:- WindowBuilder and NetRexx plugin installed in Eclipse. Some experience of mixing Java and NetRexx within Eclipse. Create the Project:- Open a new Java project (File->New->Java Project) Within the project create a new package (WindowBuilder prefers it that way) Create GUI:- New->Other Fill out the Wizard… And click Finish… Click “Design” From the Palette select and drop the following onto the canvas:- · GridBagLayout · JLabel · JTextField · JButton · JTextArea Right-click on the button, Add Event Handler->Action->actionPerformed These components can be customised to suit in the properties pane(s), but, for now we will leave them as they are. If you were not taken to the source view then click on the “Source” button next to “Design.” You are now presented with the source to create your basic GUI. Add a NetRexx source file – for the sake of the example call it “bridge.nrx” /* A "bridge" for the WindowBuilder example */ options replace package org.netrexx import javax.swing import java.awt class bridge properties private textBox = JTextField outBox = JTextArea method bridge(args = String[]) nop /* Do all of your NetRexx initialisation here... */ method addSrc(in = JTextField) -- Could use the indirect property support for these... textBox = in textBox.setText("Initialised") method addDest(out = JTextArea) outBox = out outBox.setText("Ready\n") method doIt str = textBox.getText() outBox.append(str||"\n") textBox.setText("") We will connect this to the Swing GUI, and when the button is pressed text will be taken from the text field and added to the text area. To connect, modify the swing generated code as such package org.netrexx; import java.awt.EventQueue; public class Demo { private JFrame frame; private JTextField textField; private static bridge nrBit; /* nrBit - the NetRexx bit */ /** * Launch the application. */ public static void main(String[] args) { nrBit = new bridge(args); /* Setup the NetRexx side of things - note that the GUI is NOT READY!!! */ EventQueue.invokeLater(new Runnable() { public void run() { try { Demo window = new Demo(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Demo() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; frame.getContentPane().setLayout(gridBagLayout); JLabel lblNewLabel = new JLabel("New label"); GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0); gbc_lblNewLabel.gridx = 3; gbc_lblNewLabel.gridy = 0; frame.getContentPane().add(lblNewLabel, gbc_lblNewLabel); textField = new JTextField(); GridBagConstraints gbc_textField = new GridBagConstraints(); gbc_textField.insets = new Insets(0, 0, 5, 0); gbc_textField.fill = GridBagConstraints.HORIZONTAL; gbc_textField.gridx = 3; gbc_textField.gridy = 2; frame.getContentPane().add(textField, gbc_textField); textField.setColumns(10); nrBit.addSrc(textField); /* Add the souce field to the bridge */ JButton btnNewButton = new JButton("New button"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { nrBit.doIt(); /*Add the action call */ } }); GridBagConstraints gbc_btnNewButton = new GridBagConstraints(); gbc_btnNewButton.insets = new Insets(0, 0, 5, 0); gbc_btnNewButton.gridx = 3; gbc_btnNewButton.gridy = 4; frame.getContentPane().add(btnNewButton, gbc_btnNewButton); JTextArea textArea = new JTextArea(); GridBagConstraints gbc_textArea = new GridBagConstraints(); gbc_textArea.fill = GridBagConstraints.BOTH; gbc_textArea.gridx = 3; gbc_textArea.gridy = 6; frame.getContentPane().add(textArea, gbc_textArea); nrBit.addDest(textArea); /* Add the output pane... */ } } This can be invoked via “Run As->Java Application” _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Could we have a Wiki page or something else where these things could be posted, probably as a subpage of the original Netrexx Homepage?
Exactly that is that kind of information I am looking for. |
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
bridge cannot be resolved to a type bridge cannot be resolved to a type JFrame cannot be resolved to a type at org.netrexx.Demo.main(Demo.java:16) When I cut and paste the nrx and java code listed above into eclipse, I get the above error messages. |
Free forum by Nabble | Edit this page |