I need to input a name in the JMenuItem(employee name) using JOptionPane,
I used this statement
(JOptionPane.showInputDialog(frame, "Enter Employee Name");)
and I try using a string variable but nothings happen.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.text.MessageFormat;
import javax.swing.table.AbstractTableModel;
public class Cs extends JFrame implements ActionListener
{
FlowLayout layout = new FlowLayout();
final JFileChooser fc = new JFileChooser();
JFrame frame = new JFrame();
JMenuBar menu = new JMenuBar();
JMenu file = new JMenu("File");
JMenu view = new JMenu("View");
JMenuItem o = new JMenuItem("Open");
JMenu a = new JMenu("Add");
JMenuItem p = new JMenuItem("Print");
JMenuItem enam1 = new JMenuItem("Employee Name");
JMenuItem enum1 = new JMenuItem("Employee Number");
JMenuItem enam2 = new JMenuItem("Employee Name");
JMenuItem enum2 = new JMenuItem("Employee Number");
JMenuItem all = new JMenuItem("All");
MessageFormat header = new MessageFormat("Page {0,number,integer}");
private JTable table;
public Cs()
{
table = new JTable();
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
file.setMnemonic('F');
view.setMnemonic('V');
setJMenuBar(menu);
menu.add(file);
menu.add(view);
file.add(o);
file.add(a);
file.add(p);
a.add(enam1);
a.add(enum1);
view.add(enam2);
view.add(enum2);
view.add(all);
setTitle("Case Study in IT-7");
setSize(400,300);
setLocation(300,100);
setVisible(true);
setLayout(layout);
setResizable(false);
setDefaultLookAndFeelDecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
o.addActionListener(this);
p.addActionListener(this);
enam1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == o)
{
int returnVal = fc.showOpenDialog(Cs.this);
}
if(source == p)
{
try
{
table.print(JTable.PrintMode.FIT_WIDTH, header, null);
}
catch (java.awt.print.PrinterException z)
{
System.err.format("Cannot print %s%n", z.getMessage());
}
}
if(source == enam1)
{
JOptionPane.showInputDialog(frame, "Enter Employee Name");}
}
public static void main (String[]args)
{
Cs1 app = new Cs1();
}
}