/**
* @(#)Menu_FileDialog.java
*
*
* @author - Anant Mahale
* @version 1.00 2013/8/25
*program for file dialog box
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Menu_FileDialog
{
public static void main(String args[])
{
myframe m=new myframe();
m.setTitle("Open & Save");
m.setSize(400,400);
m.setVisible(true);
m.setLocation(100,100);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class myframe extends JFrame
{
mypanel p;
myframe()
{
p=new mypanel();
Container c=getContentPane();
c.add(p);
}
class mypanel extends JPanel implements ActionListener
{
JTextArea txta_show;
JMenu file;
JMenuItem open,save;
JMenuBar jmb=new JMenuBar();
mypanel()
{
setLayout(new BorderLayout());
file=new JMenu("File");
open=new JMenuItem("Open");
open.addActionListener(this);
save=new JMenuItem("save");
save.addActionListener(this);
file.add(open);
file.add(save);
jmb.add(file);
setJMenuBar(jmb);
txta_show=new JTextArea();
add(txta_show);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==open)
{
JFileChooser jfc=new JFileChooser();
jfc.showOpenDialog(this);
}
if(ae.getSource()==save)
{
JFileChooser jfc=new JFileChooser();
jfc.showSaveDialog(this);
}
}
}
}