package intro;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.*;
@SuppressWarnings("unused")
public class Intro extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField textField;
private JPasswordField upass;
/**
* Create the panel.
*/
public Intro() {
setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(10, 11, 580, 30);
add(panel);
JLabel lblWelcomeToThe = new JLabel("Welcome to the TotalBuild TMS");
panel.add(lblWelcomeToThe);
JLabel lblMinecraftUsername = new JLabel("Minecraft Username");
lblMinecraftUsername.setFont(new Font("Tahoma", Font.PLAIN, 11));
lblMinecraftUsername.setBounds(20, 52, 96, 14);
add(lblMinecraftUsername);
JLabel lblPassword = new JLabel("Password");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 11));
lblPassword.setBounds(20, 77, 96, 14);
add(lblPassword);
textField = new JTextField();
textField.setBounds(126, 49, 120, 20);
add(textField);
textField.setColumns(10);
upass = new JPasswordField();
upass.setBounds(126, 74, 120, 20);
add(upass);
JButton btnNewButton = new JButton("Login");
btnNewButton.isDefaultCapable();
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String user = textField.getText();
String pass = upass.getText();
Connection con = null;
String url = "jdbc:mysql://mySQL_ADDRESS:PORT/";
String driver = "com.mysql.jdbc.Driver";
String db = "DB_NAME";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, "mySQL_USER", "mySQL_PASS");
try{
Statement st = con.createStatement();
st.executeQuery("SELECT * FROM ustep1 WHERE user='" + user + "'");
ResultSet rs = st.getResultSet ();
String dbpass = "";
while (rs.next ())
{
dbpass = rs.getString("pass");
}
if(dbpass==pass){
String result = "Welcome, " + user + ". You entered the correct login info.";
JOptionPane.showMessageDialog(null, result);
} else {
String result2 = "Sorry " + user + ", You entered incorrect login info." + dbpass;
JOptionPane.showMessageDialog(null, result2);
}
}
catch (SQLException s){
System.err.println("SQL Error!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 11));
btnNewButton.setBounds(30, 102, 89, 23);
add(btnNewButton);
JButton btnRegister = new JButton("Register");
btnRegister.setFont(new Font("Tahoma", Font.PLAIN, 11));
btnRegister.setEnabled(false);
btnRegister.setBounds(136, 102, 89, 23);
add(btnRegister);
}
private void setDefaultButton(JButton btnNewButton) {
// TODO Auto-generated method stub
}
}