I am working on a video rental application. The system must provide a password protected environment with 2 different levels of authorisation. 1. Managerial level: who has the right to unlimited access. 2. Employee: who has access to their own specific functionality. I would like to solve this by using a pop-up menu, which pop-up when the user interacts with the application. But I have no idea how to do this. I would really appreciate some help! I attach the gui that I have been working on.
//Text field for the search string: private TextField searchField; private String result= "";
private Color blue = new Color(44, 153, 211); private Color grey = new Color(190, 194, 194); private Color black = new Color(0, 0, 0); pmqa_DBLayer database;
public void makeMenus(){ MenuBar mb = new MenuBar (); Menu staffMenu = new Menu ("Staff"); Menu admMenu = new Menu ("Administration"); mb.add(staffMenu); mb.add(admMenu);
//-------------------------------------------createButton()-------------- ---------------------- //Method to get the same size on the buttons public JButton createButton(String label) { JButton Button = new JButton(label); Button.setBackground(blue); Button.setPreferredSize(new Dimension(40, 5)); return Button; }//createButton()
public void insertPanel() { clearResult(); myContentPanel.remove(rightPanel); JPanel insertPanel = new JPanel(); insertPanel.setBackground(blue); GridLayout grid = new GridLayout(7,2); insertPanel.setLayout(grid);
title = new JLabel ("Title:" ,Label.LEFT); title.setForeground(black); actor = new JLabel ("Actor:" ,Label.LEFT); actor.setForeground(black); genre = new JLabel ("Genre:" ,Label.LEFT); genre.setForeground(black); length = new JLabel ("Length:" ,Label.LEFT); length.setForeground(black); videoNo = new JLabel ("VideoNo:" ,Label.LEFT); videoNo.setForeground(black);
//Declare TextField titleField = new TextField (14); titleField.setBackground(grey); actorField = new TextField (14); actorField.setBackground(grey); genreField = new TextField (14); genreField.setBackground(grey); videoNoField = new TextField (14); videoNoField.setBackground(grey);
JPanel top1 = new JPanel(); //panels are created to hold textfield, label and button top1.setBackground(blue); JPanel top2 = new JPanel(); top2.setBackground(blue); JPanel top3 = new JPanel(); top3.setBackground(blue); JPanel top4 = new JPanel(); top4.setBackground(blue); JPanel top5 = new JPanel(); top5.setBackground(blue); JPanel top6 = new JPanel(); top6.setBackground(blue); JPanel top7 = new JPanel(); top7.setBackground(blue); JPanel top8 = new JPanel(); top8.setBackground(blue); JPanel top9 = new JPanel(); top9.setBackground(blue); JPanel top10 = new JPanel(); top10.setBackground(blue); JPanel top11 = new JPanel(); top11.setBackground(blue);
top1.add(title); //panels are created to hold textfield, label and button insertPanel.add(top1); top2.add(titleField); insertPanel.add(top2); top3.add(actor); insertPanel.add(top3); top4.add(actorField); insertPanel.add(top4); top5.add(genre); insertPanel.add(top5); top6.add(genreField); insertPanel.add(top6); top7.add(length); insertPanel.add(top7); top8.add(lengthField); insertPanel.add(top8); top9.add(videoNo); insertPanel.add(top9); top10.add(videoNoField); insertPanel.add(top10);
public void removePanel() { clearResult(); myContentPanel.remove(rightPanel); JPanel removePanel = new JPanel(); removePanel.setBackground(blue); GridLayout grid = new GridLayout(7,2); removePanel.setLayout(grid);
title = new JLabel ("Title:" ,Label.LEFT); title.setForeground(black); actor = new JLabel ("Actor:" ,Label.LEFT); actor.setForeground(black); genre = new JLabel ("Genre:" ,Label.LEFT); genre.setForeground(black); length = new JLabel ("Length:" ,Label.LEFT); length.setForeground(black); videoNo = new JLabel ("VideoNo:" ,Label.LEFT); videoNo.setForeground(black);
//Declare TextField titleField = new TextField (14); titleField.setBackground(grey); actorField = new TextField (14); actorField.setBackground(grey); genreField = new TextField (14); genreField.setBackground(grey); videoNoField = new TextField (14); videoNoField.setBackground(grey);
JPanel top1 = new JPanel(); //panels are created to hold textfield, label and button top1.setBackground(blue); JPanel top2 = new JPanel(); top2.setBackground(blue); JPanel top3 = new JPanel(); top3.setBackground(blue); JPanel top4 = new JPanel(); top4.setBackground(blue); JPanel top5 = new JPanel(); top5.setBackground(blue); JPanel top6 = new JPanel(); top6.setBackground(blue); JPanel top7 = new JPanel(); top7.setBackground(blue); JPanel top8 = new JPanel(); top8.setBackground(blue); JPanel top9 = new JPanel(); top9.setBackground(blue); JPanel top10 = new JPanel(); top10.setBackground(blue); JPanel top11 = new JPanel(); top11.setBackground(blue);
top1.add(title); //panels are created to hold textfield, label and button removePanel.add(top1); top2.add(titleField); removePanel.add(top2); top3.add(actor); removePanel.add(top3); top4.add(actorField); removePanel.add(top4); top5.add(genre); removePanel.add(top5); top6.add(genreField); removePanel.add(top6); top7.add(length); removePanel.add(top7); top8.add(lengthField); removePanel.add(top8); top9.add(videoNo); removePanel.add(top9); top10.add(videoNoField); removePanel.add(top10);
Ok! What I can understand from your code is that you want to check the details entered by the user and then open the relative GUI with the relative details. Best way to go about is after your main GUI, create two classes: Manager and Employee. Create a GUI interface for the authentication window you want to appear, which asks for something like username and password. When details are entered and "OK" is pressed, the GUI will check on what was entered against your fixed info or a database and open the relative class. Give some more details and I will send you some code.
Thanks! But I'm not sure what you mean. When I run the application and the user e.g. tries to add a video, I would like a pop-up menu to appear that asks for username and password. I have created two tables in the database, one manager and one employee. When the user types in username and password, I would like to have a method that check the username and password against the database. I would really appreciate some code.
ok....to check the validity of the password you need to create a connection to the database. The design of your GUI could be changed to as follows: a main Frame which has two login options, Employee and Manager. When either one is clicked, a popup window opens to ask for the username and password, which are checked against their respective tables in the database. If true, it will open a respective GUI for the user with the functionality added as you want.
Alternatively as in your case, u can have one table called user which has a component called "Type". This can be either Employee or Manager, for all usernames and password. The system will check the value of this column and return for you the correct component.
the following code should help, although you will need to change the variables around.
Also remember, your database needs to be added to the ODBC Data Sources in Windows. This can be accessed from Settings-->Control Panel-->ODBC Data Sources or search for it. In the window, go to the section called System DSN-->Press Add-->Select Microsoft Access Driver-->Data Source Name must be the same given to DSN in the DBConn class-->then select your database-->press ok---press ok.
Thank you very much for all your help! :-) If I create two gui, do I have to create two pop-up menus as well? Or how do I code the pop-up? I'm also wondering how I create DDL in Access, I only find the design view and the vizard.? When I tried to connect the database to odbc it didnt work I got the message "Invalid directory or file path", do you no whats wrong?
I'm very sorry if I'm annoying you :-( Thanks again!
no worries..... The understanding I got was that the Manager's GUI will have more options and functionality than the Employees one. So you can create two seperate GUIs for each with the relevant functionality. The first GUI which should be called in your main method should the main one, which will have two buttons only, one for Employee and the other for Manager. When the user selects anyone, the popup window for username and password is called up. You just need to code this once and call it from both buttons. e.g. Popupwindow pw = new Popupwindow(); In the popup window, you will have a button which the user will press to submit the details of username and password. In the Action Performed method for this button, create an object of the class DBConn.i.e. DBConn db = new DBConn(); db.verify(username, password); db.terminate(); This will pass the details to the DBConn class and verify the details. Then it will open the correct GUI window, eith Employee or Manager. As far as Access is concerned, once you create you file, save it in the same folder as you .java files. Then open up ODBC and go the section for System DSN. Here click ADD, then select the option Microsoft Access Driver, and click Ok. This will bring you to a setup window. On the top, add a relevant name for the database like Video. Then press SELECT in the section for Database and select your file. Then click OK and Ok again to close the application. In the DBConn file that you create, write the name of the DSN that you gave in the setup like Video. This is put in for DSN in the code that I sent you, right up on top. This will allow you access the database without providing the entire path.
If you still have problems, send me a zipped copy of all your code on geegee_pk@yahoo.com, and I will try to sort it out for you.