Package menu

Source Code of menu.MainMenu

package menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import main.ILanguage;
import main.ISettings;
import user.ModifyMyInformation;
import admin.AdminTools;
import database.DbwDBConnection;

public class MainMenu extends JMenuBar implements IMainMenu, ILanguage, ISettings{

  /**
   *
   */
  private static final long serialVersionUID = -1234850848833173075L;
  private JMenuItem    jmHelp;
  private JMenu      jmOptions;
  private  JMenuItem    jmCredits;
  private  JMenu      jmAbout;
  private  JMenu      jmBonus;
  private JMenuItem    jmReportBugs;
  private JMenuItem    jmDeleteAllPrivateMessages;
  private JMenuItem    jmDeleteAllPublicMessages;
  private JMenuItem    jmModifyInformations;
  private JMenuItem    jmUsersList;
  private JMenuItem    jmHymne;
  private JMenuItem    jmComposeMessage;
  private JMenuItem    jmChangePassword;
  private JMenuItem    jmDisconnect;
  private JMenu      jmFile;
  private String       userName;
  private DbwDBConnection dataBaseConnection;
  protected Object jMenuItem=new JMenuItem();

  public MainMenu(String userName){
    this.userName=userName;

    dataBaseConnection= new DbwDBConnection();

    createMenu();
  }
  public void createMenu(){
    this.jmHelp=new JMenuItem(HELP);
    this.jmOptions= new JMenu(OPTIONS);
    this.jmCredits= new JMenuItem(CREDITS);
    this.jmAbout= new JMenu(ABOUT);
    this.jmBonus= new JMenu(BONUS);
    this.jmDisconnect=new JMenuItem(DISCONNECT);
    this.jmComposeMessage = new JMenuItem(COMPOSE_MESSAGE);
    this.jmChangePassword= new JMenuItem(CHANGE_PASSWORD);
    this.jmReportBugs= new JMenuItem(REPORT_BUGS);
    this.jmModifyInformations= new JMenuItem(MODIFY_MY_INFORMATION);
    this.jmDeleteAllPrivateMessages= new JMenuItem(DELETE_ALL_PRIVATE_MESSAGES);
    this.jmDeleteAllPublicMessages= new JMenuItem(DELETE_ALL_PUBLIC_MESSAGES);
    this.jmHymne= new JMenuItem(HYMNE);
    this.jmFile=new JMenu(FILE);
   
    jmFile.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmFile.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmFile.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmFile.setForeground(MENU_MOUSE_PRESSED)
      }
    });


    jmHymne.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmHymne.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmHymne.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmHymne.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmHymne.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeHymne){
        //TODO
      }});



    jmComposeMessage.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmComposeMessage.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmComposeMessage.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmComposeMessage.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmComposeMessage.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        new ComposeNewMessage(COMPOSE_NEW_MESSAGE_TITLE,userName);
      }});

    jmDeleteAllPrivateMessages.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmDeleteAllPrivateMessages.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmDeleteAllPrivateMessages.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmDeleteAllPrivateMessages.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmDeleteAllPrivateMessages.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        //TODO
      }});
    jmDeleteAllPublicMessages.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmDeleteAllPublicMessages.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmDeleteAllPublicMessages.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmDeleteAllPublicMessages.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmDeleteAllPublicMessages.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        //TODO
      }});

    jmReportBugs.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmReportBugs.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmReportBugs.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmReportBugs.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmReportBugs.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        //TODO
      }});

    jmModifyInformations.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmModifyInformations.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmModifyInformations.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmModifyInformations.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmModifyInformations.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        new ModifyMyInformation(userName, dataBaseConnection);
      }});



    jmHelp.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmHelp.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmHelp.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmHelp.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmHelp.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        new Help(HELP,HELP_TEXT);
      }});



    jmOptions.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmOptions.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmOptions.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmOptions.setForeground(MENU_MOUSE_PRESSED)
      }
    });

    jmBonus.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmBonus.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmBonus.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmBonus.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmBonus.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aemiAbout)
      {

      }
    });

    jmCredits.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmCredits.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmCredits.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmCredits.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmCredits.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        new About(ABOUT,ABOUT_TEXT);
      }});
    jmAbout.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmAbout.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmAbout.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmAbout.setForeground(MENU_MOUSE_PRESSED)
      }
    });


    jmChangePassword.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmChangePassword.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmChangePassword.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmChangePassword.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmChangePassword.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        try {
          new ChangePassword(userName);
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }});
    this.jmUsersList=new JMenuItem(USER_LIST);
    jmUsersList.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmUsersList.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmUsersList.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmUsersList.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmUsersList.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        String result=dataBaseConnection.getUserInformation(userName);
        new UsersList(result);
      }});

    jmDisconnect.addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        jmDisconnect.setForeground(MENU_MOUSE_ENTERED);
      }
      public void mouseExited(MouseEvent arg0) {
        jmDisconnect.setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        jmDisconnect.setForeground(MENU_MOUSE_PRESSED)
      }
    });
    this.jmDisconnect.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent aeComposeMessage){
        dataBaseConnection.disconnectUser(userName);
      }});
    jmFile.add(jmComposeMessage);
    jmFile.add(jmDisconnect);
    jmAbout.add(jmReportBugs);
    jmAbout.add(jmHelp);
    jmAbout.add(jmCredits);   
    jmOptions.add(jmChangePassword);
    jmOptions.add(jmModifyInformations);
    jmOptions.add(jmDeleteAllPrivateMessages);
    jmOptions.add(jmDeleteAllPublicMessages);
    jmBonus.add(jmUsersList);
    jmBonus.add(jmHymne);

    if (dataBaseConnection.getUserLevel(userName)==0 || dataBaseConnection.getUserLevel(userName)==1)
      this.add(new AdminTools(userName, dataBaseConnection));
    this.add(jmFile);
    this.add(jmOptions);
    this.add(jmAbout);
    this.add(jmBonus);
   


  }
  /*public void changeMenuColor(JMenuItem jMenuItem){

    ((Component) this.jMenuItem).addMouseListener(new MouseAdapter(){
      public void mouseEntered(MouseEvent e) {
        ((JComponent) MainMenu.this.jMenuItem).setForeground(Color.BLUE);
      }
      public void mouseExited(MouseEvent arg0) {
        ((JComponent) MainMenu.this.jMenuItem).setForeground(MENU_MOUSE_EXITED);

      }
      public void mousePressed(MouseEvent arg0) {
        ((JComponent) MainMenu.this.jMenuItem).setForeground(MENU_MOUSE_PRESSED); 
      }
    });

  }*/
}
 
TOP

Related Classes of menu.MainMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.