Jump to content

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.JButton*
import javax.swing.JFrame
import javax.swing.JLabel
 
class Clicks : JFrame(), ActionListener {
Line 1,210 ⟶ 1,208:
label = JLabel(text)
clicker = JButton("click me")
clicker.addActionListener(this) // listen to the button
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
setSize(300, 200) // stretch out the window
defaultCloseOperation = EXIT_ON_CLOSE // stop the program on "X"
setVisible( isVisible = true) // show it
}
 
override fun actionPerformed(arg0: ActionEvent) {
if (arg0.source == clicker) { // if they clicked the button
if (clicks == 0) text = "There has been " + (++clicks) + " click"
else text = "There have been " + (++clicks) + " clicks"
label.text = text // change the text
}
}
}
 
fun main(args: Array<String>) {
Cookies help us deliver our services. By using our services, you agree to our use of cookies.