Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1. package UILayer;
  2.  
  3. import javax.swing.*;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import ControllLayer.*;
  10.  
  11. public class GUI extends JFrame{
  12. public static void main(String[] args) {
  13. new GUI();
  14. }
  15.  
  16. public GUI(){
  17. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18. this.setSize(640, 480);
  19. this.setLocationRelativeTo(null);
  20.  
  21. JTabbedPane tabs = new JTabbedPane(SwingConstants.NORTH);
  22. tabs.add("Customers",customersPage());
  23. tabs.add("Stock", stockPage());
  24. tabs.add("Supplier", supplierPage());
  25. tabs.add("Employees", employeePage());
  26.  
  27. getContentPane().add(tabs);
  28. this.setVisible(true);
  29.  
  30. }
  31.  
  32. private JPanel customersPage(){
  33. JPanel customerPanel = new JPanel();
  34. customerPanel.setLayout(new GridBagLayout());
  35. JButton button = new JButton("YES MA'FAKA'");
  36. button.addActionListener(new ActionListener() {
  37. public void actionPerformed(ActionEvent e) {
  38. }
  39. });
  40. addComp(customerPanel, button, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  41.  
  42. return customerPanel;
  43. }
  44.  
  45. private JPanel stockPage(){
  46. JPanel stockPanel = new JPanel();
  47. stockPanel.setLayout(new GridBagLayout());
  48.  
  49. JScrollPane scrollPane = new JScrollPane();
  50. GridBagConstraints gbc_scrollPane = new GridBagConstraints();
  51. gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
  52. JTable table = new JTable();
  53. String[] columnNames = {"First Name",
  54. "Last Name",
  55. "Sport",
  56. "# of Years",
  57. "Vegetarian"};
  58. Object[][] data = {
  59. {"Kathy", "Smith",
  60. "Snowboarding", new Integer(5), new Boolean(false)},
  61. {"John", "Doe",
  62. "Rowing", new Integer(3), new Boolean(true)},
  63. {"Sue", "Black",
  64. "Knitting", new Integer(2), new Boolean(false)},
  65. {"Jane", "White",
  66. "Speed reading", new Integer(20), new Boolean(true)},
  67. {"Joe", "Brown",
  68. "Pool", new Integer(10), new Boolean(false)}
  69. };
  70. table = new JTable(data, columnNames);
  71. scrollPane.setViewportView(table);
  72. addComp(stockPanel, scrollPane, 0,0,0,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  73.  
  74. return stockPanel;
  75. }
  76.  
  77. private JPanel supplierPage(){
  78. JPanel stockPanel = new JPanel();
  79. stockPanel.setLayout(new GridBagLayout());
  80.  
  81. JLabel name= new JLabel("Name:");
  82. addComp(stockPanel, name, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  83. JTextField textName = new JTextField();
  84. addComp(stockPanel, textName, 1,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  85.  
  86. JLabel telephone= new JLabel("Telephone:");
  87. addComp(stockPanel, telephone, 0,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  88. JTextField textphone = new JTextField();
  89. addComp(stockPanel, textphone, 1,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  90.  
  91. JLabel email= new JLabel("Email:");
  92. addComp(stockPanel, email, 0,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  93. JTextField textMail = new JTextField();
  94. addComp(stockPanel, textMail, 1,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  95.  
  96. JLabel webSite= new JLabel("WEB site:");
  97. addComp(stockPanel, webSite, 0,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  98. JTextField textWeb = new JTextField();
  99. addComp(stockPanel, textWeb, 1,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  100.  
  101. JLabel address= new JLabel("Address:");
  102. addComp(stockPanel, address, 0,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  103. JTextField textCountry = new JTextField();
  104. addComp(stockPanel, textCountry, 1,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  105. JTextField textZip = new JTextField();
  106. addComp(stockPanel, textZip, 1,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  107. JTextField textAddress = new JTextField();
  108. addComp(stockPanel, textAddress, 1,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  109.  
  110. if(SupplierController.getInstance().getSupplier()!=null){
  111. textName.setText(SupplierController.getInstance().getSupplier().getName());
  112. textMail.setText(SupplierController.getInstance().getSupplier().getEmail());
  113. textWeb.setText(SupplierController.getInstance().getSupplier().getWebsite());
  114. textCountry.setText(SupplierController.getInstance().getSupplier().getCountry());
  115. textAddress.setText(SupplierController.getInstance().getSupplier().getStreet());
  116. textphone.setText(SupplierController.getInstance().getSupplier().getPhone());
  117. textZip.setText(SupplierController.getInstance().getSupplier().getZip());
  118. }
  119.  
  120. JButton btnSave = new JButton("Save");
  121. addComp(stockPanel, btnSave, 0,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  122. btnSave.addActionListener(new ActionListener() {
  123. public void actionPerformed(ActionEvent e) {
  124. String name=textName.getText();
  125. String mail=textMail.getText();
  126. String Web=textWeb.getText();
  127. String country=textCountry.getText();
  128. String address=textAddress.getText();
  129. int phone;
  130. int zip;
  131. try{
  132. phone=Integer.parseInt(textphone.getText());
  133. try{
  134. zip=Integer.parseInt(textZip.getText());
  135. SupplierController.getInstance().setSupplier(name,phone,mail,Web,country,zip,address);
  136. }
  137. catch(Exception e1){
  138. System.out.println("Enter numbers in zip field!");
  139. };
  140. }
  141. catch(Exception e0){
  142. System.out.println("Enter numbers in phone nr. field!");
  143. };
  144. }
  145. });
  146.  
  147. return stockPanel;
  148.  
  149. }
  150.  
  151. private JPanel employeePage(){
  152. JPanel stockPanel = new JPanel();
  153. stockPanel.setLayout(new GridBagLayout());
  154.  
  155. String[] selected={"Andrei","Ralfs","Stoicho","New"};
  156. JComboBox person = new JComboBox(selected);
  157. addComp(stockPanel, person, 0,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  158.  
  159. JButton btnRemove = new JButton("remove");
  160. addComp(stockPanel, btnRemove, 1,0,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  161.  
  162. JLabel name= new JLabel("Name:");
  163. addComp(stockPanel, name, 0,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  164. JTextField textName = new JTextField("Andrei");
  165. addComp(stockPanel, textName, 1,1,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  166.  
  167. JLabel telephone= new JLabel("Telephone:");
  168. addComp(stockPanel, telephone, 0,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  169. JTextField textphone = new JTextField("Maika ty");
  170. addComp(stockPanel, textphone, 1,2,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  171.  
  172. JLabel email= new JLabel("Email:");
  173. addComp(stockPanel, email, 0,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  174. JTextField textMail = new JTextField("me@da.com");
  175. addComp(stockPanel, textMail, 1,3,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  176.  
  177. JLabel webSite= new JLabel("WEB site:");
  178. addComp(stockPanel, webSite, 0,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  179. JTextField textWeb = new JTextField("null");
  180. addComp(stockPanel, textWeb, 1,4,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  181.  
  182. JLabel address= new JLabel("Address:");
  183. addComp(stockPanel, address, 0,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  184. JTextField textCountry = new JTextField("Denmark");
  185. addComp(stockPanel, textCountry, 1,5,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  186. JTextField textZip = new JTextField("morcu picu");
  187. addComp(stockPanel, textZip, 1,6,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  188. JTextField textAddress = new JTextField("gumba 12");
  189. addComp(stockPanel, textAddress, 1,7,1,1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
  190.  
  191. JButton btnSave = new JButton("Save");
  192. addComp(stockPanel, btnSave, 0,7,1,1, GridBagConstraints.CENTER, GridBagConstraints.NONE);
  193.  
  194. person.addActionListener (new ActionListener () {
  195. public void actionPerformed(ActionEvent e) {
  196. if(person.getSelectedItem().toString().equals("New")){
  197. textName.setText("");
  198. textphone.setText("");
  199. textMail.setText("");
  200. textWeb.setText("");
  201. textCountry.setText("");
  202. textZip.setText("");
  203. textAddress.setText("");
  204. }
  205. else{
  206. textName.setText("Andrei");
  207. textphone.setText("Maika ty");
  208. textMail.setText("me@da.com");
  209. textWeb.setText("null");
  210. textCountry.setText("Denmark");
  211. textZip.setText("morcu picu");
  212. textAddress.setText("gumba 12");
  213. }
  214. }
  215. });
  216.  
  217. return stockPanel;
  218.  
  219. }
  220.  
  221.  
  222. private void addComp(JPanel thePanel, JComponent comp, int xPos, int yPos, int compWidth, int compHeight, int place, int stretch){
  223. GridBagConstraints gridConstraints = new GridBagConstraints();
  224. gridConstraints.gridx = xPos;
  225. gridConstraints.gridy = yPos;
  226. gridConstraints.gridwidth = compWidth;
  227. gridConstraints.gridheight = compHeight;
  228. gridConstraints.weightx = 100;
  229. gridConstraints.weighty = 100;
  230. gridConstraints.insets = new Insets(5,5,5,5);
  231. gridConstraints.anchor = place;
  232. gridConstraints.fill = stretch;
  233. thePanel.add(comp, gridConstraints);
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement