Guest User

Hello world

a guest
Jul 29th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. //Hello world class
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. import javax.swing.event.*;
  6.        
  7. public class HelloWorld extends JFrame{
  8.     private JButton button;
  9.    
  10.     public HelloWorld(){
  11.     super("Hello World");
  12.    
  13.     button = new JButton("Click here");
  14.     add(button);
  15.    
  16.     HandlerClass handler = new HandlerClass();
  17.     button.addActionListener(handler);
  18.    
  19.     }
  20.    private class HandlerClass implements ActionListener{
  21.        @Override
  22.     public void actionPerformed(ActionEvent event){
  23.         JOptionPane.showMessageDialog(null, String.format("Hello world", event.getActionCommand()));
  24.        
  25.     }
  26.     }
  27. }
  28.  
  29. //main class
  30. import javax.swing.*;  
  31. import java.awt.*;
  32.  
  33.  
  34. class MyFirst extends JFrame {
  35. public static void main(String[] args) {
  36.     Gui hello = new Gui();
  37.    
  38.     hello.setSize(100, 100);
  39.     hello.setDefaultCloseOperation(hello.EXIT_ON_CLOSE);
  40.     hello.setVisible(true);
  41.    
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment