Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.85 KB | None | 0 0
  1. //Note button for check gain should be added.
  2. //In database each good should have it own table.
  3. //The check gain, loss,sales etc will appear in toolbar
  4. /**
  5.  * @about MM-Pro Manage Small enterprises.
  6.  * @author F.E. Noel Nfebe.
  7.  * @version 1.0
  8.  */
  9. import java.awt.*;
  10. import javax.swing.*;
  11. import java.awt.event.*;
  12. import java.awt.event.ActionEvent; //The following are event controllers
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.KeyEvent;
  15. import java.awt.Dimension; //For things like Dimesions from getScreenSize toolkit.
  16. import java.awt.Toolkit; //For Issues like getings beeps screensize etc.
  17. import javax.swing.border.EtchedBorder;
  18.  
  19. public class MYMANAGERPRO extends JFrame {
  20.    
  21.    JPanel All_Content_Pane = new JPanel();
  22.    JMenuBar All_Menu_Items = new JMenuBar();
  23.    /*Menu list */
  24.    JMenu File = new JMenu("FILE");
  25.    JMenu Check_products = new JMenu("CHECK PRODUCTS");
  26.    JMenu Reports = new JMenu("REPORTS");
  27.    JMenu Help = new JMenu("HELP");
  28.    /*MenuItems for File */
  29.    JMenuItem Save_to_Database = new JMenuItem("Save to Database");
  30.    JMenuItem Close = new JMenuItem("Close");
  31.    /*MenuItems for Reports*/
  32.    JMenuItem Daily_reports = new JMenuItem("View Daily Rep...");
  33.    JMenuItem Weekly_reports =  new JMenuItem("View Weekly Rep...");
  34.    JMenuItem Monthly_reports = new JMenuItem("View Monthly Rep...");
  35.    /*MenuItem for Check Products */
  36.    JMenuItem Add_New_Products = new JMenuItem("Add new product(s)");
  37.    JMenuItem Delete_product = new JMenuItem("Delete product");
  38.    JMenuItem Change_product_name  = new JMenuItem("Change product name");
  39.    JMenuItem Change_product_price = new JMenuItem("Change product price");
  40.    JMenuItem Check_Current_Products = new JMenuItem("Check current product(s)");
  41.    JMenuItem Change_all_details = new JMenuItem("Change all details");
  42.   /*MenutItems for Help*/
  43.    JMenuItem help = new JMenuItem("Help");
  44.    JToolBar Tool_Bar =new  JToolBar();
  45.    //ToolBar buttons
  46.    JButton ADD = new JButton(new ImageIcon("addicon.jpeg"));
  47.    JButton DELETE = new JButton(new ImageIcon("deleteicon.png"));
  48.    JButton SAVE = new JButton(new ImageIcon("Save.jpeg"));
  49.    JButton PRINT = new JButton(new ImageIcon("printicon.png"));
  50.    JButton EMAIL = new JButton(new ImageIcon("email.jpeg"));
  51.    JButton RECIEPT = new JButton(new ImageIcon(""));
  52.   // Declaring Dialogs
  53.    JDialog ADD_NEW = new JDialog();
  54.   //ADD_NEW COMPONENTS
  55.    //Labels
  56.    JLabel Name_of_prod = new JLabel("Product Name");
  57.    JLabel NoP = new JLabel("Number of Products");
  58.    JLabel CostP = new JLabel("Cost Price");
  59.    JLabel SellP = new JLabel("Selling Price");
  60.    JLabel Dets = new JLabel("Details");
  61.    //Textfields
  62.    JTextField Name_Field = new JTextField(25);
  63.    JTextField No_Field = new JTextField(10);
  64.    JTextField Cost_price = new JTextField(10);
  65.    JTextField Selling_price = new JTextField(10);
  66.    JTextField Details = new JTextField(25);
  67.    //Buttons
  68.    JButton Register_prod = new JButton("Register");
  69.    JButton Cancel_reg = new JButton("Cancel");
  70.    //Extras and toolkits.
  71.    Toolkit MM_PRO_toolkit = getToolkit();
  72.    Dimension Size = new Dimension();  
  73.    //Button Listener
  74.    GridBagLayout gb = new GridBagLayout();
  75.    GridBagConstraints gbc = new GridBagConstraints();
  76.    //JOptionpane Items for testing Dialogs with optionpanes
  77.    JOptionPane optionpane = new JOptionPane("Testing", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
  78.    final JDesktopPane desk = new JDesktopPane();
  79.    //Class to hold all Regitration Items
  80. public class Registration{
  81.       String Name_of_Product;
  82.       int Number_of_Products;
  83.       float Cost;
  84.       float newprice;
  85.       String Details;
  86.     }
  87. int Registration_Counter=0;
  88.  //Registration Array
  89.  Registration[] REGISTRATION_DATA = new Registration[2000];
  90.  //Class to hold SellDetails
  91.  public class Sells{
  92.      String Name_of_Customer;
  93.      int Number_of_Items;
  94.      //Include time of purchase
  95.      //Include Date of purchase
  96.      float Amount_payable;
  97.      float Amount_paid;
  98.      float Balance;
  99.  }
  100.  /*Constructor method for MYMANAGERPRO.*/
  101.     public MYMANAGERPRO(){
  102.     setTitle("MY MANAGER PRO");
  103.     Size = MM_PRO_toolkit.getScreenSize();
  104.     //Using Size of computer screen to create window
  105.     setSize(Size.width-getWidth(),Size.height-getHeight());
  106.     //Adding Main Panel to Window.
  107.     getContentPane().add(All_Content_Pane);
  108.     All_Content_Pane.setLayout(new FlowLayout(FlowLayout.LEFT));
  109.     //Adding file items
  110.     File.add(Add_New_Products);
  111.     File.add(Check_Current_Products);
  112.     File.add(Save_to_Database);
  113.     File.add(Close);
  114.     //Adding Report Items
  115.     Reports.add(Daily_reports);
  116.     Reports.add(Weekly_reports);
  117.     Reports.add(Monthly_reports);
  118.     //Adding check products items
  119.     Check_products.add(Add_New_Products);
  120.     Check_products.add(Delete_product);
  121.     Check_products.add(Change_product_name);
  122.     Check_products.add(Change_product_price);
  123.     Check_products.add(Check_Current_Products);
  124.     Check_products.add(Change_all_details);
  125.     //Adding help items
  126.     Help.add(help);
  127.  
  128.   /*Adding toolbar and components */
  129.     Tool_Bar.add(ADD);
  130.     Tool_Bar.add(DELETE);
  131.     Tool_Bar.add(SAVE);
  132.     Tool_Bar.add(PRINT);
  133.     Tool_Bar.add(EMAIL);
  134.     Tool_Bar.add(RECIEPT);
  135.   /* Previously controlled lenght in Jpanel, difficult!  Tool_Bar.setPreferredSize(new Dimension(1340,50)); */
  136.  //Adding toolbar directly into JFrame.
  137.     add(Tool_Bar, BorderLayout.NORTH);
  138.      
  139.  /*Adding all orther  Components hierichically to panel */
  140.  /*Previosly include  "All_Menu_Items.setPreferredSize(new Dimension(Size.width+670-getWidth()+670,25));"
  141.   *Because I wanted to manage the size of menubar to take screen size but using Jpanel. but when its
  142.    added directly into the the aligments are done automatically.
  143.  */  
  144.     All_Menu_Items.add(File);
  145.     All_Menu_Items.add(Check_products);
  146.     All_Menu_Items.add(Reports);
  147.     All_Menu_Items.add(Help);    
  148.  //The Menu Bar Is not added to the Content pane(Jpanel)
  149.     setJMenuBar(All_Menu_Items);  
  150.     All_Content_Pane.add(Tool_Bar);
  151.    
  152.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  153.     setVisible(true);
  154.     Popups();
  155.     Listeners();
  156.  
  157.     }
  158.     private void Popups(){
  159.       //Registration Popup.
  160.       //ADD_NEW= optionpane.createDialog(desk,"MAN NA MAN"); //Trying to test Dialog with optionpane.
  161.         ADD_NEW.setTitle("Register Products");
  162.         ADD_NEW.setLocation(Size.width/2-getWidth()/2,Size.height/2-getHeight()/2);
  163.         ADD_NEW.setLayout(new GridBagLayout());
  164.        //Settings for GridBagConstraints
  165.         gbc.gridx=0;
  166.         gbc.gridy=0;
  167.         gbc.anchor=GridBagConstraints.LINE_START;
  168.         //Adding Labels first.
  169.         ADD_NEW.add(Name_of_prod, gbc);
  170.         gbc.gridy++;
  171.         ADD_NEW.add(NoP, gbc);
  172.         gbc.gridy++;
  173.         ADD_NEW.add(CostP, gbc);
  174.         gbc.gridy++;
  175.         ADD_NEW.add(SellP, gbc);
  176.         gbc.gridy++;
  177.         ADD_NEW.add(Dets, gbc);
  178.         gbc.gridy++;
  179.        //Adding Fields
  180.         gbc.gridy=0; gbc.gridx=1;
  181.         ADD_NEW.add(Name_Field, gbc);
  182.         gbc.gridy++;
  183.         ADD_NEW.add(No_Field, gbc);
  184.         gbc.gridy++;
  185.         ADD_NEW.add(Cost_price, gbc);
  186.         gbc.gridy++;
  187.         ADD_NEW.add(Selling_price, gbc);
  188.         gbc.gridy++;
  189.         ADD_NEW.add(Details, gbc);
  190.         gbc.gridy++;
  191.         //Buttons or Reg. Page.
  192.         gbc.gridx=0;
  193.         ADD_NEW.add(Register_prod, gbc);
  194.         gbc.gridx=1;
  195.         ADD_NEW.add(Cancel_reg, gbc);
  196.         //Packing Dialog
  197.        ADD_NEW.setSize(450,175);
  198.         //Making Registration class an array
  199.  
  200.        
  201.     }
  202.  
  203.     private void Listeners(){
  204.        //I commented this piece of code out(Listener) to get it work for 2 Buttons.
  205.        /* Add_New_Products.addActionListener(new ActionListener() {
  206.             public void actionPerformed(ActionEvent Registration){
  207.              ADD_NEW.setVisible(true);
  208.              
  209.             }
  210.         }); */
  211.         //Creating Listener for addicon button and add_new_products in check products menu.
  212.         ActionListener FOR_NEW_PRODUCTS = new ActionListener(){
  213.             public void actionPerformed(ActionEvent e){
  214.                 ADD_NEW.setVisible(true);
  215.             }
  216.         };
  217.         Add_New_Products.addActionListener(FOR_NEW_PRODUCTS);
  218.         ADD.addActionListener(FOR_NEW_PRODUCTS);
  219.         //Setting Action for Registration Button on Registration Dialog.
  220.         Register_prod.addActionListener(new ActionListener(){
  221.             public void actionPerformed(ActionEvent e){
  222.         //Getting Inputs from Dialog
  223.               REGISTRATION_DATA[Registration_Counter].Number_of_Products=
  224.                      Integer.parseInt(No_Field.getText());
  225.               ADD_NEW.setVisible(false);  
  226.             }    
  227.         });
  228.     }
  229.  
  230.      public static void main(String[] args) {
  231.         // TODO code application logic here.
  232.        new MYMANAGERPRO();
  233.      
  234.      }
  235.    
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement