public
Created

Java GUI with JRuby

  • Download Gist
app.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require 'java'
require 'forms-1.3.0.jar'
require 'miglayout15-swing.jar'
include_class "net.miginfocom.swing.MigLayout"
include_class 'javax.swing.AbstractAction'
include_class 'javax.swing.Action'
require 'gui.jar'
class Gui < Java::Gui
def jRubyAcion
puts "it works"
end
end
 
Gui.main([])
 
class SaveProject
def self.perform
end
def initialize(inputs)
@inputs = inputs
end
 
end
 
class OpenProject
end
gui.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
import java.awt.EventQueue;
 
 
public class Gui {
 
private JFrame frmWebappswordSdk;
private JTextField nameField;
private JPanel submodulesPanel;
private JComboBox langBox;
private ArrayList<JCheckBox> methods = new ArrayList<JCheckBox>();
private ArrayList<JComboBox> submodules = new ArrayList<JComboBox>();
private final Action action = new SwingAction();
 
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Gui window = new Gui();
window.frmWebappswordSdk.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
 
/**
* Create the application.
*/
public Gui() {
initialize();
}
 
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmWebappswordSdk = new JFrame();
frmWebappswordSdk.setTitle("App");
frmWebappswordSdk.setBounds(100, 100, 478, 348);
frmWebappswordSdk.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmWebappswordSdk.getContentPane().setLayout(new BorderLayout(0, 0));
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
frmWebappswordSdk.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JPanel info = new JPanel();
tabbedPane.addTab("Info", null, info, null);
info.setLayout(new MigLayout("", "[311px][grow]", "[16px][16px][][][grow]"));
JLabel nameLabel = new JLabel("Name");
info.add(nameLabel, "flowx,cell 0 0,alignx left");
nameField = new JTextField();
info.add(nameField, "cell 1 0,alignx left");
nameField.setColumns(20);
JLabel langLabel = new JLabel("Lang");
info.add(langLabel, "cell 0 1,alignx left");
langBox = new JComboBox();
langBox.setModel(new DefaultComboBoxModel(new String[] {"PHP"}));
info.add(langBox, "cell 1 1,growx");
JLabel methodsLabel = new JLabel("Methods");
info.add(methodsLabel, "cell 0 2,alignx left");
JCheckBox methodCheckBox = new JCheckBox("New check box");
info.add(methodCheckBox, "flowy,cell 1 2");
methods.add(methodCheckBox);
 
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("New check box");
info.add(chckbxNewCheckBox_1, "cell 1 2");
methods.add(chckbxNewCheckBox_1);
 
JLabel submodulesLabel = new JLabel("Submodules");
info.add(submodulesLabel, "cell 0 3,alignx left");
JButton addSubmoduleButton = new JButton("+");
addSubmoduleButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JComboBox submoduleBox = new JComboBox();
submoduleBox.setModel(new DefaultComboBoxModel(new String[] {"PHP"}));
submodulesPanel.add(submoduleBox);
submodules.add(submoduleBox);
}
});
info.add(addSubmoduleButton, "flowx,cell 1 3,aligny baseline");
submodulesPanel = new JPanel();
info.add(submodulesPanel, "cell 1 4,grow");
submodulesPanel.setLayout(new GridLayout(0, 1, 0, 0));
JComboBox submoduleBox = new JComboBox();
submodulesPanel.add(submoduleBox);
JPanel installers = new JPanel();
tabbedPane.addTab("Installers", null, installers, null);
installers.setLayout(new GridLayout(0, 1, 0, 0));
JTabbedPane installersTabs = new JTabbedPane(JTabbedPane.TOP);
installers.add(installersTabs);
JEditorPane installersEditor = new JEditorPane();
installersTabs.addTab("New tab", null, installersEditor, null);
JPanel validators = new JPanel();
tabbedPane.addTab("Validators", null, validators, null);
validators.setLayout(new GridLayout(1, 0, 0, 0));
JEditorPane editorPane_1 = new JEditorPane();
validators.add(editorPane_1);
JMenuBar menuBar = new JMenuBar();
frmWebappswordSdk.getContentPane().add(menuBar, BorderLayout.NORTH);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
JMenuItem mntmNew = new JMenuItem("New");
mnFile.add(mntmNew);
JMenuItem mntmSave = new JMenuItem("Save");
mntmSave.setAction(action);
mnFile.add(mntmSave);
JMenuItem mntmOpen = new JMenuItem("Open");
mnFile.add(mntmOpen);
}
public void jRubyAcion(){
System.out.print("test");
}
private class SwingAction extends AbstractAction {
public SwingAction() {
putValue(NAME, "Save");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
jRubyAcion();
Hashtable result = new Hashtable();
result.put("name", nameField.getText());
result.put("lang", langBox.getSelectedItem());
ArrayList<String> submodulesArray = new ArrayList<String>();
for(JComboBox submodule : submodules)
submodulesArray.add((String)submodule.getSelectedItem());
ArrayList<String> methodsArray = new ArrayList<String>();
for(JCheckBox method : methods){
if(method.isSelected())
methodsArray.add(method.getText());
}
result.put("submodules", submodulesArray);
result.put("methods", methodsArray);
System.out.print("perform");
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.