diff --git a/examples/forms/basic.own b/examples/forms/basic.own new file mode 100644 index 0000000..59eb3ee --- /dev/null +++ b/examples/forms/basic.own @@ -0,0 +1,6 @@ +use "forms" + +window = newWindow("Basic form example") +window.add("Hello, world") +window.pack() +window.setVisible() \ No newline at end of file diff --git a/examples/forms/button.own b/examples/forms/button.own new file mode 100644 index 0000000..d30f4f9 --- /dev/null +++ b/examples/forms/button.own @@ -0,0 +1,11 @@ +use "forms" + +button = newButton("Click me") +button.onClick(def() { + println "Oh, you clicked me." +}) + +window = newWindow("Button example") +window.add(button) +window.pack() +window.setVisible() \ No newline at end of file diff --git a/examples/forms/complicatedForm.own b/examples/forms/complicatedForm.own new file mode 100644 index 0000000..7796b58 --- /dev/null +++ b/examples/forms/complicatedForm.own @@ -0,0 +1,38 @@ +use "std" +use "forms" + +actionsPanel = newPanel() +actionsPanel.setLayout(boxLayout(actionsPanel, BoxLayout.PAGE_AXIS)) +actionsPanel.add("Actions:") +actionsPanel.add(newButton("Action 1")) +actionsPanel.add(newButton("Action 2")) +actionsPanel.add(newButton("Action 3")) +actionsPanel.add(newButton("Action 4")) + +enterTextLabel = newLabel("Enter a text", SwingConstants.CENTER) + +textField = newTextField() +textField.addKeyListener(def(type, event) { + lengthLabel.setText(length(textField.getText())) +}) + +statusPanel = newPanel() +statusPanel.setLayout(boxLayout(statusPanel, BoxLayout.LINE_AXIS)) +statusPanel.add("Length: ") +lengthLabel = newLabel() +statusPanel.add(lengthLabel) + +mainPanel = newPanel(borderLayout(10, 10)) +mainPanel.setPreferredSize(400, 250) +mainPanel.add(actionsPanel, BorderLayout.WEST) +mainPanel.add(enterTextLabel, BorderLayout.NORTH) +mainPanel.add(textField, BorderLayout.CENTER) +mainPanel.add(statusPanel, BorderLayout.SOUTH) + + +window = newWindow("Complicated Form Example") +window.setMinimumSize(200, 220) +window.setLocationByPlatform() +window.add(mainPanel) +window.pack() +window.setVisible() diff --git a/examples/forms/panel.own b/examples/forms/panel.own new file mode 100644 index 0000000..3f7de8d --- /dev/null +++ b/examples/forms/panel.own @@ -0,0 +1,37 @@ +use "forms" + +// Create Panel with BoxLayout +panel = newPanel() +panel.setLayout(boxLayout(panel, BoxLayout.PAGE_AXIS)) +// String label (alias to JLabel) +panel.add("String label") + +// Add label +label = newLabel("Label") +label.setHorizontalAlignment(SwingConstants.CENTER) +panel.add(label) + +// Add text field +textField = newTextField("Some text") +textField.setColumns(20) +panel.add(textField) + +// Add button +button = newButton("Button") +panel.add(button) + +// Add another button +clearBtn = newButton("Clear panel") +clearBtn.onClick(def() { + panel.removeAll() + panel.revalidate() + panel.repaint() +}) +panel.add(clearBtn) + +window = newWindow("Panel Example") +window.setLocation(400, 200) +window.add(panel) +window.pack() +window.setAlwaysOnTop() +window.setVisible() \ No newline at end of file diff --git a/examples/forms/textfield.own b/examples/forms/textfield.own new file mode 100644 index 0000000..33fd1c6 --- /dev/null +++ b/examples/forms/textfield.own @@ -0,0 +1,23 @@ +use "std" +use "forms" + +textField = newTextField("Some text") + +button = newButton("Click me") +button.onClick(def() { + println "TextField text: " + textField.getText() + textField.setText(textField.getText() + " Let's add new line") +}) + +window = newWindow("Text field example") +window.add(textField) +window.add(button, BorderLayout.SOUTH) +window.pack() +window.setLocationByPlatform() +window.setVisible() + +textField.onAction(def() = echo("I am a TextField")) +textField.addKeyListener(def(type, event) { + println sprintf("%s %d %s", + type, event.keyCode, toChar(event.keyChar)) +}) \ No newline at end of file