[java] a
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import java.awt.*;
- public class MainFrame extends GUI {
- JFrame frame = new JFrame();
- JPanel panel,panelCenter,panelTop,panelLeft,panelRight,panelBottom;
- JLabel heading1;
- public MainFrame() {
- // MainFrame characteristics
- frame.setTitle("Electric Bill Calculator");
- frame.setSize(800,600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setResizable(true);
- frame.setLocationRelativeTo(null);
- //note: the whole main frame's panel uses BorderLayout
- panel = new JPanel();
- panel.setLayout(new BorderLayout());
- //Top panel
- panelTop();
- //Left panel
- panelLeft();
- //Right panel
- panelRight();
- //Center panel
- panelCenter();
- // Bottom Panel
- panelBottom();
- frame.add(panel);
- frame.setVisible(true);
- }
- public void panelTop() {
- //------------------------------------TOP--------------------------------------------------------------------
- // note: heading
- //panelTop.setBackground(Color.RED);
- //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
- panelTop = new JPanel();
- panelTop.setBorder(new EmptyBorder(0, 100, 0, 100));
- JLabel heading_input = new JLabel("TNB BILL CALCULATOR",SwingConstants.CENTER);
- FontClass.setLabelStyle(heading_input,"title");
- // adding image
- panelTop.add(heading_input);
- panel.add(panelTop, BorderLayout.NORTH);
- // //--------------------------------------------------------------------------------------------------------
- }
- public void panelLeft() {
- //------------------------------------LEFT--------------------------------------------------------------------
- panelLeft = new JPanel();
- //panelLeft.setBorder(new EmptyBorder(0, 50, 0, 0));
- //panelLeft.setBackground(Color.RED);
- //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
- //heading1 = new JLabel(" ",SwingConstants.CENTER);
- // FontClass.setLabelStyle(heading1,"title");
- //panelLeft.add(heading1);
- panel.add(panelLeft, BorderLayout.WEST);
- //----------------------------------------------------------------------------------------------------
- }
- public void panelRight() {
- //------------------------------------RIGHT--------------------------------------------------------------------
- panelRight = new JPanel();
- //panelRight.setBorder(new EmptyBorder(0, 0, 0, 10));
- //panelLeft.setBackground(Color.RED);
- //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
- // heading1 = new JLabel(" ",SwingConstants.CENTER);
- // FontClass.setLabelStyle(heading1,"title");
- // panelRight.add(heading1);
- panel.add(panelRight, BorderLayout.EAST);
- //----------------------------------------------------------------------------------------------------
- }
- public void panelCenter() {
- //------------------------------------CENTER--------------------------------------------------------------------
- // CENTER part of BorderLayout, we are adding flowlayout panel in it.
- panelCenter = new JPanel();
- // panelCenter.setBackground(Color.CYAN);
- panelCenter.setBorder(new EmptyBorder(100, 50, 100, 50));
- panelCenter.setLayout(new GridLayout(3,2,0,10));
- textBox("Total Consumption (kWh):","Select month");
- JLabel emptyLabel = new JLabel(" Visit https://myelectricitybill.my/bill_calculator_domestic.html");
- FontClass.setLabelStyle(emptyLabel,"small");
- //resetButton.setBackground(Color.GRAY);
- ButtonActivity();
- panelCenter.add(emptyLabel);
- panelCenter.add(calculateTotal);
- panel.add(panelCenter,BorderLayout.CENTER);
- //---------------------------------------------------------------------------------------------------------------
- }
- public void panelBottom() {
- //------------------------------------BOTTOM--------------------------------------------------------------------
- // note: heading
- panelBottom = new JPanel();
- panelBottom.setLayout(new GridBagLayout());
- //panelBottom.setBackground(Color.RED);
- panelBottom.setBorder(new EmptyBorder(0, 0, 0, 0));
- GridBagConstraints c = new GridBagConstraints();
- c.insets = new Insets(10, 0, 0, 0);
- c.fill = GridBagConstraints.BOTH;
- /* ButtonActivity();
- c.gridx = 2;
- c.gridy = 1;
- c.weightx = 0;
- c.weighty = -5;
- c.ipadx = 0;
- c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(calculateTotal, c);*/
- label_result = new JLabel("Result");
- FontClass.setLabelStyle(label_result,"title");
- c.gridx = 2;
- c.gridy = 3;
- c.weightx = 0;
- c.weighty = 0;
- panelBottom.add(label_result, c);
- JLabel estimateTitle = new JLabel("Estimated Result:");
- FontClass.setLabelStyle(estimateTitle,"normal_bold");
- c.gridx = 0;
- c.gridy = 5;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(estimateTitle, c);
- label_estimate = new JLabel(" RM00.00");
- FontClass.setLabelStyle(label_estimate,"normal");
- c.gridx = 3;
- c.gridy = 5;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(label_estimate, c);
- icptTitle = new JLabel("ICPT:");
- FontClass.setLabelStyle(icptTitle,"normal_bold");
- c.gridx = 0;
- c.gridy = 6;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(icptTitle, c);
- label_icpt = new JLabel(" - RM00.00");
- FontClass.setLabelStyle(label_icpt,"normal");
- c.gridx = 3;
- c.gridy = 6;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(label_icpt, c);
- JLabel taxTitle = new JLabel("Service Tax (6%):");
- FontClass.setLabelStyle(taxTitle,"normal_bold");
- c.gridx = 0;
- c.gridy = 7;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(taxTitle, c);
- label_tax = new JLabel(" - RM00.00");
- FontClass.setLabelStyle(label_tax,"normal");
- c.gridx = 3;
- c.gridy = 7;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(label_tax, c);
- JLabel resultTitle = new JLabel("Total Bill:");
- FontClass.setLabelStyle(resultTitle,"normal_bold");
- c.gridx = 0;
- c.gridy = 8;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(resultTitle, c);
- label_total = new JLabel(" RM00.00");
- FontClass.setLabelStyle(label_total,"normal");
- c.gridx = 3;
- c.gridy = 8;
- c.weightx = 0;
- c.weighty = 0;
- // c.anchor = GridBagConstraints.LINE_START;
- panelBottom.add(label_total, c);
- //panelBottom.setBackground(Color.RED);
- panelBottom.setBorder(new EmptyBorder(0, 0, 50, 0));
- //panelTop.setBorder(new EmptyBorder(0, 0, 100, 0));
- panel.add(panelBottom, BorderLayout.SOUTH);
- // //--------------------------------------------------------------------------------------------------------
- }
- @Override
- public void textBox(String text1,String text2) {
- super.textBox(text1,text2);
- panelCenter.add(super.label); panelCenter.add(super.fieldConsumption);
- panelCenter.add(super.label2); panelCenter.add(super.comboMonths);
- }
- public static void main(String[] args) {
- new MainFrame();
- }
- }
Editor
You can edit this paste and save as new: