[java] a

Viewer

  1.  
  2. import javax.swing.*;
  3. import javax.swing.border.EmptyBorder;
  4. import java.awt.*;
  5.  
  6.  
  7.  
  8. public class MainFrame extends GUI {
  9.     JFrame frame = new JFrame();
  10.     JPanel panel,panelCenter,panelTop,panelLeft,panelRight,panelBottom;
  11.     JLabel heading1;
  12.  
  13.     public MainFrame() {
  14.         // MainFrame characteristics
  15.         frame.setTitle("Electric Bill Calculator");
  16.         frame.setSize(800,600);
  17.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18.         frame.setResizable(true);
  19.         frame.setLocationRelativeTo(null);
  20.  
  21.         //note: the whole main frame's panel uses BorderLayout
  22.         panel =  new JPanel();
  23.         panel.setLayout(new BorderLayout());
  24.  
  25.         //Top panel
  26.         panelTop();
  27.         //Left panel
  28.         panelLeft();
  29.         //Right panel
  30.         panelRight();
  31.         //Center panel
  32.         panelCenter();
  33.         // Bottom Panel
  34.         panelBottom();
  35.  
  36.         frame.add(panel);
  37.         frame.setVisible(true);
  38.     }
  39.  
  40.     public void panelTop() {
  41.         //------------------------------------TOP--------------------------------------------------------------------
  42.         // note: heading
  43.         //panelTop.setBackground(Color.RED);
  44.         //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
  45.         panelTop = new JPanel();
  46.         panelTop.setBorder(new EmptyBorder(01000100));
  47.         JLabel heading_input = new JLabel("TNB BILL CALCULATOR",SwingConstants.CENTER);
  48.         FontClass.setLabelStyle(heading_input,"title");
  49.         // adding image
  50.  
  51.  
  52.         panelTop.add(heading_input);
  53.         panel.add(panelTop, BorderLayout.NORTH);
  54.         // //--------------------------------------------------------------------------------------------------------
  55.     }
  56.  
  57.     public void panelLeft() {
  58.         //------------------------------------LEFT--------------------------------------------------------------------
  59.         panelLeft = new JPanel();
  60.         //panelLeft.setBorder(new EmptyBorder(0, 50, 0, 0));
  61.         //panelLeft.setBackground(Color.RED);
  62.         //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
  63.         //heading1 = new JLabel("             ",SwingConstants.CENTER);
  64.        // FontClass.setLabelStyle(heading1,"title");
  65.         //panelLeft.add(heading1);
  66.         panel.add(panelLeft, BorderLayout.WEST);
  67.         //----------------------------------------------------------------------------------------------------
  68.     }
  69.  
  70.     public void panelRight() {
  71.         //------------------------------------RIGHT--------------------------------------------------------------------
  72.         panelRight = new JPanel();
  73.         //panelRight.setBorder(new EmptyBorder(0, 0, 0, 10));
  74.         //panelLeft.setBackground(Color.RED);
  75.         //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
  76.        // heading1 = new JLabel("             ",SwingConstants.CENTER);
  77.        // FontClass.setLabelStyle(heading1,"title");
  78.        // panelRight.add(heading1);
  79.         panel.add(panelRight, BorderLayout.EAST);
  80.         //----------------------------------------------------------------------------------------------------
  81.     }
  82.  
  83.     public void panelCenter() {
  84.         //------------------------------------CENTER--------------------------------------------------------------------
  85.         // CENTER part of BorderLayout, we are adding flowlayout panel in it.
  86.         panelCenter =  new JPanel();
  87.        // panelCenter.setBackground(Color.CYAN);
  88.         panelCenter.setBorder(new EmptyBorder(1005010050));
  89.         panelCenter.setLayout(new GridLayout(3,2,0,10));
  90.         textBox("Total Consumption (kWh):","Select month");
  91.         JLabel emptyLabel = new JLabel(" Visit https://myelectricitybill.my/bill_calculator_domestic.html");
  92.         FontClass.setLabelStyle(emptyLabel,"small");
  93.         //resetButton.setBackground(Color.GRAY);
  94.         ButtonActivity();
  95.  
  96.         panelCenter.add(emptyLabel);
  97.         panelCenter.add(calculateTotal);
  98.         panel.add(panelCenter,BorderLayout.CENTER);
  99.         //---------------------------------------------------------------------------------------------------------------
  100.     }
  101.  
  102.     public void panelBottom() {
  103.         //------------------------------------BOTTOM--------------------------------------------------------------------
  104.         // note: heading
  105.         panelBottom = new JPanel();
  106.         panelBottom.setLayout(new GridBagLayout());
  107.         //panelBottom.setBackground(Color.RED);
  108.         panelBottom.setBorder(new EmptyBorder(0000));
  109.         GridBagConstraints c = new GridBagConstraints();
  110.         c.insets = new Insets(10000);
  111.         c.fill = GridBagConstraints.BOTH;
  112.  
  113.        /* ButtonActivity();
  114.         c.gridx = 2;
  115.         c.gridy = 1;
  116.         c.weightx = 0;
  117.         c.weighty = -5;
  118.         c.ipadx = 0;
  119.         c.anchor = GridBagConstraints.LINE_START;
  120.         panelBottom.add(calculateTotal, c);*/
  121.  
  122.         label_result = new JLabel("Result");
  123.         FontClass.setLabelStyle(label_result,"title");
  124.         c.gridx = 2;
  125.         c.gridy = 3;
  126.         c.weightx = 0;
  127.         c.weighty = 0;
  128.         panelBottom.add(label_result, c);
  129.  
  130.         JLabel estimateTitle = new JLabel("Estimated Result:");
  131.         FontClass.setLabelStyle(estimateTitle,"normal_bold");
  132.         c.gridx = 0;
  133.         c.gridy = 5;
  134.         c.weightx = 0;
  135.         c.weighty = 0;
  136.         // c.anchor = GridBagConstraints.LINE_START;
  137.         panelBottom.add(estimateTitle, c);
  138.  
  139.         label_estimate = new JLabel("      RM00.00");
  140.         FontClass.setLabelStyle(label_estimate,"normal");
  141.         c.gridx = 3;
  142.         c.gridy = 5;
  143.         c.weightx = 0;
  144.         c.weighty = 0;
  145.         // c.anchor = GridBagConstraints.LINE_START;
  146.         panelBottom.add(label_estimate, c);
  147.  
  148.         icptTitle = new JLabel("ICPT:");
  149.         FontClass.setLabelStyle(icptTitle,"normal_bold");
  150.         c.gridx = 0;
  151.         c.gridy = 6;
  152.         c.weightx = 0;
  153.         c.weighty = 0;
  154.         // c.anchor = GridBagConstraints.LINE_START;
  155.         panelBottom.add(icptTitle, c);
  156.  
  157.         label_icpt = new JLabel("    - RM00.00");
  158.         FontClass.setLabelStyle(label_icpt,"normal");
  159.         c.gridx = 3;
  160.         c.gridy = 6;
  161.         c.weightx = 0;
  162.         c.weighty = 0;
  163.         // c.anchor = GridBagConstraints.LINE_START;
  164.         panelBottom.add(label_icpt, c);
  165.  
  166.         JLabel taxTitle = new JLabel("Service Tax (6%):");
  167.         FontClass.setLabelStyle(taxTitle,"normal_bold");
  168.         c.gridx = 0;
  169.         c.gridy = 7;
  170.         c.weightx = 0;
  171.         c.weighty = 0;
  172.         // c.anchor = GridBagConstraints.LINE_START;
  173.         panelBottom.add(taxTitle, c);
  174.  
  175.         label_tax = new JLabel("    - RM00.00");
  176.         FontClass.setLabelStyle(label_tax,"normal");
  177.         c.gridx = 3;
  178.         c.gridy = 7;
  179.         c.weightx = 0;
  180.         c.weighty = 0;
  181.         // c.anchor = GridBagConstraints.LINE_START;
  182.         panelBottom.add(label_tax, c);
  183.  
  184.         JLabel resultTitle = new JLabel("Total Bill:");
  185.         FontClass.setLabelStyle(resultTitle,"normal_bold");
  186.         c.gridx = 0;
  187.         c.gridy = 8;
  188.         c.weightx = 0;
  189.         c.weighty = 0;
  190.         // c.anchor = GridBagConstraints.LINE_START;
  191.         panelBottom.add(resultTitle, c);
  192.  
  193.         label_total = new JLabel("      RM00.00");
  194.         FontClass.setLabelStyle(label_total,"normal");
  195.         c.gridx = 3;
  196.         c.gridy = 8;
  197.         c.weightx = 0;
  198.         c.weighty = 0;
  199.         // c.anchor = GridBagConstraints.LINE_START;
  200.         panelBottom.add(label_total, c);
  201.  
  202.         //panelBottom.setBackground(Color.RED);
  203.         panelBottom.setBorder(new EmptyBorder(00500));
  204.         //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
  205.         panel.add(panelBottom, BorderLayout.SOUTH);
  206.         // //--------------------------------------------------------------------------------------------------------
  207.     }
  208.  
  209.     @Override
  210.     public void textBox(String text1,String text2) {
  211.         super.textBox(text1,text2);
  212.         panelCenter.add(super.label);  panelCenter.add(super.fieldConsumption);
  213.         panelCenter.add(super.label2); panelCenter.add(super.comboMonths);
  214.  
  215.  
  216.     }
  217.  
  218.     public static void main(String[] args) {
  219.          new MainFrame();
  220.  
  221.     }
  222.  
  223. }
  224.  

Editor

You can edit this paste and save as new:


File Description
  • a
  • Paste Code
  • 22 Jun-2021
  • 8.12 Kb
You can Share it: