SWING - Radio Buttons

java.lang.Object
extended byjava.awt.Component
extended byjava.awt.Container
extended byjavax.swing.JComponent
extended byjavax.swing.AbstractButton
extended byjavax.swing.JToggleButton
extended byjavax.swing.JRadioButton

Constructor Summary
JRadioButton()
Creates an initially unselected radio button with no set text.
JRadioButton(Action a)
Creates a radiobutton where properties are taken from the Action supplied.
JRadioButton(Icon icon)
Creates an initially unselected radio button with the specified image but no text.
JRadioButton(Icon icon, boolean selected)
Creates a radio button with the specified image and selection state, but no text.
JRadioButton(String text)
Creates an unselected radio button with the specified text.
JRadioButton(String text, boolean selected)
Creates a radio button with the specified text and selection state.
JRadioButton(String text, Icon icon)
Creates a radio button that has the specified text and image, and that is initially unselected.
JRadioButton(String text, Icon icon, boolean selected)
Creates a radio button that has the specified text, image, and selection state.

Method Summary
protected void configurePropertiesFromAction(Action a)
Factory method which sets the ActionEvent source's properties according to values from the Action instance.
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
Factory method which creates the PropertyChangeListener used to update the ActionEvent source as properties change on its Action instance.
AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JRadioButton.
String getUIClassID()
Returns the name of the L&F class that renders this component.
protected String paramString()
Returns a string representation of this JRadioButton.
void updateUI()
Resets the UI property to a value from the current look and feel.

Example

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

public class Radiobutton extends JApplet implements ItemListener{
JTextField text;
JRadioButton radio1, radio2, radio3, radio4;
ButtonGroup group;

public void init() {

Container frame1=getContentPane();
frame1.setLayout(new FlowLayout());

group=new ButtonGroup();

radio1=new JRadioButton("Radio Button 1");
radio2=new JRadioButton("Radio Button 2");
radio3=new JRadioButton("Radio Button 3");
radio4=new JRadioButton("Radio Button 4");
text=new JTextField(20);

group.add(radio1);
group.add(radio2);
group.add(radio3);
group.add(radio4);

radio1.addItemListener(this);
radio2.addItemListener(this);
radio3.addItemListener(this);
radio4.addItemListener(this);

frame1.add(radio1);
frame1.add(radio2);
frame1.add(radio3);
frame1.add(radio4);

frame1.add(text);
}

public void itemStateChanged(ItemEvent e){
if(e.getItemSelectable()==radio1){
text.setText("You Select Radio Button 1");
}else if(e.getItemSelectable()==radio2){
text.setText("You Select Radio Button 2");
}else if(e.getItemSelectable()==radio3){
text.setText("You Select Radio Button 3");
}else if(e.getItemSelectable()==radio4){
text.setText("You Select Radio Button 4");
}


}
}

Output

SWING - Check Boxes

java.lang.Object
extended byjava.awt.Component
extended byjava.awt.Container
extended byjavax.swing.JComponent
extended byjavax.swing.AbstractButton
extended byjavax.swing.JToggleButton
extended byjavax.swing.JCheckBox

Constructor Summary
JCheckBox()
Creates an initially unselected check box button with no text, no icon.
JCheckBox(Action a)
Creates a check box where properties are taken from the Action supplied.
JCheckBox(Icon icon)
Creates an initially unselected check box with an icon.
JCheckBox(Icon icon, boolean selected)
Creates a check box with an icon and specifies whether or not it is initially selected.
JCheckBox(String text)
Creates an initially unselected check box with text.
JCheckBox(String text, boolean selected)
Creates a check box with text and specifies whether or not it is initially selected.
JCheckBox(String text, Icon icon)
Creates an initially unselected check box with the specified text and icon.
JCheckBox(String text, Icon icon, boolean selected)
Creates a check box with text and icon, and specifies whether or not it is initially selected.

Method Summary
protected void configurePropertiesFromAction(Action a)
Factory method which sets the ActionEvent source's properties according to values from the Action instance.
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
Factory method which creates the PropertyChangeListener used to update the ActionEvent source as properties change on its Action instance.
AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JCheckBox.
String getUIClassID()
Returns a string that specifies the name of the L&F class that renders this component.
boolean isBorderPaintedFlat()
Gets the value of the borderPaintedFlat property.
protected String paramString()
Returns a string representation of this JCheckBox.
void setBorderPaintedFlat(boolean b)
Sets the borderPaintedFlat property, which gives a hint to the look and feel as to the appearance of the check box border.
void updateUI()
Resets the UI property to a value from the current look and feel.

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

public class checkbox extends JApplet implements ItemListener{
JTextField text;
JCheckBox checkbox1, checkbox2, checkbox3, checkbox4;

public void init() {

Container frame1=getContentPane();
frame1.setLayout(new FlowLayout());


checkbox1=new JCheckBox("Check Box1");
checkbox2=new JCheckBox("Check Box2");
checkbox3=new JCheckBox("Check Boz3");
checkbox4=new JCheckBox("Check Box4");
text=new JTextField(20);

checkbox1.addItemListener(this);
checkbox2.addItemListener(this);
checkbox3.addItemListener(this);
checkbox4.addItemListener(this);

frame1.add(checkbox1);
frame1.add(checkbox2);
frame1.add(checkbox3);
frame1.add(checkbox4);

frame1.add(text);
}

public void itemStateChanged(ItemEvent e){
if(e.getItemSelectable()==checkbox1){
text.setText("Hello from Swing");
}else if(e.getItemSelectable()==checkbox2){
text.setText("Hello from Swing");
}else if(e.getItemSelectable()==checkbox3){
text.setText("Hello from Swing");
}else if(e.getItemSelectable()==checkbox4){
text.setText("Hello from Swing");
}


}
}

SWING - JButton

java.lang.Object
extended byjava.awt.Component
extended byjava.awt.Container
extended byjavax.swing.JComponent
extended byjavax.swing.AbstractButton
extended byjavax.swing.JButton

Swaing button let you do a lot more than AWT buttons. Some of the things you can do with the JButton class include using setToolTipText to add a tooltip to the button, using setMargin to set the inserts in the button itself, using doClick to click the button from code, adding images to the button, and adding mnemonics (Keyboard shortcuts) to the button. Of course, you can do standard AWT things with JButton too, such as using setEnabled to enable or disable the button, using addActionListener to register an action listener with the button and adding action commands to JButton objects with setActionCommand.

Constructor Summary
JButton()
Creates a b0utton with no set text or icon.
JButton(Action a)
Creates a button where properties are taken from the Action supplied.
JButton(Icon icon)
Creates a button with an icon.
JButton(String text)
Creates a button with text.
JButton(String text, Icon icon)
Creates a button with initial text and an icon.

Method Summary
protected void configurePropertiesFromAction(Action a)
Factory method which sets the AbstractButton's properties according to values from the Action instance.
AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JButton.
String getUIClassID()
Returns a string that specifies the name of the L&F class that renders this component.
boolean isDefaultButton()
Gets the value of the defaultButton property, which if true means that this button is the current default button for its JRootPane.
boolean isDefaultCapable()
Gets the value of the defaultCapable property.
protected String paramString()
Returns a string representation of this JButton.
void removeNotify()
Overrides JComponent.removeNotify to check if this button is currently set as the default button on the RootPane, and if so, sets the RootPane's default button to null to ensure the RootPane doesn't hold onto an invalid button reference.
void setDefaultCapable(boolean defaultCapable)
Sets the defaultCapable property, which determines whether this button can be made the default button for its root pane.
void updateUI()
Resets the UI property to a value from the current look and feel.

Example:

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

public class jbutton extends JApplet{
JTextField text=new JTextField(20);
JButton button=new JButton("Click Here");
public void init() {
Container frame1=getContentPane();
frame1.setLayout(new FlowLayout());
frame1.add(text);
frame1.add(button);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
text.setText("Hello from Swing");
}
});
}
}

Output:

Displaying Images in Button

It is easy to display images in buttons using the ImageIcon class, because several JButton constructors let you add icons to buttons. You can also set the alignment of the text and image using these AbstractButton methods.

setVerticalTextAlignment - Sets the vertical text alignment relative to the image.

setHorizontalAlignment - Sets the horizontal text alignment relative to the image.

setVerticalAlignment - Sets the vertical alignment of the button's contents.

setHorizontalAlignment - Sets the horizontal alignment of the button's contents.

Lets' look at an example in which i add an image from button.jpg to the button example from the previous,

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

public class jbutton extends JApplet{
JTextField text=new JTextField(20);
JButton button=new JButton("asass", new ImageIcon("button1.jpg"));
public void init() {
Container frame1=getContentPane();
frame1.setLayout(new FlowLayout());
frame1.add(text);
frame1.add(button);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
text.setText("Hello from Swing");
}
});
}

}

Default Buttons and Mnemonics

Besides making buttons into default buttons, you can also give each button a mnemonic, which is a keyboard shortcut, much like those you see in menus. You underline one (case-insensitive) letter in a button's caption, and when the button has the focus, typing that character activates the button.

Example:

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

public class jbutton extends JApplet{
JTextField text=new JTextField(20);
JButton button1=new JButton("Click Here");
JButton button2=new JButton("Click Here 1");
public void init() {
Container frame1=getContentPane();
frame1.setLayout(new FlowLayout());

button2.setMnemonic('l');
getRootPane().setDefaultButton(button2);


frame1.add(text);
frame1.add(button1);
frame1.add(button2);
getRootPane().requestFocus();

button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
text.setText("Hello from Swing");
}
});
}
}

Output:

SWING - JTextBox

java.lang.Object
extended byjava.awt.Component
extended byjava.awt.Container
extended byjavax.swing.JComponent
extended byjavax.swing.text.JTextComponent
extended byjavax.swing.JTextField
Constructor Summary
JTextField()
Constructs a new TextField.
JTextField(Document doc, String text, int columns)
Constructs a new JTextField that uses the given text storage model and the given number of columns.
JTextField(int columns)
Constructs a new empty TextField with the specified number of columns.
JTextField(String text)
Constructs a new TextField initialized with the specified text.
JTextField(String text, int columns)
Constructs a new TextField initialized with the specified text and columns.

Method Summary
void addActionListener(ActionListener l)
Adds the specified action listener to receive action events from this textfield.
protected void configurePropertiesFromAction(Action a)
Factory method which sets the ActionEvent source's properties according to values from the Action instance.
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
Factory method which creates the PropertyChangeListener used to update the ActionEvent source as properties change on its Action instance.
protected Document createDefaultModel()
Creates the default implementation of the model to be used at construction if one isn't explicitly given.
protected void fireActionPerformed()
Notifies all listeners that have registered interest for notification on this event type.
AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JTextField.
Action getAction()
Returns the currently set Action for this ActionEvent source, or null if no Action is set.
ActionListener[] getActionListeners()
Returns an array of all the ActionListeners added to this JTextField with addActionListener().
Action[] getActions()
Fetches the command list for the editor.
int getColumns()
Returns the number of columns in this TextField.
protected int getColumnWidth()
Returns the column width.
int getHorizontalAlignment()
Returns the horizontal alignment of the text.
BoundedRangeModel getHorizontalVisibility()
Gets the visibility of the text field.
Dimension getPreferredSize()
Returns the preferred size Dimensions needed for this TextField.
int getScrollOffset()
Gets the scroll offset, in pixels.
String getUIClassID()
Gets the class ID for a UI.
boolean isValidateRoot()
Calls to revalidate that come from within the textfield itself will be handled by validating the textfield, unless the textfield is contained within a JViewport, in which case this returns false.
protected String paramString()
Returns a string representation of this JTextField.
void postActionEvent()
Processes action events occurring on this textfield by dispatching them to any registered ActionListener objects.
void removeActionListener(ActionListener l)
Removes the specified action listener so that it no longer receives action events from this textfield.
void scrollRectToVisible(Rectangle r)
Scrolls the field left or right.
void setAction(Action a)
Sets the Action for the ActionEvent source.
void setActionCommand(String command)
Sets the command string used for action events.
void setColumns(int columns)
Sets the number of columns in this TextField, and then invalidate the layout.
void setDocument(Document doc)
Associates the editor with a text document.
void setFont(Font f)
Sets the current font.
void setHorizontalAlignment(int alignment)
Sets the horizontal alignment of the text.
void setScrollOffset(int scrollOffset)
Sets the scroll offset, in pixels.

Example:

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

public class jtextbox extends JApplet{
JTextField text= new JTextField(18);

public jtextbox() {
Container frame = getContentPane();
frame.setLayout(new FlowLayout());
frame.add(text);
text.setText("Hellow From Java");
}
}

SWING - Label

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
Constructor Summary
JLabel()
Creates a JLabel instance with no image and with an empty string for the title.
JLabel(Icon image)
Creates a JLabel instance with the specified image.
JLabel(Icon image, int horizontalAlignment)
Creates a JLabel instance with the specified image and horizontal alignment.
JLabel(String text)
Creates a JLabel instance with the specified text.
JLabel(String text, Icon icon, int horizontalAlignment)
Creates a JLabel instance with the specified text, image, and horizontal alignment.
JLabel(String text, int horizontalAlignment)
Creates a JLabel instance with the specified text and horizontal alignment.

Method Summary
protected int checkHorizontalKey(int key, String message)
Verify that key is a legal value for the horizontalAlignment properties.
protected int checkVerticalKey(int key, String message)
Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
AccessibleContext getAccessibleContext()
Get the AccessibleContext of this object
Icon getDisabledIcon()
Returns the value of the disabledIcon property if it's been set, If it hasn't been set and the value of the icon property is an ImageIcon, we compute a "grayed out" version of the icon and update the disabledIcon property with that.
int getDisplayedMnemonic()
Return the keycode that indicates a mnemonic key.
int getDisplayedMnemonicIndex()
Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character.
int getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.
int getHorizontalTextPosition()
Returns the horizontal position of the label's text, relative to its image.
Icon getIcon()
Returns the graphic image (glyph, icon) that the label displays.
int getIconTextGap()
Returns the amount of space between the text and the icon displayed in this label.
Component getLabelFor()
Get the component this is labelling.
String getText()
Returns the text string that the label displays.
LabelUI getUI()
Returns the L&F object that renders this component.
String getUIClassID()
Returns a string that specifies the name of the l&f class that renders this component.
int getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.
int getVerticalTextPosition()
Returns the vertical position of the label's text, relative to its image.
boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img.
protected String paramString()
Returns a string representation of this JLabel.
void setDisabledIcon(Icon disabledIcon)
Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
void setDisplayedMnemonic(char aChar)
Specifies the displayedMnemonic as a char value.
void setDisplayedMnemonic(int key)
Specify a keycode that indicates a mnemonic key.
void setDisplayedMnemonicIndex(int index)
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic.
void setHorizontalAlignment(int alignment)
Sets the alignment of the label's contents along the X axis.
void setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the label's text, relative to its image.
void setIcon(Icon icon)
Defines the icon this component will display.
void setIconTextGap(int iconTextGap)
If both the icon and text properties are set, this property defines the space between them.
void setLabelFor(Component c)
Set the component this is labelling.
void setText(String text)
Defines the single line of text this component will display.
void setUI(LabelUI ui)
Sets the L&F object that renders this component.
void setVerticalAlignment(int alignment)
Sets the alignment of the label's contents along the Y axis.
void setVerticalTextPosition(int textPosition)
Sets the vertical position of the label's text, relative to its image.
void updateUI()
Resets the UI property to a value from the current look and feel.

Example:

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

public class jlabel extends JApplet{
public jlabel() {
Container contentpane=getContentPane();
JLabel label=new JLabel("Hello from Java");
contentpane.setLayout(new FlowLayout()); //Used for Line Alignment
contentpane.add(label);
}
}

The ImageIcon class lets you create an icon from an image file for use in a Swing control.

Constructor Summary
ImageIcon()
Creates an uninitialized image icon.
ImageIcon(byte[] imageData)
Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF or JPEG.
ImageIcon(byte[] imageData, String description)
Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF or JPEG.
ImageIcon(Image image)
Creates an ImageIcon from an image object.
ImageIcon(Image image, String description)
Creates an ImageIcon from the image.
ImageIcon(String filename)
Creates an ImageIcon from the specified file.
ImageIcon(String filename, String description)
Creates an ImageIcon from the specified file.
ImageIcon(URL location)
Creates an ImageIcon from the specified URL.
ImageIcon(URL location, String description)
Creates an ImageIcon from the specified URL.

Method Summary
AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this ImageIcon.
String getDescription()
Gets the description of the image.
int getIconHeight()
Gets the height of the icon.
int getIconWidth()
Gets the width of the icon.
Image getImage()
Returns this icon's Image.
int getImageLoadStatus()
Returns the status of the image loading operation.
ImageObserver getImageObserver()
Returns the image observer for the image.
protected void loadImage(Image image)
Loads the image, returning only when the image is loaded.
void paintIcon(Component c, Graphics g, int x, int y)
Paints the icon.
void setDescription(String description)
Sets the description of the image.
void setImage(Image image)
Sets the image displayed by this icon.
void setImageObserver(ImageObserver observer)
Sets the image observer for the image.
String toString()
Returns a string representation of this image.

Example:

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

public class jlabel extends JApplet{

public void jlabel() {
Container contentPane=getContentPane();


JLabel label=new JLabel("Label", new ImageIcon("label.jpg"), JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
label.setHorizontalTextPosition(JLabel.CENTER);


contentPane.add(label);
}



SWING - Applets, Applications and Pluggable Look And Feel

Swing is a set of packages built on top of the AWT that provides you with a great number of prebuilt classes (over 250 classes and 40UI components). These 40 UI Components are:

  • JApplet - An extended version of java.applet.Applet that adds support for root panes and other panes
  • JButton - A push and command button
  • JCheckBox - A check box that can be selected or deselected, displaying its state visually.
  • JCheckBoxMenuItem - A menu item that can be selected or deselected, displaying its state visually.
  • JColorChooser - A pane of controls to allow a user to select a color.
  • JComboBox - A combo box, which is a combination of a test field and dropdown list.
  • JComponent - The base class for swing components
  • JDesktopPane - A container used to create a multiple-document interface or a desktop.
  • JDialog - The base class for creating a dialog window.
  • JEditorPane - A text component that allows the user o edit various kinds of content.
  • JFileChooser - Lets the user choose a file.

  • JFrame - An extended version of java.awt.Frane that adds support root panes and other panes.

  • JInternalFrame - A lightweight object that provides many of the features of a heavyweight frame.

  • JInternalFrame.JDesktopIcon - Represents an inconified version of a JInternalFrame.

  • JLabel - A display area for a short text string or an image or both.

  • JLayeredPane - Adds layers to a Swing container, allowing components to overlap each other.

  • JList - A components that allows the user to select one or more objects from list.

  • JMenu - A pop-up menu containing JMenuItems that's displayed when the user selects it in the JMenuBar component.

  • JMenuBar - An implementation of menu bar.

  • JMenuItem - An implementation of menu item.

  • JObjectPane - Makes it easy to pop up a standard dialog box.

  • JPanel - A generic lightweight container.

  • JPasswordField - Allows editing of a single line of text where the view does not show the original characters.

  • JPopupMenu - A pop-up menu.

  • JPopupMenu.Separator - A pop-up menu specific separator

  • JProgressBar - A component that displays an integer value within an interval.

  • JRadioButton - A radio button that can be selected or deselected, displaying its state visually

  • JRadioButtonMenuItem - An radio button menu item.

  • JRootPane - The fundamental component in the container hierarchy.

  • JScrollBar - An implementation of a scrollbar.

  • JScrollPane - A container that manages a view port, optional vertical and horizontal scrollbars and optional row and column heading view ports.

  • JSeparator - A menu separator.

  • JSlider - A component that lets the user select a value by sliding a knob within an interval.

  • JSplitPane - Divides two components.

  • JTabbedPane - Lets the user switch between a group of components by clicking tabs.

  • JTable - Presents data in a two dimensional table format

  • JTextArea - A multiline area that displays text.

  • JTextField - Allows the editing of a single line of text.

  • JTextPane - A text component that can be marked up with attributes.

  • JToggleButton - A two-state button

  • JToggleButton.ToggleButtonModel - The toggle button model

  • JToolBar - A toolbar, useful for displaying commonly used controls.

  • JToolBar.Separator - A toolbar-separator

  • JToolTip - Displays a tool tip for a component

  • JTree - Displays a set of hierarchical data as an outline

  • JTree.DynamicUtilTreeNode - Can wrap vectors/ hashtables/ arrays/ strings and create appropriate children tree nodes

  • JTree.EmptySelectionModel - A trees election model that does not allow anything to be selected.

  • JViewport - The view port through which you see the information

  • JWindow - A window that can be displayed anywhere on the desktop

Inheritance, Inner Classes and Interfaces

Inheritance

Example, an applet create a super class based on the Applet class using the extends keyword-

import java.applet.Applet; //File Name is applet.java
import java.awt.*;
public class applet extends Applet //Here applet is a user defined class and Applet is library class of java
{
public void paint(Graphics g) // Here Graphics is a library class of super class Applet
{
g.drawString("Hello from Java",60,100); //Here drawString is a library method of class Applet
}
}

Interface

Suppose you want to create an applet that handles button clicks. To create a standard applet, you can derive a class from the java.applet.Applet class, and to handle button clicks, you use another class, ActionListener. Therefore, it looks as through you'll have to base your applet on the Applet and ActionListener classes.

In this case, that means you can extend your applet from the Applet class and use the implements keyword to add the button-click handling.

Example:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class clicker extends Applet implements ActionListener{
TextField text1;
Button button1;

public void init(){
text1=new TextField(20);
add(text1);
button1=new Button("Click Here");
add(button1);
button1.addActionListener(this);
}

public void actionPerformed(ActionEvent event){
String msg=new String("Welcome to Java");
if(event.getSource()==button1){
text1.setText(msg);
}
}
}

Inner Class

Java now lets you creates within classes, and the enclosed class is called an inner class. You might not see much need for defining classes within classes now, but it will become more apparent when we start handling user interface events, such as when the user closes a window.

Events are handled with interfaces and when you implement an interface, you must also provide implementations of several abstract methods inside the interface. To make this process easier, java provides adapter classes (Inner Class)

Example:

AppFrame.java file contains-

import java.awt.*;
import java.awt.event.*;

public class AppFrame extends Frame
{
public void paint(Graphics g)
{
g.drawString("Hello from Java..",60,100);
}
}

App.java file contains-

import java.awt.*;
import java.awt.event.*;

public class App
{
public static void main(String[] args)
{
AppFrame f=(new AppFrame());
f.setSize(200,200);
f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
f.show();
}
}