Saturday, May 19, 2012

Creating Frame using SWING( JAVA)


/* EXTENDING THE FRAME CLASS */

import javax.swing.*;
import java.awt.event.*;

class MyFrame extends JFrame implements ActionListener
{
JButton btnExit;

public MyFrame()
{
super("My Third Window...");

btnExit = new JButton("Exit");
add(btnExit);
btnExit.addActionListener(this);

setSize(400, 400);
setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}

public class SwingFrame
{
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}

No comments:

Post a Comment