Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Note button for check gain should be added.
- //In database each good should have it own table.
- //The check gain, loss,sales etc will appear in toolbar
- /**
- * @about MM-Pro Manage Small enterprises.
- * @author F.E. Noel Nfebe.
- * @version 1.0
- */
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.event.ActionEvent; //The following are event controllers
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.Dimension; //For things like Dimesions from getScreenSize toolkit.
- import java.awt.Toolkit; //For Issues like getings beeps screensize etc.
- import javax.swing.border.EtchedBorder;
- public class MYMANAGERPRO extends JFrame {
- JPanel All_Content_Pane = new JPanel();
- JMenuBar All_Menu_Items = new JMenuBar();
- /*Menu list */
- JMenu File = new JMenu("FILE");
- JMenu Check_products = new JMenu("CHECK PRODUCTS");
- JMenu Reports = new JMenu("REPORTS");
- JMenu Help = new JMenu("HELP");
- /*MenuItems for File */
- JMenuItem Save_to_Database = new JMenuItem("Save to Database");
- JMenuItem Close = new JMenuItem("Close");
- /*MenuItems for Reports*/
- JMenuItem Daily_reports = new JMenuItem("View Daily Rep...");
- JMenuItem Weekly_reports = new JMenuItem("View Weekly Rep...");
- JMenuItem Monthly_reports = new JMenuItem("View Monthly Rep...");
- /*MenuItem for Check Products */
- JMenuItem Add_New_Products = new JMenuItem("Add new product(s)");
- JMenuItem Delete_product = new JMenuItem("Delete product");
- JMenuItem Change_product_name = new JMenuItem("Change product name");
- JMenuItem Change_product_price = new JMenuItem("Change product price");
- JMenuItem Check_Current_Products = new JMenuItem("Check current product(s)");
- JMenuItem Change_all_details = new JMenuItem("Change all details");
- /*MenutItems for Help*/
- JMenuItem help = new JMenuItem("Help");
- JToolBar Tool_Bar =new JToolBar();
- //ToolBar buttons
- JButton ADD = new JButton(new ImageIcon("addicon.jpeg"));
- JButton DELETE = new JButton(new ImageIcon("deleteicon.png"));
- JButton SAVE = new JButton(new ImageIcon("Save.jpeg"));
- JButton PRINT = new JButton(new ImageIcon("printicon.png"));
- JButton EMAIL = new JButton(new ImageIcon("email.jpeg"));
- JButton RECIEPT = new JButton(new ImageIcon(""));
- // Declaring Dialogs
- JDialog ADD_NEW = new JDialog();
- //ADD_NEW COMPONENTS
- //Labels
- JLabel Name_of_prod = new JLabel("Product Name");
- JLabel NoP = new JLabel("Number of Products");
- JLabel CostP = new JLabel("Cost Price");
- JLabel SellP = new JLabel("Selling Price");
- JLabel Dets = new JLabel("Details");
- //Textfields
- JTextField Name_Field = new JTextField(25);
- JTextField No_Field = new JTextField(10);
- JTextField Cost_price = new JTextField(10);
- JTextField Selling_price = new JTextField(10);
- JTextField Details = new JTextField(25);
- //Buttons
- JButton Register_prod = new JButton("Register");
- JButton Cancel_reg = new JButton("Cancel");
- //Extras and toolkits.
- Toolkit MM_PRO_toolkit = getToolkit();
- Dimension Size = new Dimension();
- //Button Listener
- GridBagLayout gb = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- //JOptionpane Items for testing Dialogs with optionpanes
- JOptionPane optionpane = new JOptionPane("Testing", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
- final JDesktopPane desk = new JDesktopPane();
- //Class to hold all Regitration Items
- public class Registration{
- String Name_of_Product;
- int Number_of_Products;
- float Cost;
- float newprice;
- String Details;
- }
- int Registration_Counter=0;
- //Registration Array
- Registration[] REGISTRATION_DATA = new Registration[2000];
- //Class to hold SellDetails
- public class Sells{
- String Name_of_Customer;
- int Number_of_Items;
- //Include time of purchase
- //Include Date of purchase
- float Amount_payable;
- float Amount_paid;
- float Balance;
- }
- /*Constructor method for MYMANAGERPRO.*/
- public MYMANAGERPRO(){
- setTitle("MY MANAGER PRO");
- Size = MM_PRO_toolkit.getScreenSize();
- //Using Size of computer screen to create window
- setSize(Size.width-getWidth(),Size.height-getHeight());
- //Adding Main Panel to Window.
- getContentPane().add(All_Content_Pane);
- All_Content_Pane.setLayout(new FlowLayout(FlowLayout.LEFT));
- //Adding file items
- File.add(Add_New_Products);
- File.add(Check_Current_Products);
- File.add(Save_to_Database);
- File.add(Close);
- //Adding Report Items
- Reports.add(Daily_reports);
- Reports.add(Weekly_reports);
- Reports.add(Monthly_reports);
- //Adding check products items
- Check_products.add(Add_New_Products);
- Check_products.add(Delete_product);
- Check_products.add(Change_product_name);
- Check_products.add(Change_product_price);
- Check_products.add(Check_Current_Products);
- Check_products.add(Change_all_details);
- //Adding help items
- Help.add(help);
- /*Adding toolbar and components */
- Tool_Bar.add(ADD);
- Tool_Bar.add(DELETE);
- Tool_Bar.add(SAVE);
- Tool_Bar.add(PRINT);
- Tool_Bar.add(EMAIL);
- Tool_Bar.add(RECIEPT);
- /* Previously controlled lenght in Jpanel, difficult! Tool_Bar.setPreferredSize(new Dimension(1340,50)); */
- //Adding toolbar directly into JFrame.
- add(Tool_Bar, BorderLayout.NORTH);
- /*Adding all orther Components hierichically to panel */
- /*Previosly include "All_Menu_Items.setPreferredSize(new Dimension(Size.width+670-getWidth()+670,25));"
- *Because I wanted to manage the size of menubar to take screen size but using Jpanel. but when its
- added directly into the the aligments are done automatically.
- */
- All_Menu_Items.add(File);
- All_Menu_Items.add(Check_products);
- All_Menu_Items.add(Reports);
- All_Menu_Items.add(Help);
- //The Menu Bar Is not added to the Content pane(Jpanel)
- setJMenuBar(All_Menu_Items);
- All_Content_Pane.add(Tool_Bar);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- Popups();
- Listeners();
- }
- private void Popups(){
- //Registration Popup.
- //ADD_NEW= optionpane.createDialog(desk,"MAN NA MAN"); //Trying to test Dialog with optionpane.
- ADD_NEW.setTitle("Register Products");
- ADD_NEW.setLocation(Size.width/2-getWidth()/2,Size.height/2-getHeight()/2);
- ADD_NEW.setLayout(new GridBagLayout());
- //Settings for GridBagConstraints
- gbc.gridx=0;
- gbc.gridy=0;
- gbc.anchor=GridBagConstraints.LINE_START;
- //Adding Labels first.
- ADD_NEW.add(Name_of_prod, gbc);
- gbc.gridy++;
- ADD_NEW.add(NoP, gbc);
- gbc.gridy++;
- ADD_NEW.add(CostP, gbc);
- gbc.gridy++;
- ADD_NEW.add(SellP, gbc);
- gbc.gridy++;
- ADD_NEW.add(Dets, gbc);
- gbc.gridy++;
- //Adding Fields
- gbc.gridy=0; gbc.gridx=1;
- ADD_NEW.add(Name_Field, gbc);
- gbc.gridy++;
- ADD_NEW.add(No_Field, gbc);
- gbc.gridy++;
- ADD_NEW.add(Cost_price, gbc);
- gbc.gridy++;
- ADD_NEW.add(Selling_price, gbc);
- gbc.gridy++;
- ADD_NEW.add(Details, gbc);
- gbc.gridy++;
- //Buttons or Reg. Page.
- gbc.gridx=0;
- ADD_NEW.add(Register_prod, gbc);
- gbc.gridx=1;
- ADD_NEW.add(Cancel_reg, gbc);
- //Packing Dialog
- ADD_NEW.setSize(450,175);
- //Making Registration class an array
- }
- private void Listeners(){
- //I commented this piece of code out(Listener) to get it work for 2 Buttons.
- /* Add_New_Products.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent Registration){
- ADD_NEW.setVisible(true);
- }
- }); */
- //Creating Listener for addicon button and add_new_products in check products menu.
- ActionListener FOR_NEW_PRODUCTS = new ActionListener(){
- public void actionPerformed(ActionEvent e){
- ADD_NEW.setVisible(true);
- }
- };
- Add_New_Products.addActionListener(FOR_NEW_PRODUCTS);
- ADD.addActionListener(FOR_NEW_PRODUCTS);
- //Setting Action for Registration Button on Registration Dialog.
- Register_prod.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- //Getting Inputs from Dialog
- REGISTRATION_DATA[Registration_Counter].Number_of_Products=
- Integer.parseInt(No_Field.getText());
- ADD_NEW.setVisible(false);
- }
- });
- }
- public static void main(String[] args) {
- // TODO code application logic here.
- new MYMANAGERPRO();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement