Package gui

Source Code of gui.NumericPad

package gui;

import hibernateSwingApi.component.CTextField;

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Robot;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import control.NumericPadControl;

public class NumericPad {
  /**
   * @wbp.parser.entryPoint
   */

  private CTextField cTextFieldBarkodVeyaMiktar;
  private JButton cButtonEnter = new JButton();
  private JPanel panel;
  private JButton button0;
  private JButton button1;
  private JButton button2;
  private JButton button3;
  private JButton button4;
  private JButton button5;
  private JButton button6;
  private JButton button7;
  private JButton button8;
  private JButton button9;
  private JButton buttonSil;
  private JButton buttonTemizle;
  private JButton btnX;
  private Robot robot;
  private int pos;

  public CTextField getcTextFieldBarkodVeyaMiktar() {
    return cTextFieldBarkodVeyaMiktar;
  }

  public void setcTextFieldBarkodVeyaMiktar(
      CTextField cTextFieldBarkodVeyaMiktar) {
    this.cTextFieldBarkodVeyaMiktar = cTextFieldBarkodVeyaMiktar;
  }

  public JButton getcButtonEnter() {
    return cButtonEnter;
  }

  public void setcButtonEnter(JButton cButtonEnter) {
    this.cButtonEnter = cButtonEnter;
  }

  /**
   * @wbp.parser.entryPoint
   */

  public JPanel numericPad() {

    try {
      robot = new Robot();
    } catch (AWTException e) {
      e.printStackTrace();
    }

    panel = new JPanel();
    panel.setBackground(SystemColor.inactiveCaption);
    panel.setBorder(new LineBorder(Color.black, 2, false));
    panel.setBounds(0, 0, 202, 326);
    GridBagLayout gbl_panel = new GridBagLayout();
    gbl_panel.columnWidths = new int[] { 41, 41, 41, 55, 0 };
    gbl_panel.rowHeights = new int[] { 19, 27, 55, 55, 55, 60, 0 };
    gbl_panel.columnWeights = new double[] { 1.0, 1.0, 1.0, 1.0,
        Double.MIN_VALUE };
    gbl_panel.rowWeights = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
        Double.MIN_VALUE };
    panel.setLayout(gbl_panel);
    JLabel cLabelBarkodVeyaMiktar = new JLabel();
    cLabelBarkodVeyaMiktar.setHorizontalAlignment(SwingConstants.CENTER);
    cLabelBarkodVeyaMiktar.setFont(new Font("Tahoma", Font.BOLD, 15));
    cLabelBarkodVeyaMiktar.setText("BARKOD VEYA M\u0130KTAR");
    GridBagConstraints gbc_cLabelBarkodVeyaMiktar = new GridBagConstraints();
    gbc_cLabelBarkodVeyaMiktar.fill = GridBagConstraints.BOTH;
    gbc_cLabelBarkodVeyaMiktar.insets = new Insets(0, 0, 5, 0);
    gbc_cLabelBarkodVeyaMiktar.gridwidth = 4;
    gbc_cLabelBarkodVeyaMiktar.gridx = 0;
    gbc_cLabelBarkodVeyaMiktar.gridy = 0;
    panel.add(cLabelBarkodVeyaMiktar, gbc_cLabelBarkodVeyaMiktar);

    cTextFieldBarkodVeyaMiktar = new CTextField(14) {
      private static final long serialVersionUID = 1L;

      @Override
      public void addNotify() {
        super.addNotify();
        requestFocus();
      }
    };

    cTextFieldBarkodVeyaMiktar.setName("cTextFieldBarkodVeyaMiktar");
    GridBagConstraints gbc_cTextFieldBarkodVeyaMiktar = new GridBagConstraints();
    gbc_cTextFieldBarkodVeyaMiktar.fill = GridBagConstraints.BOTH;
    gbc_cTextFieldBarkodVeyaMiktar.insets = new Insets(0, 0, 5, 0);
    gbc_cTextFieldBarkodVeyaMiktar.gridwidth = 4;
    gbc_cTextFieldBarkodVeyaMiktar.gridx = 0;
    gbc_cTextFieldBarkodVeyaMiktar.gridy = 1;
    panel.add(cTextFieldBarkodVeyaMiktar, gbc_cTextFieldBarkodVeyaMiktar);

    button7 = new JButton();
    button7.setFont(new Font("Tahoma", Font.BOLD, 14));
    button7.setText("7");
    GridBagConstraints gbc_button7 = new GridBagConstraints();
    gbc_button7.fill = GridBagConstraints.BOTH;
    gbc_button7.insets = new Insets(0, 0, 5, 5);
    gbc_button7.gridx = 0;
    gbc_button7.gridy = 2;
    panel.add(button7, gbc_button7);

    button8 = new JButton();
    button8.setFont(new Font("Tahoma", Font.BOLD, 14));
    button8.setText("8");
    GridBagConstraints gbc_button8 = new GridBagConstraints();
    gbc_button8.fill = GridBagConstraints.BOTH;
    gbc_button8.insets = new Insets(0, 0, 5, 5);
    gbc_button8.gridx = 1;
    gbc_button8.gridy = 2;
    panel.add(button8, gbc_button8);

    button9 = new JButton();
    button9.setFont(new Font("Tahoma", Font.BOLD, 14));
    button9.setText("9");
    GridBagConstraints gbc_button9 = new GridBagConstraints();
    gbc_button9.fill = GridBagConstraints.BOTH;
    gbc_button9.insets = new Insets(0, 0, 5, 5);
    gbc_button9.gridx = 2;
    gbc_button9.gridy = 2;
    panel.add(button9, gbc_button9);

    buttonSil = new JButton();
    buttonSil.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
    buttonSil.setText("Sil");
    GridBagConstraints gbc_buttonSil = new GridBagConstraints();
    gbc_buttonSil.fill = GridBagConstraints.BOTH;
    gbc_buttonSil.insets = new Insets(0, 0, 5, 0);
    gbc_buttonSil.gridx = 3;
    gbc_buttonSil.gridy = 2;
    panel.add(buttonSil, gbc_buttonSil);

    button4 = new JButton();
    button4.setFont(new Font("Tahoma", Font.BOLD, 14));
    button4.setText("4");
    GridBagConstraints gbc_button4 = new GridBagConstraints();
    gbc_button4.fill = GridBagConstraints.BOTH;
    gbc_button4.insets = new Insets(0, 0, 5, 5);
    gbc_button4.gridx = 0;
    gbc_button4.gridy = 3;
    panel.add(button4, gbc_button4);

    button5 = new JButton();
    button5.setFont(new Font("Tahoma", Font.BOLD, 14));
    button5.setText("5");
    GridBagConstraints gbc_button5 = new GridBagConstraints();
    gbc_button5.fill = GridBagConstraints.BOTH;
    gbc_button5.insets = new Insets(0, 0, 5, 5);
    gbc_button5.gridx = 1;
    gbc_button5.gridy = 3;
    panel.add(button5, gbc_button5);

    button6 = new JButton();
    button6.setFont(new Font("Tahoma", Font.BOLD, 14));
    button6.setText("6");
    GridBagConstraints gbc_button6 = new GridBagConstraints();
    gbc_button6.fill = GridBagConstraints.BOTH;
    gbc_button6.insets = new Insets(0, 0, 5, 5);
    gbc_button6.gridx = 2;
    gbc_button6.gridy = 3;
    panel.add(button6, gbc_button6);

    buttonTemizle = new JButton();
    buttonTemizle.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
    buttonTemizle.setText("C");
    GridBagConstraints gbc_buttonTemizle = new GridBagConstraints();
    gbc_buttonTemizle.fill = GridBagConstraints.BOTH;
    gbc_buttonTemizle.insets = new Insets(0, 0, 5, 0);
    gbc_buttonTemizle.gridx = 3;
    gbc_buttonTemizle.gridy = 3;
    panel.add(buttonTemizle, gbc_buttonTemizle);

    button1 = new JButton();
    button1.setFont(new Font("Tahoma", Font.BOLD, 14));
    button1.setText("1");
    GridBagConstraints gbc_button1 = new GridBagConstraints();
    gbc_button1.fill = GridBagConstraints.BOTH;
    gbc_button1.insets = new Insets(0, 0, 5, 5);
    gbc_button1.gridx = 0;
    gbc_button1.gridy = 4;
    panel.add(button1, gbc_button1);

