Skip to main content
ZTSolutions

Main_gui.class – MAIN GUI ELEMENTS

/***
  * MAIN GUI ELEMENTS
  * **/
 
   public Main_Gui() {
	   
	   
        //construct components
        jCE = new JButton ("CE");
        j7 = new JButton ("7");
        jC = new JButton ("C");
        j8 = new JButton ("8");
        j9 = new JButton ("9");
        jdiv = new JButton ("/");
        jback = new JButton ("<");
        j4 = new JButton ("4");
        jMultiply = new JButton ("x");
        j5 = new JButton ("5");
        j6 = new JButton ("6");
        jMinus = new JButton ("-");
        jAdd = new JButton ("+");
        j3 = new JButton ("3");
        j1 = new JButton ("1");
        j2 = new JButton ("2");
        jComa = new JButton (".");
        j0 = new JButton ("0");
        jsign = new JButton ("+/-");
        jEqual = new JButton ("=");
        jnumber = new JTextField (5);
        jcalc = new JTextField (5);
        
      
        jnumber.setHorizontalAlignment(JTextField.RIGHT);
        jnumber.setFont(fon);
        jcalc.setHorizontalAlignment(JTextField.RIGHT);
        jnumber.requestFocus();
        
       // jnumber.setEditable(false);
        jcalc.setEditable(false);
        
        //set components properties
        jCE.setToolTipText ("Clear  Entry");
        j7.setToolTipText ("Seven");
        jC.setToolTipText ("Clear");
        j8.setToolTipText ("Eight");
        j9.setToolTipText ("Nine");
        jdiv.setToolTipText ("Divide");
        jback.setToolTipText ("Back spance");
        j4.setToolTipText ("four");
        jMultiply.setToolTipText ("Multiply");
        j5.setToolTipText ("Five");
        j6.setToolTipText ("Six");
        jMinus.setToolTipText ("Minus");
        jAdd.setToolTipText ("Add");
        j3.setToolTipText ("Three");
        j1.setToolTipText ("One");
        j2.setToolTipText ("Two");
        jComa.setToolTipText ("coma");
        j0.setToolTipText ("zero");
        jEqual.setToolTipText ("equals");
        jnumber.setToolTipText ("numbers");
        jcalc.setToolTipText ("Calculations");

        //adjust size and set layout
        setPreferredSize (new Dimension (270, 366));
        setLayout (null);

        //add components
        add (jCE);
        add (j7);
        add (jC);
        add (j8);
        add (j9);
        add (jdiv);
        add (jback);
        add (j4);
        add (jMultiply);
        add (j5);
        add (j6);
        add (jMinus);
        add (jAdd);
        add (j3);
        add (j1);
        add (j2);
        add (jComa);
        add (j0);
        add (jsign);
        add (jEqual);
        add (jnumber);
        add (jcalc);
        
        jCE.addActionListener(this);
	       jC.addActionListener(this);
	       j0.addActionListener(this);
	       j1.addActionListener(this);
	       j2.addActionListener(this);
	        j3.addActionListener(this);
	        j4.addActionListener(this);
	        j5.addActionListener(this);
	        j6.addActionListener(this);
	        j7.addActionListener(this);
	        j8.addActionListener(this);
	        j9.addActionListener(this);
	        jComa.addActionListener(this);
	        jsign.addActionListener(this);
	        jEqual.addActionListener(this);
	        jdiv.addActionListener(this);
	        jback.addActionListener(this);
	        jMultiply.addActionListener(this);
	        jMinus.addActionListener(this);
	        jAdd.addActionListener(this); 
        
        //set component bounds (only needed by Absolute Positioning)
        jCE.setBounds (10, 110, 60, 45);
        j7.setBounds (10, 165, 60, 40);
        jC.setBounds (75, 110, 55, 45);
        j8.setBounds (75, 165, 55, 40);
        j9.setBounds (135, 165, 55, 40);
        jdiv.setBounds (195, 110, 55, 45);
        jback.setBounds (135, 110, 55, 45);
        j4.setBounds (10, 210, 60, 40);
        jMultiply.setBounds (195, 165, 55, 40);
        j5.setBounds (75, 210, 55, 40);
        j6.setBounds (135, 210, 55, 40);
        jMinus.setBounds (195, 210, 55, 40);
        jAdd.setBounds (195, 255, 55, 40);
        j3.setBounds (135, 255, 55, 40);
        j1.setBounds (10, 255, 60, 40);
        j2.setBounds (75, 255, 55, 40);
        jComa.setBounds (135, 300, 55, 40);
        j0.setBounds (75, 300, 55, 40);
        jsign.setBounds (10, 300, 60, 40);
        jEqual.setBounds (195, 300, 55, 40);
        jnumber.setBounds (10, 50, 240, 55);
        jcalc.setBounds (10, 20, 240, 25);
    
   }