0

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();
    }
}
2
Contributors
1
Reply
7
Views
4 Years
Discussion Span
Last Post by stultuske
1

why do you pass frame as a parameter?
also, you are showing and running an input dialog, but you're not saving the returned value anywhere, what's the use of that?
could you please be a bit more specific of what the problem is exactly?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.