mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Добавлены примеры для forms
This commit is contained in:
parent
0cd9446b14
commit
cb5cae184d
33
examples/forms/look_and_feel.own
Normal file
33
examples/forms/look_and_feel.own
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use ["java", "forms"]
|
||||||
|
|
||||||
|
UIManager = newClass("javax.swing.UIManager")
|
||||||
|
// UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel")
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
|
||||||
|
|
||||||
|
label = newLabel("Current value: 50")
|
||||||
|
progressBar = newProgressBar()
|
||||||
|
progressBar.setValue(50)
|
||||||
|
progressBar.onChange(def() {
|
||||||
|
label.setText("Current value: " + progressBar.getValue())
|
||||||
|
})
|
||||||
|
minusBtn = newButton("-1")
|
||||||
|
minusBtn.onClick(def() = changeProgress(-1))
|
||||||
|
plusBtn = newButton("+1")
|
||||||
|
plusBtn.onClick(def() = changeProgress(1))
|
||||||
|
|
||||||
|
def changeProgress(delta) {
|
||||||
|
value = progressBar.getValue() + delta
|
||||||
|
if (value > 100) value = 100
|
||||||
|
else if (value < 0) value = 0
|
||||||
|
progressBar.setValue(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
window = newWindow("ProgressBar example")
|
||||||
|
window.add(minusBtn, BorderLayout.WEST)
|
||||||
|
window.add(progressBar, BorderLayout.CENTER)
|
||||||
|
window.add(plusBtn, BorderLayout.EAST)
|
||||||
|
window.add(label, BorderLayout.SOUTH)
|
||||||
|
window.pack()
|
||||||
|
window.setLocationByPlatform()
|
||||||
|
window.setResizable(false)
|
||||||
|
window.setVisible()
|
24
examples/forms/windowlistener.own
Normal file
24
examples/forms/windowlistener.own
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use "forms"
|
||||||
|
|
||||||
|
textArea = newTextArea("Window logs:")
|
||||||
|
|
||||||
|
window = newWindow("Window listener example")
|
||||||
|
window.addWindowListener(def(type, event) {
|
||||||
|
textArea.append("\n" + type + ", id: " + match event.id {
|
||||||
|
case WINDOW_OPENED: "WINDOW_OPENED"
|
||||||
|
case WINDOW_CLOSING: "WINDOW_CLOSING"
|
||||||
|
case WINDOW_CLOSED: "WINDOW_CLOSED"
|
||||||
|
case WINDOW_ICONIFIED: "WINDOW_ICONIFIED"
|
||||||
|
case WINDOW_DEICONIFIED: "WINDOW_DEICONIFIED"
|
||||||
|
case WINDOW_ACTIVATED: "WINDOW_ACTIVATED"
|
||||||
|
case WINDOW_DEACTIVATED: "WINDOW_DEACTIVATED"
|
||||||
|
case WINDOW_GAINED_FOCUS: "WINDOW_GAINED_FOCUS"
|
||||||
|
case WINDOW_LOST_FOCUS: "WINDOW_LOST_FOCUS"
|
||||||
|
case WINDOW_STATE_CHANGED: "WINDOW_STATE_CHANGED"
|
||||||
|
case _: "unknown type"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
window.add(newScrollPane(textArea))
|
||||||
|
window.setSize(300, 200)
|
||||||
|
window.setLocationByPlatform()
|
||||||
|
window.setVisible()
|
Loading…
Reference in New Issue
Block a user