    button2 = new JButton();
    button2.setFont(new Font("Tahoma", Font.BOLD, 14));
    button2.setText("2");
    GridBagConstraints gbc_button2 = new GridBagConstraints();
    gbc_button2.fill = GridBagConstraints.BOTH;
    gbc_button2.insets = new Insets(0, 0, 5, 5);
    gbc_button2.gridx = 1;
    gbc_button2.gridy = 4;
    panel.add(button2, gbc_button2);

    button3 = new JButton();
    button3.setFont(new Font("Tahoma", Font.BOLD, 14));
    button3.setText("3");
    GridBagConstraints gbc_button3 = new GridBagConstraints();
    gbc_button3.fill = GridBagConstraints.BOTH;
    gbc_button3.insets = new Insets(0, 0, 5, 5);
    gbc_button3.gridx = 2;
    gbc_button3.gridy = 4;
    panel.add(button3, gbc_button3);

    btnX = new JButton();
    btnX.setFont(new Font("Tahoma", Font.BOLD, 14));
    btnX.setText("*");
    GridBagConstraints gbc_btnX = new GridBagConstraints();
    gbc_btnX.fill = GridBagConstraints.BOTH;
    gbc_btnX.insets = new Insets(0, 0, 5, 0);
    gbc_btnX.gridx = 3;
    gbc_btnX.gridy = 4;
    panel.add(btnX, gbc_btnX);

    button0 = new JButton();
    button0.setFont(new Font("Tahoma", Font.BOLD, 14));
    button0.setText("0");
    GridBagConstraints gbc_button0 = new GridBagConstraints();
    gbc_button0.fill = GridBagConstraints.BOTH;
    gbc_button0.insets = new Insets(0, 0, 0, 5);
    gbc_button0.gridwidth = 2;
    gbc_button0.gridx = 0;
    gbc_button0.gridy = 5;
    panel.add(button0, gbc_button0);
    cButtonEnter.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));

    cButtonEnter.setName("enter");
    cButtonEnter.setText("Enter");
    GridBagConstraints gbc_cButtonEnter = new GridBagConstraints();
    gbc_cButtonEnter.fill = GridBagConstraints.BOTH;
    gbc_cButtonEnter.gridwidth = 2;
    gbc_cButtonEnter.gridx = 2;
    gbc_cButtonEnter.gridy = 5;
    panel.add(cButtonEnter, gbc_cButtonEnter);
    initListener();
    return panel;

  }

  private void initListener() {
    cTextFieldBarkodVeyaMiktar.addKeyListener(new KeyAdapter() {

      @Override
      public void keyReleased(KeyEvent e) {

        if (!cTextFieldBarkodVeyaMiktar.getText().equals("")) {
          if (!NumericPadControl.validate(cTextFieldBarkodVeyaMiktar
              .getText())) {
            robotMetodu(KeyEvent.VK_BACK_SPACE);
          }
        }

      }

      @Override
      public void keyTyped(KeyEvent e) {
        if (e.getKeyChar() == KeyEvent.VK_ENTER) {
          cButtonEnter.doClick();
        }
      }
    });

    buttonSil.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        cTextFieldBarkodVeyaMiktar.requestFocusInWindow();
        robotMetodu(KeyEvent.VK_BACK_SPACE);

      }
    });

    buttonTemizle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        cTextFieldBarkodVeyaMiktar.setText("");
        cTextFieldBarkodVeyaMiktar.requestFocusInWindow();
      }
    });

    btnX.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_MULTIPLY);
      }
    });

    button0.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_0);
      }
    });

    button3.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_3);
      }
    });

    button2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_2);
      }
    });

    button1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_1);
      }
    });

    button6.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_6);
      }
    });

    button5.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_5);
      }
    });

    button4.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_4);
      }
    });

    button9.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_9);
      }
    });

    button8.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        robotMetodu(KeyEvent.VK_8);
      }
    });

    button7.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        robotMetodu(KeyEvent.VK_7);
      }
    });
  }

  protected void robotMetodu(int keyEvent) {
    pos = cTextFieldBarkodVeyaMiktar.getCaretPosition();
    cTextFieldBarkodVeyaMiktar.requestFocusInWindow();
    cTextFieldBarkodVeyaMiktar.moveCaretPosition(pos);
    robot.keyPress(keyEvent);
    robot.keyRelease(keyEvent);
  }
}
TOP

Related Classes of gui.NumericPad

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.