-
Notifications
You must be signed in to change notification settings - Fork 2
/
gui.kt
54 lines (45 loc) · 1.38 KB
/
gui.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import javax.swing.*
import javax.swing.text.*
import java.awt.event.*
class Gui : JFrame() {
private var usernameField: JTextField
private var passwordField: JPasswordField
private var loginButton: JButton
fun open(name: String, login: (String, String) -> Unit) {
loginButton.addActionListener {
login(usernameField.text, String(passwordField.password))
}
setSize(295, 240)
title = name
isResizable = false
isVisible = true
}
init {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
JFrame.setDefaultLookAndFeelDecorated(true)
contentPane.layout = null
JLabel("username").apply {
setBounds(20, 20, 100, 20)
contentPane.add(this)
}
usernameField = JTextField().apply {
setBounds(20, 40, 240, 20)
contentPane.add(this)
}
JLabel("password").apply {
setBounds(20, 70, 100, 20)
contentPane.add(this)
}
passwordField = JPasswordField().apply {
setBounds(20, 90, 240, 20)
contentPane.add(this)
}
loginButton = JButton("login").apply {
setBounds(20, 130, 240, 20)
contentPane.add(this)
}
}
fun close() {
dispatchEvent(WindowEvent(this, WindowEvent.WINDOW_CLOSING))
}
}