Skip to content

Commit cb5cae1

Browse files
committed
Добавлены примеры для forms
1 parent 0cd9446 commit cb5cae1

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

examples/forms/look_and_feel.own

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use ["java", "forms"]
2+
3+
UIManager = newClass("javax.swing.UIManager")
4+
// UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel")
5+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
6+
7+
label = newLabel("Current value: 50")
8+
progressBar = newProgressBar()
9+
progressBar.setValue(50)
10+
progressBar.onChange(def() {
11+
label.setText("Current value: " + progressBar.getValue())
12+
})
13+
minusBtn = newButton("-1")
14+
minusBtn.onClick(def() = changeProgress(-1))
15+
plusBtn = newButton("+1")
16+
plusBtn.onClick(def() = changeProgress(1))
17+
18+
def changeProgress(delta) {
19+
value = progressBar.getValue() + delta
20+
if (value > 100) value = 100
21+
else if (value < 0) value = 0
22+
progressBar.setValue(value)
23+
}
24+
25+
window = newWindow("ProgressBar example")
26+
window.add(minusBtn, BorderLayout.WEST)
27+
window.add(progressBar, BorderLayout.CENTER)
28+
window.add(plusBtn, BorderLayout.EAST)
29+
window.add(label, BorderLayout.SOUTH)
30+
window.pack()
31+
window.setLocationByPlatform()
32+
window.setResizable(false)
33+
window.setVisible()

examples/forms/windowlistener.own

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use "forms"
2+
3+
textArea = newTextArea("Window logs:")
4+
5+
window = newWindow("Window listener example")
6+
window.addWindowListener(def(type, event) {
7+
textArea.append("\n" + type + ", id: " + match event.id {
8+
case WINDOW_OPENED: "WINDOW_OPENED"
9+
case WINDOW_CLOSING: "WINDOW_CLOSING"
10+
case WINDOW_CLOSED: "WINDOW_CLOSED"
11+
case WINDOW_ICONIFIED: "WINDOW_ICONIFIED"
12+
case WINDOW_DEICONIFIED: "WINDOW_DEICONIFIED"
13+
case WINDOW_ACTIVATED: "WINDOW_ACTIVATED"
14+
case WINDOW_DEACTIVATED: "WINDOW_DEACTIVATED"
15+
case WINDOW_GAINED_FOCUS: "WINDOW_GAINED_FOCUS"
16+
case WINDOW_LOST_FOCUS: "WINDOW_LOST_FOCUS"
17+
case WINDOW_STATE_CHANGED: "WINDOW_STATE_CHANGED"
18+
case _: "unknown type"
19+
})
20+
})
21+
window.add(newScrollPane(textArea))
22+
window.setSize(300, 200)
23+
window.setLocationByPlatform()
24+
window.setVisible()

0 commit comments

Comments
 (0)