GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, December 19, 2010

Java Event

This code will show on how to make Java Event:

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Main{

    public static void main(String[] args){

         new Main();
    }

    public Main(){

        frame = new JFrame("Event Application");
        bDialog = new JButton("Show Dialog");

        bDialog.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
                JOptionPane.showMessageDialog( frame,
                                         "Holla World");
            }
        });

        frame.add(bDialog);
        frame.setLayout(new FlowLayout(FlowLayout.CENTER));
        frame.setSize(400, 300);    
        frame.setLocation(200, 100); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    private JFrame frame;
    private JButton bDialog;
}
Share/Bookmark

No comments:

Post a Comment