2.3 Create an application that displays a frame with a menu bar. When a user selects any menu or menu item, display that selection on a text area in the center of the frame

Prac9Menu.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Prac9Menu extends JFrame implements ActionListener
{
private JMenuItem newOne;
private JMenuItem save;
private JMenuItem SaveAs;
private JMenuItem exit;
private JTextArea l;

Prac9Menu()
{
setLayout(new FlowLayout());
JMenuBar menubar=new JMenuBar();

JMenu menu=new JMenu("File");

l=new JTextArea(1,5);
JPanel p=new JPanel();
add(p);
l.setLayout(new FlowLayout());
p.add(l);

newOne=new JMenuItem("new");
save=new JMenuItem("save");
SaveAs=new JMenuItem("SaveAs");
exit=new JMenuItem("Exit");

menubar.add(menu);
menu.add(newOne);
menu.add(save);
menu.add(SaveAs);
menu.add(exit);

newOne.addActionListener(this);
save.addActionListener(this);
SaveAs.addActionListener(this);
exit.addActionListener(this);

setDefaultCloseOperation(EXIT_ON_CLOSE);
setJMenuBar(menubar);

setSize(600,400);
setVisible(true);

}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==newOne)
{
l.setText("new");
}
else if(ae.getSource()== save)
{
l.setText("save");
}
else if(ae.getSource()== SaveAs)
{
l.setText("saveAS");
}
else if(ae.getSource()== exit)
{
l.setText("exit");
}
}

public static void main(String arg[])
{
new Prac9Menu();
}
}

Output

Try code to see proper output

Happy Coding :)