import javax.swing.*;
	import java.awt.*;
	import java.awt.event.*;
	
		public class MainFrame extends JFrame{
		
		
		
	 
		JMenuBar main=new JMenuBar();
		JMenu menu1=new JMenu("File");
		JMenu menu2=new JMenu("Search");
		JMenu menu3=new JMenu("Display");
		JMenu menu4=new JMenu("About");
		JMenuItem exit=new JMenuItem("Exit");
		JMenuItem pw=new JMenuItem("Piece Worker");
		JMenuItem hw=new JMenuItem("Hourly Employee");
		JMenuItem pcw=new JMenuItem("Piece Worker");
		JMenuItem hrly=new JMenuItem("Hourly Worker");
		JMenuItem author=new JMenuItem("Author");
		JLabel label=new JLabel("Hello");
		public MainFrame(){
		
				setTitle("Employee Entry");
			 
				setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				setLayout(new FlowLayout());
				setJMenuBar(main);
				main.add(menu1);
				main.add(menu2);
				main.add(menu3);
				main.add(menu4);
				menu1.add(exit);
				menu2.add(pw);
				menu2.add(hw);
				menu3.add(pcw);
				menu3.add(hrly);
				menu4.add(author);
			  
				label.setFont(new Font("Arial",Font.BOLD,26));				
			}
		 
			public static void main(String [] args){
					
					MainFrame frame=new MainFrame();
					frame.setSize(500,200);
					frame.setVisible(true);
					frame.setResizable(false);			
				}
			}

Can someone teach me how to put an image to the whole space of the frame....

Recommended Answers

All 20 Replies

One of the easiest way would be, if you don't intend to add any components to the main frame

JLabel lab = new JLabel(new ImageIcon("full file path"));
frame.setSize(500,200);
frame.add(lab);
frame.setVisible(true);
frame.setResizable(false);

If you want to put the Image to the whole screen then you will have to get the scaled image for the icon and also change the size of the label to the frame's dimension.

ok i get what your trying to say to me....but the problem is I don't know how to add your idea you give to me to the code I have posted here.....how to add the code of inserting image to the code i have posted here.....


thank you much..........

Inside the constructor, create the JLabel with the image and add it to the component. You might want to look at the API of JLabel.

For adding elements to a frame check some tutorials. I usually do this in the constructor:

private JPanel panel = new JPanel();

public MainFrame() {
setTitle("Employee Entry");
....


// create the label as explained
// added to the panel:
panel.add(label);

// add the panel to the frame
add(panel);
}
import javax.swing.*;
	import java.awt.*;
	import java.awt.event.*;
	
		public class MainFrame extends JFrame {	
		
		 		JPanel panel=new JPanel();
	 
		JMenuBar main=new JMenuBar();
		JMenu menu1=new JMenu("File");
		JMenu menu2=new JMenu("Search");
		JMenu menu3=new JMenu("Display");
		JMenu menu4=new JMenu("About");
		JMenuItem exit=new JMenuItem("Exit");
		JMenuItem pw=new JMenuItem("Piece Worker");
		JMenuItem hw=new JMenuItem("Hourly Employee");
		JMenuItem pcw=new JMenuItem("Piece Worker");
		JMenuItem hrly=new JMenuItem("Hourly Worker");
		JMenuItem author=new JMenuItem("Author");
		JLabel label=new JLabel("Hello");
		public MainFrame()
		
			{
			 
				setTitle("Employee Entry");
				 			  	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				setLayout(new FlowLayout());
				setJMenuBar(main);
				main.add(menu1);
				main.add(menu2);
				main.add(menu3);
				main.add(menu4);
				menu1.add(exit);
				menu2.add(pw);
				menu2.add(hw);
				menu3.add(pcw);
				menu3.add(hrly);
				menu4.add(author);
			 				label.setFont(new Font("Arial",Font.BOLD,26));	
			}
			 			
				  
			public static void main(String [] args){
					
					MainFrame frame=new MainFrame();
					frame.setSize(500,200);
					frame.setVisible(true);
					frame.setResizable(false);			
				}
			}

