zaliczeniePP/apka_StolowkaZPM/src/oknoPIN.java

122 lines
3.5 KiB
Java
Raw Normal View History

2019-01-06 17:06:43 +01:00
import java.awt.EventQueue;
2019-01-08 22:18:04 +01:00
//import java.awt.Toolkit;
2019-01-06 17:06:43 +01:00
import javax.swing.JFrame;
import javax.swing.JLabel;
2019-01-08 22:18:04 +01:00
import javax.swing.JOptionPane;
2019-01-06 17:06:43 +01:00
import java.awt.Color;
import javax.swing.SwingConstants;
2019-01-08 22:18:04 +01:00
//import javax.swing.BoxLayout;
//import javax.swing.JTree;
//import javax.swing.JSlider;
//import javax.swing.JToggleButton;
//import com.jgoodies.forms.layout.FormLayout;
//import com.jgoodies.forms.layout.ColumnSpec;
//import com.jgoodies.forms.layout.RowSpec;
//import com.jgoodies.forms.layout.FormSpecs;
//import javax.swing.JTextField;
2019-01-06 17:06:43 +01:00
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
2019-01-08 22:18:04 +01:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
2019-01-06 17:06:43 +01:00
import java.awt.event.ActionEvent;
2019-01-07 00:24:10 +01:00
import java.awt.Font;
2019-01-06 17:06:43 +01:00
2019-01-08 22:18:04 +01:00
public class oknoPIN extends StolowkaZPM {
2019-01-06 17:06:43 +01:00
2019-01-07 00:24:10 +01:00
private JFrame PodajPin;
2019-01-06 17:06:43 +01:00
private JPasswordField passwordField;
public static void noweOkno() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
oknoPIN window = new oknoPIN();
2019-01-07 00:24:10 +01:00
window.PodajPin.setVisible(true);
2019-01-06 17:06:43 +01:00
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
2019-01-08 22:18:04 +01:00
Connection conn=null;
public oknoPIN () {
initialize2();
2019-01-06 17:06:43 +01:00
}
/**
* Initialize the contents of the frame.
*/
2019-01-08 22:18:04 +01:00
private void initialize2 () {
//**************************************
conn=SQLiteConnection.dbConnector();
//**************************************
2019-01-07 00:24:10 +01:00
PodajPin = new JFrame();
PodajPin.setTitle("Podaj PIN");
PodajPin.setBounds(100, 100, 528, 306);
PodajPin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PodajPin.getContentPane().setLayout(null);
PodajPin.setSize(1700, 600);
2019-01-06 17:06:43 +01:00
JLabel lblOknoPin = new JLabel("Podaj sw\u00F3j PIN");
2019-01-07 00:24:10 +01:00
lblOknoPin.setFont(new Font("Tahoma", Font.PLAIN, 56));
lblOknoPin.setBounds(608, 128, 440, 58);
2019-01-06 17:06:43 +01:00
lblOknoPin.setHorizontalAlignment(SwingConstants.CENTER);
lblOknoPin.setBackground(Color.YELLOW);
lblOknoPin.setForeground(Color.BLUE);
2019-01-07 00:24:10 +01:00
PodajPin.getContentPane().add(lblOknoPin);
2019-01-06 17:06:43 +01:00
passwordField = new JPasswordField(0);
2019-01-07 00:24:10 +01:00
passwordField.setFont(new Font("Tahoma", Font.PLAIN, 60));
2019-01-06 17:06:43 +01:00
passwordField.setHorizontalAlignment(SwingConstants.CENTER);
passwordField.setToolTipText("4 cyfry PIN");
2019-01-07 00:24:10 +01:00
passwordField.setBounds(753, 211, 157, 73);
PodajPin.getContentPane().add(passwordField);
2019-01-06 17:06:43 +01:00
JButton btnZaloguj = new JButton("Zaloguj");
2019-01-07 00:24:10 +01:00
btnZaloguj.setFont(new Font("Tahoma", Font.PLAIN, 50));
2019-01-06 17:06:43 +01:00
btnZaloguj.addActionListener(new ActionListener() {
2019-01-08 22:18:04 +01:00
@SuppressWarnings("deprecation")
2019-01-06 17:06:43 +01:00
public void actionPerformed(ActionEvent e) {
2019-01-08 22:18:04 +01:00
try {
String query = "SELECT * FROM users WHERE RFID=? and Password=?";
PreparedStatement pst2 = conn.prepareStatement(query);
pst2.setString(1, "0000");
pst2.setString(2, passwordField.getText());
ResultSet pass = pst2.executeQuery();
int count = 0;
while (pass.next()) {
count=count+1;
}
if (count == 1) {
passwordField.setText("");
JOptionPane.showMessageDialog(PodajPin, "Zalogowano!");
PodajPin.setVisible(false);
DrukujBilet wybierzMenu = new DrukujBilet();
wybierzMenu.oknoDrukujBilet();
} else {
passwordField.setText("");
JOptionPane.showMessageDialog(PodajPin, "NIE Zalogowano!");
}
pass.close();
pst2.close();
} catch (Exception e1){
JOptionPane.showMessageDialog(null, e1);
passwordField.setText("");
}
2019-01-06 17:06:43 +01:00
}
});
2019-01-07 00:24:10 +01:00
btnZaloguj.setBounds(724, 298, 213, 69);
PodajPin.getContentPane().add(btnZaloguj);
2019-01-06 17:06:43 +01:00
}
}