Advertisement
enkacang

CASE STUDY 1 - IPT

Oct 4th, 2022
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 KB | None | 0 0
  1. //GROUP IPT 01DDT20F1122 / 01DDT20F...
  2.  
  3. import java.awt.*;
  4. import java.awt.event.WindowEvent;    
  5. import java.awt.event.WindowListener;    
  6. import java.awt.event.WindowAdapter;    
  7.  
  8.  
  9. public class CaseStudy1 extends Frame  {
  10.    
  11.     private int _xSizePanel = 400;;
  12.     private int _ySizePanel = 30;
  13.     private int _xIncrement = 30;
  14.    
  15.     private Panel _panel1;
  16.     private Panel _panel2;
  17.     private Panel _panel3;
  18.     private Panel _panel4;
  19.     private Panel _panel5;
  20.     private Panel _panel6;
  21.     private Panel _panel7;
  22.        
  23.     public CaseStudy1(String title)
  24.     {
  25.         //Initialization
  26.         this.startInitialization();
  27.         this.addCloseButtonHandler();
  28.         this.addMenuBar();
  29.  
  30.  
  31.         //ALL FORM START
  32.         this.addPanelLabel(new Panel(),"", 1);
  33.         this.addPanelLabel(new Panel(),"PENTHOUZE SUBANG JAYA REGISTRATION", 2);
  34.  
  35.         this.addPanelForm(_panel1, "Name :", 3, 30);
  36.         this._panel1.setBackground(Color.WHITE);
  37.  
  38.         this.addPanelForm(_panel2, "IC No :", 4, 30);
  39.         this._panel2.setBackground(Color.WHITE);
  40.  
  41.         this.addPanelForm(_panel6, "Phone No :", 5, 30);
  42.         this._panel6.setBackground(Color.WHITE);
  43.  
  44.  
  45.         this.addPanelLabel(new Panel(),"GENDER", 6);
  46.         this.addPanelRadioButton(_panel3, "Male-Female", 7);
  47.         this._panel3.setBackground(Color.WHITE);
  48.  
  49.  
  50.         this.addPanelLabel(new Panel(),"PICK YOUR HOBBIES", 8);
  51.         this.addPanelCheckBoxButton(_panel5, "Game-Sports-Reading-Meditation", 9);
  52.         this._panel5.setBackground(Color.WHITE);
  53.        
  54.         this.addPanelLabel(new Panel(),"ADDRESS", 10);
  55.         this.addPanelFormTextArea(_panel7, "", 11, 4, 30);
  56.         this._panel7.setBackground(Color.WHITE);
  57.         this._panel7.setBounds(0, 11 * _xIncrement,_xSizePanel,_ySizePanel + 50);
  58.        
  59.         Panel tempPanel = new Panel();
  60.         this.addPanelButton(tempPanel,"Submit", 14);
  61.         tempPanel.setBackground(Color.WHITE);
  62.         this.addPanelLabel(new Panel(),"THANK YOU", 15);
  63.         //ALL FORM END
  64.    
  65.        
  66.         //End Initialization
  67.         this.endInitialization(title);
  68.     }
  69.    
  70.     private void startInitialization()
  71.     {
  72.         _panel1 = new Panel();
  73.         _panel2 = new Panel();
  74.         _panel3 = new Panel();
  75.         _panel4 = new Panel();
  76.         _panel5 = new Panel();
  77.         _panel6 = new Panel();
  78.         _panel7 = new Panel();
  79.     }
  80.    
  81.     private void endInitialization(String title)
  82.     {
  83.         this.setTitle(title);
  84.         this.setLayout(null);
  85.         this.setResizable(false);
  86.         this.setSize(400,480);
  87.         this.setVisible(true);
  88.     }
  89.    
  90.     private void addCloseButtonHandler()
  91.     {
  92.         addWindowListener (new WindowAdapter() {    
  93.          public void windowClosing (WindowEvent e) {    
  94.           dispose();    
  95.          }    
  96.         });
  97.     }
  98.    
  99.     private void addMenuBar()
  100.     {
  101.          MenuBar menuBar = new MenuBar();  
  102.          Menu menu = new Menu("Menu");  
  103.          MenuItem itemExit= new MenuItem("Exit");  
  104.          menu.add(itemExit);  
  105.          menuBar.add(menu);
  106.          this.setMenuBar(menuBar);  
  107.     }
  108.     //REGION START : ALL FORM
  109.     private void addPanelLabel(Panel panel, String label, int xPosition)
  110.     {
  111.         this.createPanel(panel, xPosition);
  112.        
  113.         panel.add(new Label(label));
  114.     }
  115.    
  116.     private void addPanelForm(Panel panel, String label, int xPosition, int textFieldSize)
  117.     {
  118.         this.createPanel(panel, xPosition);
  119.        
  120.         panel.add(new Label(label));
  121.         panel.add(new TextField("", textFieldSize));
  122.     }
  123.    
  124.     private void addPanelFormTextArea(Panel panel, String label, int xPosition, int rowSize, int columnSize)
  125.     {
  126.         this.createPanel(panel, xPosition);
  127.         panel.add(new Label(label));
  128.         panel.add(new TextArea (rowSize, columnSize));
  129.     }
  130.    
  131.     private void addPanelRadioButton(Panel panel, String buttonName, int xPosition)
  132.     {
  133.         this.createPanel(panel, xPosition);
  134.        
  135.         String[] buttonSplit = buttonName.split("-");
  136.        
  137.         CheckboxGroup checkBoxGroup1 = new CheckboxGroup();
  138.        
  139.         for (String name : buttonSplit)
  140.         {
  141.             panel.add(new Checkbox(name, checkBoxGroup1, false));
  142.         }
  143.     }
  144.    
  145.     private void addPanelCheckBoxButton(Panel panel, String buttonName, int xPosition)
  146.     {
  147.         this.createPanel(panel, xPosition);
  148.        
  149.         String[] buttonSplit = buttonName.split("-");
  150.        
  151.         for (String name : buttonSplit)
  152.         {
  153.             panel.add(new Checkbox(name));
  154.         }
  155.     }
  156.    
  157.     private void addPanelButton(Panel panel, String buttonName, int xPosition)
  158.     {
  159.         this.createPanel(panel, xPosition);
  160.        
  161.         panel.add(new Button(buttonName));
  162.     }
  163.    
  164.     private void createPanel(Panel panel, int xPosition)
  165.     {
  166.         panel.setBounds(0,xPosition * _xIncrement,_xSizePanel,_ySizePanel);
  167.         panel.setBackground(Color.gray);
  168.         panel.setLayout(new FlowLayout());
  169.         this.add(panel);
  170.     }
  171.     //REGION END : ALL FORM
  172.    
  173.     public static void main(String args[])
  174.     {
  175.         new CaseStudy1("Penthouze SUBANG JAYA");
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement