mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Добавлены примеры
This commit is contained in:
parent
134e0fe4ca
commit
adce68e598
6
examples/forms/basic.own
Normal file
6
examples/forms/basic.own
Normal 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
11
examples/forms/button.own
Normal 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()
|
38
examples/forms/complicatedForm.own
Normal file
38
examples/forms/complicatedForm.own
Normal 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
37
examples/forms/panel.own
Normal 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()
|
23
examples/forms/textfield.own
Normal file
23
examples/forms/textfield.own
Normal 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))
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user