-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.kt
55 lines (49 loc) · 1.42 KB
/
App.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
55
package example
import java.awt.*
import java.net.URI
import javax.swing.*
import javax.swing.event.HyperlinkEvent
private const val SITE = "https://ateraimemo.com/"
fun makeUI(): Component {
val textArea = JTextArea()
val editor = JEditorPane("text/html", "<html><a href='$SITE'>$SITE</a>")
editor.isOpaque = false
editor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true)
editor.isEditable = false
editor.addHyperlinkListener { e ->
if (Desktop.isDesktopSupported() && e.eventType == HyperlinkEvent.EventType.ACTIVATED) {
runCatching {
Desktop.getDesktop().browse(URI(SITE))
}.onFailure {
it.printStackTrace()
textArea.text = it.message
}
textArea.text = e.toString()
}
}
val p = JPanel()
p.add(editor)
p.border = BorderFactory.createTitledBorder("Desktop.getDesktop().browse(URI)")
return JPanel(BorderLayout()).also {
it.add(p, BorderLayout.NORTH)
it.add(JScrollPane(textArea))
it.preferredSize = Dimension(320, 240)
}
}
fun main() {
EventQueue.invokeLater {
runCatching {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
}.onFailure {
it.printStackTrace()
Toolkit.getDefaultToolkit().beep()
}
JFrame().apply {
defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
contentPane.add(makeUI())
pack()
setLocationRelativeTo(null)
isVisible = true
}
}
}