howto make a button do an action on kotlin swing code example
Example: howto make a button do an action on kotlin swing
import java.awt.Image;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class JButtonIcon {
JButtonIcon(){
/* JFrame is a top level container (window)
* where we would be adding our button
*/
JFrame frame=new JFrame();
// Creating Button
JButton b = new JButton();
try {
Image img = ImageIO.read(getClass().getResource("play.gif"));
b.setIcon(new ImageIcon(img));
} catch (IOException ex) {
}
b.setBounds(50,50,90, 50);
//Adding button onto the frame
frame.add(b);
// Setting Frame size. This is the window size
frame.setSize(300,200);
frame.setLayout(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JButtonIcon();
}
}