howto make a button do an action on kotlin swing

Solutions on MaxInterview for howto make a button do an action on kotlin swing by the best coders in the world

showing results for - "howto make a button do an action on kotlin swing"
Luigi
20 Jul 2016
1import java.awt.Image;
2import java.io.IOException;
3
4import javax.imageio.ImageIO;
5import javax.swing.*;
6
7public class JButtonIcon {
8    JButtonIcon(){  
9        /* JFrame is a top level container (window)
10         * where we would be adding our button
11         */
12        JFrame frame=new JFrame();  
13                          
14        // Creating Button          
15        JButton b = new JButton();
16        try {
17            Image img = ImageIO.read(getClass().getResource("play.gif"));
18            b.setIcon(new ImageIcon(img));
19          } catch (IOException ex) {
20          }
21        
22        b.setBounds(50,50,90, 50);  
23             
24        //Adding button onto the frame
25        frame.add(b);  
26                  
27        // Setting Frame size. This is the window size
28        frame.setSize(300,200);  
29        
30        frame.setLayout(null);  
31        frame.setVisible(true);  
32                  
33        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
34                  
35    }  
36              
37    public static void main(String[] args) {  
38            new JButtonIcon();  
39    }  
40}