Can someone help me how to make it work my program..
I'm using the JMenuBar..to create JMenuItem but my problem is if the user will choose one of the menu item..for instance if the user will choose in the menu item PieceWorker the pieceworker window shoud result...i don't know how to call the other frame ....can some one teach me..or if you do have known a sites that can solve my problem..please let me know....

thanks...

You need to add an ActionListener to each of your items. Look at the JMenuItem API. When the menu is clicked the ActionListener's method will be called.
If you want to open another frame, just do what you did in the main.
Create a new frame and then make it visible. You can run that code from anywhere for as many frames that you created.

You can easily find tutorials on the net. Just search!

Can someone give me some idea...I have only JFrame for my main...lets just say the home..in my home class there I use a JMenuBar to create JMenuItem..then my problem now is how to call the JMenuItem I put in the main my the list of the menu of my program and I don't how to call from another classes I have created...in my first menu I have the file..the item that belong to file is the exit and the employee entry..what I want is that if the user will click the word exit in the menu the program should exit..then if the user wil click the employee entry the employee entry frame should be the result

hope you can give me some idea or some sites for me to refer...

This the main or lets just say my home page of my program...

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

public class MainMenu extends JFrame implements ActionListener{

    private MenuBar mainBar = new MenuBar();
    private Menu menu1 = new Menu("File");
    private Menu menu2 = new Menu("Search");
    private Menu menu3 = new Menu("Display");
    private Menu menu4 = new Menu("About");
    private MenuItem emp = new MenuItem("Employee Entry");
    private MenuItem exit = new MenuItem("Exit");
    private MenuItem search_he = new MenuItem("Hourly Employee");
    private MenuItem search_pe = new MenuItem("Piece Worker");
    private MenuItem display_he = new MenuItem("Hourly Employee");
    private MenuItem display_pe = new MenuItem("Piece Worker");
    private MenuItem author = new MenuItem("Author");

    private MainMenu(){

        super("University of Cebu - Employee Entry");
          ImageIcon i=new ImageIcon("cics_logo.png");
          add(new JLabel(i));


        setLayout(new FlowLayout());
        setMenuBar(mainBar);
        mainBar.add(menu1);
        mainBar.add(menu2);
        mainBar.add(menu3);
        mainBar.add(menu4);
        menu1.add(emp);
        menu1.add(exit);
        menu2.add(search_he);
        menu2.add(search_pe);
        menu3.add(display_he);
        menu3.add(display_pe);
        menu4.add(author);
                 }



    public void actionPerformed(ActionEvent e){

          }

    public static void main(String[] args){
        MainMenu mMenu = new MainMenu();

        mMenu.setSize(500, 500);
        mMenu.setVisible(true);
        mMenu.setResizable(false);
        mMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

I really need some help....

please look at my program what kind of listener should I use ..

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

public class MainMenu extends JFrame implements ActionListener{
  
    private MenuBar mainBar = new MenuBar();
    private Menu menu1 = new Menu("File");
    private Menu menu2 = new Menu("Search");
    private Menu menu3 = new Menu("Display");
    private Menu menu4 = new Menu("About");
    private MenuItem emp = new MenuItem("Employee Entry");
    private MenuItem exit = new MenuItem("Exit");
    private MenuItem search_he = new MenuItem("Hourly Employee");
    private MenuItem search_pe = new MenuItem("Piece Worker");
    private MenuItem display_he = new MenuItem("Hourly Employee");
    private MenuItem display_pe = new MenuItem("Piece Worker");
    private MenuItem author = new MenuItem("Author");
  
    private MainMenu(){
      
        super("University of Cebu - Employee Entry");
          ImageIcon i=new ImageIcon("cics_logo.png");
          add(new JLabel(i));
         

        setLayout(new FlowLayout());
        setMenuBar(mainBar);
        mainBar.add(menu1);
        mainBar.add(menu2);
        mainBar.add(menu3);
        mainBar.add(menu4);
        menu1.add(emp);
        menu1.add(exit);
        menu2.add(search_he);
        menu2.add(search_pe);
        menu3.add(display_he);
        menu3.add(display_pe);
        menu4.add(author);
                 }
 

 
    public void actionPerformed(ActionEvent e){
        Object source = e.getSource();
        Container con = getContentPane();
			int exit;
		   boolean isYes;
 
		           if(source==exit){
					  exit=JOptionPane.showConfirmDialog(null,"Are you sure you want to exit");
					  isYes=(exit==JOptionPane.YES_CANCEL_OPTION);
					  System.out.println(0);
					 }
					  					   
  }
    public static void main(String[] args){
        MainMenu mMenu = new MainMenu();
      
        mMenu.setSize(500, 500);
        mMenu.setVisible(true);
        mMenu.setResizable(false);
        mMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

I add some on my code in the actionperformed please do check what i did wrong i can't get it...

The code seems correct. But you need to declare when the "exit" is clicked what listener it will use. You have the method actionPerformed, so when it is called you will get result that you want. But you need to declare when that method will be called. Meaning that you need to add the listener that you created to the elements you want to respond to it:

...
menu1.add(exit);
menu2.add(pw);
menu2.add(hw);
menu3.add(pcw);
menu3.add(hrly);
menu4.add(author);
...

// check the API for the correct spelling of the method
exit.addActionListener(this);
author.addActionListener(this);
...


public void actionPerformed(ActionEvent e){
   Object source = e.getSource();
   
   // exit is the MenuItem declared globaly
   if(source==exit){ 

     int choice = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit");
     if (choice == JOptionPane.) { // check the API of JOptionPane in order to determine what to use here
         System.exit(0);
    }

   } else if (source==author) { // author MenuItem clicked

     // do some stuff
     // you can declare a different frame here and open it
     AuthorFrame fr = new AuthorFrame();
     
      fr.setSize(500, 500);
      fr.setVisible(true);
      fr.setResizable(false);
      fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   }
					  				   
}

This is my code the JMenuItem "exit" is already working, but our teacher required us that the "exit"JMenuItems should have the button "Yes" and "Cancel"..but what I make is the" Yes"and the "No" button but I don't know how to change it..I hope some one can give me suggestion....

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

public class MainMenu extends JFrame implements ActionListener{
  
    private MenuBar mainBar = new MenuBar();
    private Menu menu1 = new Menu("File");
    private Menu menu2 = new Menu("Search");
    private Menu menu3 = new Menu("Display");
    private Menu menu4 = new Menu("About");
    private MenuItem emp = new MenuItem("Employee Entry");
    private MenuItem exit = new MenuItem("Exit");
    private MenuItem search_he = new MenuItem("Hourly Employee");
    private MenuItem search_pe = new MenuItem("Piece Worker");
    private MenuItem display_he = new MenuItem("Hourly Employee");
    private MenuItem display_pe = new MenuItem("Piece Worker");
    private MenuItem author = new MenuItem("Author");
  
    private MainMenu(){
      
        super("University of Cebu - Employee Entry");
          ImageIcon i=new ImageIcon("cics_logo.png");
          add(new JLabel(i));
         addActionListener();

        setLayout(new FlowLayout());
        setMenuBar(mainBar);
        mainBar.add(menu1);
        mainBar.add(menu2);
        mainBar.add(menu3);
        mainBar.add(menu4);
        menu1.add(emp);
        menu1.add(exit);
        menu2.add(search_he);
        menu2.add(search_pe);
        menu3.add(display_he);
        menu3.add(display_pe);
        menu4.add(author);
	   }
  public void addActionListener(){
   
			 exit.addActionListener(this); 
			 search_pe.addActionListener(this);
			 search_he.addActionListener(this);
			 display_pe.addActionListener(this);
			 display_he.addActionListener(this);
			 author.addActionListener(this);
			 emp.addActionListener(this);
	 	}
    public void actionPerformed(ActionEvent e){
     Object source = e.getSource();
         Container con = getContentPane();
					 
		 if(e.getSource()==exit){
		 
		 if  (JOptionPane.showConfirmDialog(new JFrame(),
         "Are you sure you want to Exit?", "Exit",
   JOptionPane.YES_NO_OPTION) == JOptionPane.YES_NO_OPTION){
   				   System.exit(0);
	  	this.setVisible(true);

 }
 }
	 	  
	 					  					   
  }
     public static void main(String[] args){
        MainMenu mMenu = new MainMenu();
      
        mMenu.setSize(500, 500);
        mMenu.setVisible(true);
        mMenu.setResizable(false);
        mMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

And off course my JMenuItem contains a lot of Menus..but my problem is I don't know how to call it,because it is in the other class..
This is the code..Can you help me how to work all my JMenuItem in my homepage of my program..

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

public class EmployeeEntry extends JFrame implements ActionListener{
  
    JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel6_1, panel6_2;
    JTextField txtId, txtLast, txtFirst, txtMi, txtAge, txtBranch, txtHeHrs, txtHeRate, txtPeItm, txtPeRate;
    JComboBox cbEmployee;
    JButton btnAdd, btnDelete, btnBack;
    JRadioButton rbMale, rbFemale;
    String separator = "--------------------", hourly = "Hourly Employee     ", piece = "Piece Worker        ";
  
    //instantiation
   private void instantiate() {
  
        panel1 = new JPanel();
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel4 = new JPanel();
        panel5 = new JPanel();
        panel6 = new JPanel();
        panel7 = new JPanel();
        panel8 = new JPanel();
  
        txtId = new JTextField(8);
        txtLast = new JTextField(10);
        txtFirst = new JTextField(10);
        txtMi = new JTextField(1);
        txtAge = new JTextField(2);
        txtBranch = new JTextField(15);
        txtHeHrs = new JTextField(8);
        txtHeRate = new JTextField(12);
        txtPeItm = new JTextField(8);
        txtPeRate = new JTextField(7);
      
        String employee[]= {separator, hourly, piece};
        cbEmployee=new JComboBox(employee);  
  
        btnAdd=new JButton("ADD");
        btnDelete = new JButton("DELETE");
        btnBack = new JButton("Back to Main");
    
        rbMale=new JRadioButton("Male");
        rbFemale=new JRadioButton("Female");   
    }
  
    public EmployeeEntry() {
        super("Employee Entry");
        setIconImage(new ImageIcon("images/logo.jpg").getImage());
        Container pane = this.getContentPane();
        this.instantiate();
      
        pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
        pane.add(panel1);
        pane.add(panel2);
        pane.add(panel3);
        pane.add(panel4);
        pane.add(panel5);
        pane.add(panel6);
        pane.add(panel7);
        pane.add(panel8);  
          
        //adding components
        FlowLayout layout=new FlowLayout();
            layout.setAlignment(FlowLayout.LEFT);
      
            panel1.setLayout(layout);
            panel1.add(new JLabel(" ID NUMBER "));
            panel1.add(txtId);  
  
        JPanel panel2_1, panel2_2, panel2_3;
            panel2_1 = new JPanel();
            panel2_2 = new JPanel();
            panel2_3 = new JPanel();
            panel2_1.setLayout(new BoxLayout(panel2_1,BoxLayout.X_AXIS));
            panel2_2.setLayout(new BoxLayout(panel2_2,BoxLayout.X_AXIS));
            panel2_3.setLayout(new BoxLayout(panel2_3,BoxLayout.X_AXIS));
      
            panel2_1.add(new JLabel(" LASTNAME "));
            panel2_1.add(txtLast);
            panel2_2.add(new JLabel(" FIRSTNAME "));
            panel2_2.add(txtFirst);
            panel2_3.add(new JLabel(" MI "));
            panel2_3.add(txtMi);
          
            panel2.setLayout(layout);
            panel2.add(panel2_1);
            panel2.add(panel2_2);
            panel2.add(panel2_3);
            
            panel3.setLayout(layout);
            panel3.add(new JLabel(" AGE "));
            panel3.add(txtAge);
            panel3.add(new JLabel(" GENDER "));
            panel3.add(rbMale);
            panel3.add(new JLabel("              "));
            panel3.add(rbFemale);
           ButtonGroup genderButtonGroup=new ButtonGroup();
              genderButtonGroup.add(rbFemale);
              genderButtonGroup.add(rbMale);
            panel4.setLayout(layout);
          
            panel5.setLayout(layout);
            panel5.add(new JLabel(" BRANCH "));
            panel5.add(txtBranch);
            panel5.add(new JLabel(" EMPLOYEE TYPE "));
            panel5.add(cbEmployee);
            setVisible(true);
      
//LINE BORDER      
            panel6.setLayout(new BorderLayout());
            panel7.add(btnAdd);
            panel7.add(btnDelete);
            panel7.add(btnBack);
          btnAdd.addActionListener(this);
			 btnDelete.addActionListener(this);
			 btnBack.addActionListener(this);
            panel8.setLayout(layout);
            setVisible(true);
			
    }
  
    public void actionPerformed(ActionEvent e){
        Object source = e.getSource();
        Container con = getContentPane();
      
        if(source == hourly){
            panel6_2.setVisible(false);
            this.setVisible(true);
        } else if(source == piece){
            panel6_1.setVisible(false);
            this.setVisible(true);
        }else if(source == separator){
            this.setVisible(false);
        }
    }
  
    public static void main(String[]args) {
        EmployeeEntry emp=new EmployeeEntry();
            emp.setSize(500,400);
            emp.setResizable(false);
            emp.setVisible(true);
            emp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

I hope all my JMenus would work...

You need to add the ActionListener like below

author.addActionListener(this);

Now also add a println in your actionPerformed just to test

Churva, check the API of the JOptionPane. I repeatedly tell you to check the API but you don't. From all of your posts you give the impression that you want others to give you the solution.
If you have read the JOptionPane API you would have found the solution. Don't just use random commands.

If you want a "Yes and Cancel", why did you create the JOptionPane like that?
>>>
JOptionPane.showConfirmDialog(new JFrame(),
"Are you sure you want to Exit?", "Exit",
JOptionPane.YES_NO_OPTION)
<<<
Did you read the API in order to see what that argument means and what you should use? Or did you copy it from somewhere, or you just use your IDE's auto complete system and just chose a random argument?

And in my previous post I told you how to call the EmployeeEntry frame when the "Employee Entry" item is clicked. I gave you an example on how to call frames. Don't use a main method. That is only when you run the program in order to open the MainMenu frame. That you call from a main method, but for the others you just instantiate them like any other class. Like in my example, which you didn't follow

javaAddict I have read all your suggestion and I appreciate it a lot,but is just that I haven't read much about API, because I have no much resources to help me about API,and I know internet can help me learn about API but the problem is my time is limited in using internet..and also my time is limited because im just a working student it is hard to manage thats why im asking help or suggestion what to do on my program ,and im also new to GUI.,,

I just really need consideration..

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
 public class Exit extends JFrame implements ActionListener{
 
 			JLabel ask;
			JButton btnYes,btnCancel;
			
			public   Exit(){
			
			ask=new JLabel("Are you sure you want to exit?");
			btnYes=new JButton("Yes");
			btnCancel=new JButton("Cancel");
		 
				add(btnYes);
				add(btnCancel);
				add(ask);
 
 
					btnYes.addActionListener(this);
					btnCancel.addActionListener(this);
				 }
 
				public static void main(String [] args){
					Exit ex=new Exit();
					ex.setSize(100,20);
					ex.setVisible(true);
					ex.setResizable(false);
					ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}
				}

Can you help solve this one..please do check

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
 public class Exit extends JFrame implements ActionListener{
 
 			JLabel ask;
			JButton btnYes,btnCancel;
			
			public  Exit(){
			super("Exit");
			 setSize(100,20);
			setVisible(true);
			ask=new JLabel("Are you sure you want to exit?");
			btnYes=new JButton("Yes");
			btnCancel=new JButton("Cancel");
		 
				add(btnYes);
				add(btnCancel);
				add(ask);
 
 
					btnYes.addActionListener(this);
					btnCancel.addActionListener(this);
				 }
 
				public static void main(String [] args){
					Exit ex=new Exit();
					 
					ex.setResizable(false);
					ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}
				}

I really don't understand on what I did wrong.. please do help me..
Thanks...

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
 public class Exit extends JFrame implements ActionListener{
 
 			JLabel ask;
			JButton btnYes,btnCancel;
			
			public  Exit(){
			super("Exit");
			 setSize(100,20);
			setVisible(true);
			ask=new JLabel("Are you sure you want to exit?");
			btnYes=new JButton("Yes");
			btnCancel=new JButton("Cancel");
		 
				add(btnYes);
				add(btnCancel);
				add(ask);
 
 
					btnYes.addActionListener(this);
					btnCancel.addActionListener(this);
				 }
 
				public static void main(String [] args){
					Exit ex=new Exit();
					 
					ex.setResizable(false);
					ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}
				}

I really don't understand on what I did wrong.. please do help me..
Thanks...

First of all, I have already given you the solution for the above problem. I gave you the code. You said it worked. And now you write that code that is exact opposite of you have been told. I gave you the code for the "exit", gave you the code for calling other frames when you click the button, and now you write this code, without even copying what you have been told.

If you have limited time, then why do you post here and you don't study. The API I gave you has the solution. You said you didn't have time to read it but had time to post here?

Also if you don't have access to the net buy a book! Everything you ask is in every basic book.

Every code that has been posted here solves your problems. What do you want? To come to your house and write it for you?


Also you said that this gives you the YES_NO option:
>>>
JOptionPane.showConfirmDialog(new JFrame(),
"Are you sure you want to Exit?", "Exit",
JOptionPane.YES_NO_OPTION)
<<<
Time or no time, you don't need to be a genius to figure out what you need to do in order ti display a dialog with OK_CANCEL option.

Thank javaAddict..I really appreciate your help to me..but sorry if sometimes its really hard for me to get easily your idea,but its ok i still idea..

Thank You again...

Member Avatar for ztini
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class MainMenu extends JFrame{
  
	private JMenuBar bar = new JMenuBar();
	private JLabel logo;
	
	public MainMenu() {
		configBody();
		configMenu();

		setSize(500, 500);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("University of Cebu - Employee Entry");
		setVisible(true);
	}

	private void configBody() {
		setLayout(new BorderLayout());
		JPanel panel = new JPanel();
		add(panel, BorderLayout.CENTER);
		logo = new JLabel(new ImageIcon(getClass().getResource("images/cics_logo.png")));
		panel.add(logo);
	}

	private void configMenu() {
		setJMenuBar(bar);
		JMenu file = createMenu("File");
			file.add(createItem("Employee Entry"));
			file.add(createItemExit("Exit"));
		JMenu search = createMenu("Search");
			search.add(createItem("Hourly Employee"));
			search.add(createItem("Piece Worker"));
		JMenu display = createMenu("Display");
			display.add(createItem("Hourly Empoyee"));
			display.add(createItem("Piece Worker"));
		JMenu about = createMenu("About");
			about.add(createItem("Author"));
    }
    
	private JMenu createMenu(String label) {
		JMenu menu = new JMenu(label);
		bar.add(menu);
		return menu;
	}
    
	private JMenuItem createItem(String label) {
		JMenuItem item = new JMenuItem(label);
		item.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// Do something				
			}
		});
		return item;
	}
    
	private JMenuItem createItemExit(String label) {
		final JMenuItem item = new JMenuItem(label);
		item.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (JOptionPane.showConfirmDialog(item, 
						"Are you sure you want to exit?", "Exit", 
						JOptionPane.YES_NO_OPTION) == 0)
					System.exit(0); 			
			}
		});
		return item;
	}
    
    public static void main(String[] args){
    	new MainMenu();
    }
}

Thank you ztini youu have help me to my problems...

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.