From 35001eb4b0efe2f239b40e35144e666c9171aee5 Mon Sep 17 00:00:00 2001 From: s441433 Date: Tue, 8 Jan 2019 22:17:59 +0100 Subject: [PATCH] Update StolowkaZPM.java --- apka_StolowkaZPM/src/StolowkaZPM.java | 220 ++++++++++++++++++++------ 1 file changed, 170 insertions(+), 50 deletions(-) diff --git a/apka_StolowkaZPM/src/StolowkaZPM.java b/apka_StolowkaZPM/src/StolowkaZPM.java index 4d8cca5..3f6f0de 100644 --- a/apka_StolowkaZPM/src/StolowkaZPM.java +++ b/apka_StolowkaZPM/src/StolowkaZPM.java @@ -1,29 +1,46 @@ +//import javax.swing.*; +//import javax.swing.ImageIcon; +import javax.swing.JButton; import javax.swing.JFrame; -import javax.swing.JLayeredPane; -import javax.swing.JOptionPane; +//import javax.swing.JLayeredPane; +//import javax.swing.JOptionPane; //import javax.swing.JTextField; import javax.swing.JLabel; +import javax.swing.JOptionPane; +//import java.awt.Image; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JPasswordField; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; +//import java.awt.event.FocusListener; import java.awt.*; -import javax.swing.JPanel; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.layout.ColumnSpec; -import com.jgoodies.forms.layout.RowSpec; -import javax.swing.JDesktopPane; -import javax.swing.JToolBar; +//import javax.swing.JPanel; +//import com.jgoodies.forms.layout.FormLayout; +//import com.jgoodies.forms.layout.ColumnSpec; +//import com.jgoodies.forms.layout.RowSpec; +//import javax.swing.JDesktopPane; +//import javax.swing.JToolBar; import javax.swing.SwingConstants; +//import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; //import javax.swing.JPanel; public class StolowkaZPM { - private JFrame frmStowkaZpm; - private JPasswordField rfidView; + private JFrame frmStolowkaZpm; private JLabel lblNewLabel; + //public String Dalej; + //private JLabel podajPINlabel; + //private JLabel pinView; + //private String Dalej; + //public StolowkaZPM() {Dalej=null;} + //public StolowkaZPM(String n) {Dalej=n;} + //public StolowkaZPM(StolowkaZPM P) {Dalej=P.Dalej;} + //public String GetDalej() {return Dalej;} /** * Launch the application. @@ -33,73 +50,176 @@ public class StolowkaZPM { public void run() { try { StolowkaZPM window = new StolowkaZPM(); - window.frmStowkaZpm.setVisible(true); + window.frmStolowkaZpm.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } - - /** - * Create the application. - */ + + Connection conn=null; + public StolowkaZPM() { - initialize(); + initialize1(); } - /** - * Initialize the contents of the frame. - */ - private void initialize() { - frmStowkaZpm = new JFrame(); - frmStowkaZpm.addFocusListener(new FocusAdapter() { + private void initialize1() { + + //************************************** + conn=SQLiteConnection.dbConnector(); + //************************************** + frmStolowkaZpm = new JFrame(); + frmStolowkaZpm.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent arg0) { } }); + //Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); //int x = (int) ((size.getWidth() - frmStowkaZpm.getWidth()) / 2); //int y = (int) ((size.getHeight() - frmStowkaZpm.getHeight()) / 2); //frmStowkaZpm.setLocation(x, y); - frmStowkaZpm.setTitle("Sto\u0142\u00F3wka ZPM"); - frmStowkaZpm.setBounds(1, 1, 499, 356); - frmStowkaZpm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frmStowkaZpm.getContentPane().setLayout(new GridLayout(0, 1, 0, 0)); + frmStolowkaZpm.setTitle("Sto\u0142\u00F3wka ZPM"); + frmStolowkaZpm.setBounds(1, 1, 499, 356); + frmStolowkaZpm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmStolowkaZpm.getContentPane().setLayout(new GridLayout(0, 1, 0, 0)); + frmStolowkaZpm.setResizable(false); + Toolkit tk = Toolkit.getDefaultToolkit(); + int xsize = (int) tk.getScreenSize().getWidth(); + int ysize = (int) tk.getScreenSize().getHeight(); + frmStolowkaZpm.setSize(xsize, ysize); + + /* + lblNewLabel_1 = new JLabel("New label"); + Image img = new ImageIcon(this.getClass().getResource("/icon.png")).getImage(); + lblNewLabel_1.setIcon(new ImageIcon(img)); + frmStolowkaZpm.getContentPane().add(lblNewLabel_1); + */ lblNewLabel = new JLabel("\"Sto\u0142\u00F3wka ZPM\""); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 70)); lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); - frmStowkaZpm.getContentPane().add(lblNewLabel); + frmStolowkaZpm.getContentPane().add(lblNewLabel); JLabel lblZbliKartDo = new JLabel("Zbli\u017C kart\u0119 do czytnika RFID"); lblZbliKartDo.setHorizontalAlignment(SwingConstants.CENTER); - frmStowkaZpm.getContentPane().add(lblZbliKartDo); + frmStolowkaZpm.getContentPane().add(lblZbliKartDo); lblZbliKartDo.setFont(new Font("Tahoma", Font.PLAIN, 40)); - rfidView = new JPasswordField(); + JPasswordField rfidView = new JPasswordField(); rfidView.setHorizontalAlignment(SwingConstants.CENTER); - frmStowkaZpm.getContentPane().add(rfidView); - rfidView.setFont(new Font("Tahoma", Font.PLAIN, 17)); - rfidView.addActionListener(new ActionListener() { - @SuppressWarnings("static-access") - public void actionPerformed(ActionEvent e) { - - @SuppressWarnings("deprecation") - String RFID = rfidView.getText(); - if (RFID.equals("0005492974")){ - rfidView.setText(""); - //JOptionPane.showMessageDialog(frmStowkaZpm, "Zalogowano!"); - oknoPIN wpiszPin = new oknoPIN(); - wpiszPin.noweOkno(); - } else { - rfidView.setText(""); - //JOptionPane.showMessageDialog(frmStowkaZpm, "NIE Zalogowano!"); - } - } - }); + frmStolowkaZpm.getContentPane().add(rfidView); + rfidView.setFont(new Font("Tahoma", Font.PLAIN, 50)); rfidView.setToolTipText("numer karty"); - } -} \ No newline at end of file + rfidView.addActionListener(new ActionListener() { + @SuppressWarnings("deprecation") + public void actionPerformed(ActionEvent e) { + //String RFIDfromApp = rfidView.getText(); + //************************************** + try { + + String query = "SELECT * FROM users WHERE RFID=?"; + PreparedStatement pst = conn.prepareStatement(query); + pst.setString(1, rfidView.getText()); + ResultSet rFID = pst.executeQuery(); + String Dalej = rFID.getString("PIN"); + int count = 0; + while (rFID.next()) { + count=count+1; + } + if (count == 1) { + //rfidView.setText(""); + + //JOptionPane.showMessageDialog(frmStolowkaZpm, "Zalogowano!"); + //JOptionPane.showMessageDialog(frmStolowkaZpm, Dalej); + //oknoPIN wpiszPin = new oknoPIN(); + //wpiszPin.noweOkno(); + + + + frmStolowkaZpm.remove(lblZbliKartDo); + JLabel podajPINlabel = new JLabel("PODAJ PIN (4 CYFRY)"); + podajPINlabel.setHorizontalAlignment(SwingConstants.CENTER); + frmStolowkaZpm.getContentPane().add(podajPINlabel); + podajPINlabel.setFont(new Font("Tahoma", Font.PLAIN, 40)); + + frmStolowkaZpm.remove(rfidView); + JPasswordField pinView = new JPasswordField(); + pinView.setHorizontalAlignment(SwingConstants.CENTER); + frmStolowkaZpm.getContentPane().add(pinView); + pinView.setFont(new Font("Tahoma", Font.PLAIN, 50)); + pinView.setToolTipText("numer karty"); + + JButton btnZaloguj = new JButton("Zaloguj"); + btnZaloguj.setFont(new Font("Tahoma", Font.PLAIN, 50)); + btnZaloguj.setBounds(724, 298, 213, 69); + frmStolowkaZpm.getContentPane().add(btnZaloguj); + btnZaloguj.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + try { + String Dalej1 = pinView.getText(); + if(Dalej.equals(Dalej1)){ + DrukujBilet wybierzMenu = new DrukujBilet(); + wybierzMenu.oknoDrukujBilet();} + else{ + pinView.setText(""); + //JOptionPane.showMessageDialog(frmStolowkaZpm, Dalej1); + //JOptionPane.showMessageDialog(frmStolowkaZpm, Dalej); + } + } catch (Exception e1){ + JOptionPane.showMessageDialog(null, e1); + pinView.setText(""); + } + /* + + try { + String query2 = "SELECT * FROM users WHERE RFID=? and Password=?"; + PreparedStatement pst2 = conn.prepareStatement(query2); + pst2.setString(1, rfidView.getText()); + pst2.setString(2, pinView.getText()); + ResultSet pass2 = pst2.executeQuery(); + //JOptionPane.showMessageDialog(frmStolowkaZpm, rfidView.getText()); + //JOptionPane.showMessageDialog(frmStolowkaZpm, pinView.getText()); + int count2 = 0; + while (pass2.next()) { + count2=count2+1; + } + if (count2 == 1) { + pinView.setText(""); + JOptionPane.showMessageDialog(frmStolowkaZpm, "Zalogowano!"); + //frmStolowkaZpm.setVisible(false); + DrukujBilet wybierzMenu = new DrukujBilet(); + wybierzMenu.oknoDrukujBilet(); + } else { + pinView.setText(""); + JOptionPane.showMessageDialog(frmStolowkaZpm, "NIE Zalogowano!"); + } + pass2.close(); + pst2.close(); + + } catch (Exception e1){ + JOptionPane.showMessageDialog(null, e1); + pinView.setText(""); + } + + } + */ + }}); + + } else { + rfidView.setText(""); + //JOptionPane.showMessageDialog(frmStolowkaZpm, "NIE Zalogowano!"); + } + rFID.close(); + pst.close(); + + } catch (Exception e1){ + //JOptionPane.showMessageDialog(null, e1); + rfidView.setText(""); + } + }}); + }} \ No newline at end of file