Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Hello world class
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import javax.swing.event.*;
- public class HelloWorld extends JFrame{
- private JButton button;
- public HelloWorld(){
- super("Hello World");
- button = new JButton("Click here");
- add(button);
- HandlerClass handler = new HandlerClass();
- button.addActionListener(handler);
- }
- private class HandlerClass implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent event){
- JOptionPane.showMessageDialog(null, String.format("Hello world", event.getActionCommand()));
- }
- }
- }
- //main class
- import javax.swing.*;
- import java.awt.*;
- class MyFirst extends JFrame {
- public static void main(String[] args) {
- Gui hello = new Gui();
- hello.setSize(100, 100);
- hello.setDefaultCloseOperation(hello.EXIT_ON_CLOSE);
- hello.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment