Advertisement
RnD

Untitled

RnD
Mar 22nd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.04 KB | None | 0 0
  1. package StudyPlanner;
  2.  
  3.  
  4. import java.awt.BorderLayout;
  5. import java.awt.Color;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.awt.image.BufferedImage;
  9. import java.io.File;
  10. import java.io.IOException;
  11.  
  12. import javax.imageio.ImageIO;
  13. import javax.swing.BorderFactory;
  14. import javax.swing.BoxLayout;
  15. import javax.swing.Icon;
  16. import javax.swing.ImageIcon;
  17. import javax.swing.JButton;
  18. import javax.swing.JFrame;
  19. import javax.swing.JLabel;
  20. import javax.swing.JPanel;
  21. import javax.swing.JTextField;
  22. import javax.swing.SwingConstants;
  23.  
  24. /**
  25.  *
  26.  * @author hgm14nau
  27.  */
  28.  
  29. // class
  30. //cd desktop , cd project2
  31. //git status
  32.  
  33. //git add studyplanner/src (updates)
  34. //git commit -m 'Description'
  35. //git push -u origin master
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. public class ModuleView extends JFrame{
  43.    
  44.  
  45. private BufferedImage image;
  46.  
  47.     public ModuleView(){
  48.        
  49.        
  50.  
  51.         this.setVisible(true);
  52.         this.setLocationRelativeTo(null);
  53.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  54.        
  55. /*
  56.  * Images
  57.  */
  58.         /*
  59.          * Adding JButtons
  60.          */
  61.         JButton home = new JButton();
  62.         JButton select = new JButton();
  63.         JButton modules = new JButton();
  64.         JButton milestones = new JButton();
  65.         JButton notes = new JButton();
  66.        
  67.         /*
  68.          * Importing images from the "images" folder
  69.          */
  70.        
  71.         ImageIcon homeButton = new ImageIcon("src/images/home.png");
  72.         ImageIcon selectButton = new ImageIcon("src/images/select.png");
  73.         ImageIcon moduleButton = new ImageIcon("src/images/modules.png");
  74.         ImageIcon milestoneButton = new ImageIcon("src/images/milestones.png");
  75.         ImageIcon noteButton = new ImageIcon("src/images/notes.png");
  76.        
  77.         /*
  78.          * Setting html-styled 'hover text' for when the users mouse is hovered over
  79.          * the respective JButtons
  80.          */
  81.        
  82.         home.setToolTipText("<html>Home Button<br>Navigates to home</html>");
  83.         modules.setToolTipText("<html>Module Button<br>Navigates to Module</html>");
  84.         milestones.setToolTipText("<html>Milestone Button<br>Navigates to Milestone</html>");
  85.         notes.setToolTipText("<html>Note Button<br>Navigates to Note</html>");
  86.        
  87.         /*
  88.          * Assigning the imported images to the JButtons
  89.          */
  90.         home.setIcon(homeButton);
  91.         select.setIcon(selectButton);
  92.         modules.setIcon(moduleButton);
  93.         milestones.setIcon(milestoneButton);
  94.         notes.setIcon(noteButton);
  95.        
  96.         /*
  97.          * Setting image border to null to enhance the aesthetic design
  98.          */
  99.        
  100.         home.setBorder(null);
  101.         select.setBorder(null);
  102.         modules.setBorder(null);
  103.         milestones.setBorder(null);
  104.         notes.setBorder(null);
  105.              
  106.         home.setContentAreaFilled(false);
  107.        
  108.         /*
  109.          * End of image related code
  110.          */
  111.        
  112.        
  113.         /*
  114.          * The following code contains JPanel containers
  115.          */
  116.        
  117.         //main container to store our panels
  118.         JPanel mainContainer = new JPanel();
  119.         mainContainer.setLayout(new BoxLayout(mainContainer,BoxLayout.Y_AXIS));
  120.        
  121.         //we need this panel because the header and body should be stored in different
  122.         //panels. Where header should cover all of body's top area
  123.         // And where body is going to have two elements within with Y axis layout
  124.         JPanel headerAndBody = new JPanel();
  125.         headerAndBody.setLayout(new BoxLayout(headerAndBody,BoxLayout.Y_AXIS));
  126.    
  127.         mainContainer.add(headerAndBody);
  128.        
  129.         //Every icon in the header goes into headerIcons JPanel
  130.         JPanel headerIcons = new JPanel();
  131.         headerIcons.setLayout(new BoxLayout(headerIcons,BoxLayout.X_AXIS));
  132.         headerIcons.setPreferredSize(new Dimension(600,40));
  133.         headerIcons.setMaximumSize(new Dimension(1600, 40));
  134.        
  135.         //Headers to be put into headerIcons
  136.         JPanel header = new JPanel();
  137.         JPanel header2 = new JPanel();
  138.         JPanel header3 = new JPanel();
  139.         JPanel header4 = new JPanel();
  140.        // JPanel header5 = new JPanel();
  141.        
  142.         //footer
  143.         JPanel footer = new JPanel();
  144.        
  145.    
  146.  
  147.         //Image check.
  148.         File imageCheck = new File("src/images/modules.png");
  149.  
  150.         if(imageCheck.exists())
  151.             System.out.println("Image file found!");
  152.         else
  153.             System.out.println("Image file not found!");
  154.        
  155.         //end of image check
  156.        
  157.        
  158.         //header 1
  159.         header.setPreferredSize(new Dimension(50,40));
  160.         header.setBackground(Color.BLACK);
  161.         header.setMaximumSize(new Dimension(1600, 40));
  162.    
  163.         header.add(home);
  164.         headerIcons.add(header);
  165.        
  166.        
  167.         //header 2
  168.         header2.setPreferredSize(new Dimension(50,40));
  169.         header2.setBackground(Color.BLACK);
  170.         header2.setMaximumSize(new Dimension(1600, 40));
  171.        
  172.         header2.add(modules);
  173.         headerIcons.add(header2);
  174.        
  175.         //header 3
  176.         header3.setPreferredSize(new Dimension(50,40));
  177.         header3.setBackground(Color.BLACK);
  178.         header3.setMaximumSize(new Dimension(1600, 40));
  179.        
  180.         header3.add(milestones);
  181.         headerIcons.add(header3);
  182.        
  183.        
  184.         //header 4
  185.         header4.setPreferredSize(new Dimension(50,40));
  186.         header4.setBackground(Color.BLACK);
  187.         header4.setMaximumSize(new Dimension(1600, 40));
  188.        
  189.         header4.add(notes);
  190.         headerIcons.add(header4);
  191.        
  192.         //header 5
  193.         /*
  194.         header2.setPreferredSize(new Dimension(300,40));
  195.         header2.setBackground(Color.BLACK);
  196.         header2.setMaximumSize(new Dimension(1600, 40));
  197.        
  198.         header2.add(modules);
  199.         headerIcons.add(header2);
  200.        
  201.         */
  202.        
  203.         //Add headers to headerIcons JPanel
  204.         headerAndBody.add(headerIcons);
  205.        
  206.        
  207.        
  208.         JPanel body = new JPanel();
  209.         body.setLayout(new BoxLayout(body,BoxLayout.Y_AXIS));
  210.         headerAndBody.add(body);
  211.        
  212.         JPanel bodyTop = new JPanel();
  213.         bodyTop.setBackground(Color.WHITE);
  214.         bodyTop.setPreferredSize(new Dimension(1100, 200));
  215.  
  216.         JPanel bodyLeftSide = new JPanel();
  217.         bodyLeftSide.setBackground(Color.WHITE);
  218.         bodyLeftSide.setPreferredSize(new Dimension(1100,30));
  219.         bodyLeftSide.add(new JLabel("<html>Modules</html>"));
  220.        
  221.         JPanel bodyUserName = new JPanel();
  222.         bodyUserName.setBackground(Color.WHITE);
  223.         bodyUserName.setPreferredSize(new Dimension(1100, 30));
  224.  //       bodyUserName.add(new JLabel("<html>Username</html>"));
  225.        
  226.         JTextField user = new JTextField();
  227.         bodyUserName.add(user);
  228.         user.setPreferredSize( new Dimension( 200, 24 ) );
  229.        
  230.         JPanel bodyPassword = new JPanel();
  231.         bodyPassword.setBackground(Color.WHITE);
  232.         bodyPassword.setPreferredSize(new Dimension(1100, 30));
  233.   //      bodyPassword.add(new JLabel("<html>Password</html>"));
  234.         JTextField pass = new JTextField();
  235.         bodyPassword.add(pass);
  236.         pass.setPreferredSize( new Dimension( 200, 24 ) );
  237.        
  238.         JPanel bodySelect = new JPanel();
  239.         bodySelect.setBackground(Color.WHITE);
  240.         bodySelect.setPreferredSize(new Dimension(1100, 50));
  241.         bodySelect.add(select);
  242.        
  243.        
  244.         bodyLeftSide.setMaximumSize(new Dimension(1600, 30));
  245.         bodyUserName.setMaximumSize(new Dimension(1600, 30));
  246.         bodyPassword.setMaximumSize(new Dimension(1600,30));
  247.         bodySelect.setMaximumSize(new Dimension(1600,50));
  248.  
  249.        
  250.         body.add(bodyTop);
  251.         body.add(bodyLeftSide);
  252.         body.add(bodyUserName);
  253.         body.add(bodyPassword);
  254.         body.add(bodySelect);
  255.        
  256.        
  257.        
  258.        
  259.         JPanel bodyRightSide = new JPanel();
  260.         bodyRightSide.setPreferredSize(new Dimension(100,600));
  261.         bodyRightSide.setBackground(Color.WHITE);
  262.         bodyRightSide.setMaximumSize(new Dimension(1600, 3000));
  263.       //  bodyRightSide.setBorder(BorderFactory.createLineBorder(Color.black));
  264.       //  bodyRightSide.add(new JLabel("Dashboard"));
  265.         body.add(bodyRightSide);
  266.        
  267.        
  268.         footer.setLayout(new BoxLayout(footer,BoxLayout.X_AXIS));
  269.         footer.add(new JLabel("<html><font color=white> <i>Study Planning Software for Software Engineering. Founders; Marc Adlington, Taylor Kern, Edvinus Gurinas and Justinas Druskis (2016).</html>"));
  270.         footer.setPreferredSize(new Dimension(600,40));
  271.         footer.setBackground(Color.GRAY);
  272.         footer.setMaximumSize(new Dimension(1600, 40));
  273.      
  274.        
  275.  
  276.        
  277.         body.add(footer);
  278.    
  279.         this.add(mainContainer);
  280.          
  281.        
  282.         pack();
  283.     }
  284.     /*
  285.      * @param args the command line arguments
  286.      */
  287.     public static void main(String[] args) {
  288.         new ModuleView();
  289.     }
  290.    
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement