i need to make the Print JMenuItem to open a printdialog box when clicked but i dont know how to make it can u help me pls
p.addActionListener(new ActionListener()
heres the code can u add the printdialogbox i searched but i cant put it on the program

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


public class Cs2 extends JFrame 
{

   public static void main(String args[]){

        JFrame frame = new JFrame("Case Study no.1"); 
        frame.setSize(300,200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenuBar menu =new JMenuBar();

        frame.setJMenuBar(menu);
        JMenu file=new JMenu("File");
        JMenu view =new JMenu("View");
        menu.add(file);
        menu.add(view);
        JMenuItem o = new JMenuItem("Open");
        JMenu a = new JMenu("Add");
        JMenuItem p = new JMenuItem("Print");
        file.add(o);
        file.add(a);
        file.add(p);
        a.add(new JMenuItem("Employee Name"));
        a.add(new JMenuItem("Employee Number"));
        view.add(new JMenuItem("Employee Name"));
        view.add(new JMenuItem("Employee Number"));
        view.add(new JMenuItem("All"));         
        o.addActionListener(new ActionListener() 

    {
        public void actionPerformed(ActionEvent e) {
        JFileChooser fc =new JFileChooser();
        fc.showOpenDialog(null);

    }});    


    }
}

add an actionlistener to p, and within your actionperform method, check what the source of the event is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.