Anonymous user
Simple windowed application: Difference between revisions
→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(Added Kotlin) |
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
||
Line 1,196:
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.
class Clicks : JFrame(), ActionListener {
Line 1,210 ⟶ 1,208:
label = JLabel(text)
clicker = JButton("click me")
layout = BorderLayout() // handles placement of components
add(label, BorderLayout.CENTER) // add the label to the biggest section
add(clicker, BorderLayout.SOUTH) // put the button underneath it
defaultCloseOperation = EXIT_ON_CLOSE // stop the program on "X"
}
override fun actionPerformed(arg0: ActionEvent) {
if (arg0.source == clicker) { // if they clicked the button
if (clicks == 0) text = "There has been " + (++clicks) + " click"
else
label.text = text // change the text
}
}
}
fun main(args: Array<String>) {
|