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

This commit is contained in:
Victor 2019-10-13 00:36:56 +03:00
parent 0cd9446b14
commit cb5cae184d
2 changed files with 57 additions and 0 deletions

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

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