Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package UILayer;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import ControllLayer.*;
- public class GUI extends JFrame{
- public static void main(String[] args) {
- new GUI();
- }
- public GUI(){
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setSize(640, 480);
- this.setLocationRelativeTo(null);
- JTabbedPane tabs = new JTabbedPane(SwingConstants.NORTH);
- tabs.add("Customers",customersPage());
- tabs.add("Stock", stockPage());
- tabs.add("Supplier", supplierPage());
- tabs.add("Employees", employeePage());
- getContentPane().add(tabs);
- this.setVisible(true);
- }
- private JPanel customersPage(){
- JPanel customerPanel = new JPanel();
- customerPanel.setLayout(new GridBagLayout());
- JButton button = new JButton("YES MA'FAKA'");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- addComp(customerPanel, button, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- return customerPanel;
- }
- private JPanel stockPage(){
- JPanel stockPanel = new JPanel();
- stockPanel.setLayout(new GridBagLayout());
- JScrollPane scrollPane = new JScrollPane();
- GridBagConstraints gbc_scrollPane = new GridBagConstraints();
- gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
- JTable table = new JTable();
- String[] columnNames = {"First Name",
- "Last Name",
- "Sport",
- "# of Years",
- "Vegetarian"};
- Object[][] data = {
- {"Kathy", "Smith",
- "Snowboarding", new Integer(5), new Boolean(false)},
- {"John", "Doe",
- "Rowing", new Integer(3), new Boolean(true)},
- {"Sue", "Black",
- "Knitting", new Integer(2), new Boolean(false)},
- {"Jane", "White",
- "Speed reading", new Integer(20), new Boolean(true)},
- {"Joe", "Brown",
- "Pool", new Integer(10), new Boolean(false)}
- };
- table = new JTable(data, columnNames);
- scrollPane.setViewportView(table);
- addComp(stockPanel, scrollPane, 0,0,0,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- return stockPanel;
- }
- private JPanel supplierPage(){
- JPanel stockPanel = new JPanel();
- stockPanel.setLayout(new GridBagLayout());
- JLabel name= new JLabel("Name:");
- addComp(stockPanel, name, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textName = new JTextField();
- addComp(stockPanel, textName, 1,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel telephone= new JLabel("Telephone:");
- addComp(stockPanel, telephone, 0,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textphone = new JTextField();
- addComp(stockPanel, textphone, 1,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel email= new JLabel("Email:");
- addComp(stockPanel, email, 0,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textMail = new JTextField();
- addComp(stockPanel, textMail, 1,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel webSite= new JLabel("WEB site:");
- addComp(stockPanel, webSite, 0,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textWeb = new JTextField();
- addComp(stockPanel, textWeb, 1,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel address= new JLabel("Address:");
- addComp(stockPanel, address, 0,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textCountry = new JTextField();
- addComp(stockPanel, textCountry, 1,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JTextField textZip = new JTextField();
- addComp(stockPanel, textZip, 1,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JTextField textAddress = new JTextField();
- addComp(stockPanel, textAddress, 1,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- if(SupplierController.getInstance().getSupplier()!=null){
- textName.setText(SupplierController.getInstance().getSupplier().getName());
- textMail.setText(SupplierController.getInstance().getSupplier().getEmail());
- textWeb.setText(SupplierController.getInstance().getSupplier().getWebsite());
- textCountry.setText(SupplierController.getInstance().getSupplier().getCountry());
- textAddress.setText(SupplierController.getInstance().getSupplier().getStreet());
- textphone.setText(SupplierController.getInstance().getSupplier().getPhone());
- textZip.setText(SupplierController.getInstance().getSupplier().getZip());
- }
- JButton btnSave = new JButton("Save");
- addComp(stockPanel, btnSave, 0,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- btnSave.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String name=textName.getText();
- String mail=textMail.getText();
- String Web=textWeb.getText();
- String country=textCountry.getText();
- String address=textAddress.getText();
- int phone;
- int zip;
- try{
- phone=Integer.parseInt(textphone.getText());
- try{
- zip=Integer.parseInt(textZip.getText());
- SupplierController.getInstance().setSupplier(name,phone,mail,Web,country,zip,address);
- }
- catch(Exception e1){
- System.out.println("Enter numbers in zip field!");
- };
- }
- catch(Exception e0){
- System.out.println("Enter numbers in phone nr. field!");
- };
- }
- });
- return stockPanel;
- }
- private JPanel employeePage(){
- JPanel stockPanel = new JPanel();
- stockPanel.setLayout(new GridBagLayout());
- String[] selected={"Andrei","Ralfs","Stoicho","New"};
- JComboBox person = new JComboBox(selected);
- addComp(stockPanel, person, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JButton btnRemove = new JButton("remove");
- addComp(stockPanel, btnRemove, 1,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JLabel name= new JLabel("Name:");
- addComp(stockPanel, name, 0,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textName = new JTextField("Andrei");
- addComp(stockPanel, textName, 1,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel telephone= new JLabel("Telephone:");
- addComp(stockPanel, telephone, 0,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textphone = new JTextField("Maika ty");
- addComp(stockPanel, textphone, 1,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel email= new JLabel("Email:");
- addComp(stockPanel, email, 0,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textMail = new JTextField("me@da.com");
- addComp(stockPanel, textMail, 1,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel webSite= new JLabel("WEB site:");
- addComp(stockPanel, webSite, 0,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textWeb = new JTextField("null");
- addComp(stockPanel, textWeb, 1,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JLabel address= new JLabel("Address:");
- addComp(stockPanel, address, 0,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- JTextField textCountry = new JTextField("Denmark");
- addComp(stockPanel, textCountry, 1,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JTextField textZip = new JTextField("morcu picu");
- addComp(stockPanel, textZip, 1,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JTextField textAddress = new JTextField("gumba 12");
- addComp(stockPanel, textAddress, 1,7,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- JButton btnSave = new JButton("Save");
- addComp(stockPanel, btnSave, 0,7,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
- person.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent e) {
- if(person.getSelectedItem().toString().equals("New")){
- textName.setText("");
- textphone.setText("");
- textMail.setText("");
- textWeb.setText("");
- textCountry.setText("");
- textZip.setText("");
- textAddress.setText("");
- }
- else{
- textName.setText("Andrei");
- textphone.setText("Maika ty");
- textMail.setText("me@da.com");
- textWeb.setText("null");
- textCountry.setText("Denmark");
- textZip.setText("morcu picu");
- textAddress.setText("gumba 12");
- }
- }
- });
- return stockPanel;
- }
- private void addComp(JPanel thePanel, JComponent comp, int xPos, int yPos, int compWidth, int compHeight, int place, int stretch){
- GridBagConstraints gridConstraints = new GridBagConstraints();
- gridConstraints.gridx = xPos;
- gridConstraints.gridy = yPos;
- gridConstraints.gridwidth = compWidth;
- gridConstraints.gridheight = compHeight;
- gridConstraints.weightx = 100;
- gridConstraints.weighty = 100;
- gridConstraints.insets = new Insets(5,5,5,5);
- gridConstraints.anchor = place;
- gridConstraints.fill = stretch;
- thePanel.add(comp, gridConstraints);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement