Добавлены примеры

This commit is contained in:
Victor 2016-07-29 19:29:01 +03:00
parent 134e0fe4ca
commit adce68e598
5 changed files with 115 additions and 0 deletions

6
examples/forms/basic.own Normal file
View File

@ -0,0 +1,6 @@
use "forms"
window = newWindow("Basic form example")
window.add("Hello, world")
window.pack()
window.setVisible()

11
examples/forms/button.own Normal file
View File

@ -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()

View File

@ -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()

37
examples/forms/panel.own Normal file
View File

@ -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()

View File

@ -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))
})