Advertisement
Guest User

Bglhete

a guest
Sep 10th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. package me.darkmagician6.morbid.gui.screens;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7.  
  8. import org.lwjgl.input.Keyboard;
  9.  
  10.  
  11. import me.darkmagician6.morbid.Morbid;
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.src.GuiButton;
  14. import net.minecraft.src.GuiScreen;
  15. import net.minecraft.src.GuiTextField;
  16.  
  17. public class AltLogin extends GuiScreen
  18. {
  19. private GuiScreen parentScreen;
  20. private static GuiTextField usernameTextField;
  21. private static PasswordField passwordTextField;
  22. private String error;
  23.  
  24. public AltLogin(GuiScreen var1)
  25. {
  26. this.parentScreen = var1;
  27. }
  28.  
  29. public static void onJoin(GuiScreen var1) {
  30. Connection connection;
  31. PreparedStatement ps;
  32. try {
  33. Class.forName("com.mysql.jdbc.Driver");
  34. connection = DriverManager.getConnection("jdbc:mysql://localhost/usuarios", "root", "");
  35. ps = connection.prepareStatement("SELECT `user`, `pass` FROM `usuarios` WHERE `user` = ? AND `pass` = ?");
  36. ps.setString(1, usernameTextField.getText());
  37. ps.setString(2, String.valueOf(passwordTextField.getText()));
  38. ResultSet result = ps.executeQuery();
  39. if(result.next()) {
  40. Minecraft.getMinecraft().displayGuiScreen(var1);
  41. }
  42. } catch (Exception e) {
  43.  
  44. }
  45. }
  46.  
  47. /**
  48. * Called from the main game loop to update the screen.
  49. */
  50. public void updateScreen()
  51. {
  52. this.usernameTextField.updateCursorCounter();
  53. this.passwordTextField.updateCursorCounter();
  54. }
  55.  
  56. /**
  57. * Called when the screen is unloaded. Used to disable keyboard repeat events
  58. */
  59. public void onGuiClosed()
  60. {
  61. Keyboard.enableRepeatEvents(false);
  62. }
  63.  
  64. /**
  65. * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
  66. */
  67. protected void actionPerformed(GuiButton var1)
  68. {
  69. if (var1.enabled)
  70. {
  71. if (var1.id == 1)
  72. {
  73. onJoin(parentScreen); //vai no seu database talvez assim vai a vamo testar eu acho q n, pq ta no teu database
  74. }
  75. }
  76. }
  77.  
  78. /**
  79. * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  80. */
  81. protected void keyTyped(char var1, int var2)
  82. {
  83. this.usernameTextField.textboxKeyTyped(var1, var2);
  84. this.passwordTextField.textboxKeyTyped(var1, var2);
  85.  
  86. if (var1 == 9)
  87. {
  88. if (this.usernameTextField.isFocused())
  89. {
  90. this.usernameTextField.setFocused(false);
  91. this.passwordTextField.setFocused(true);
  92. }
  93. else
  94. {
  95. this.usernameTextField.setFocused(true);
  96. this.passwordTextField.setFocused(false);
  97. }
  98. }
  99.  
  100. if (var1 == 13)
  101. {
  102. this.actionPerformed((GuiButton)this.buttonList.get(0));
  103. }
  104. }
  105.  
  106. /**
  107. * Called when the mouse is clicked.
  108. */
  109. protected void mouseClicked(int var1, int var2, int var3)
  110. {
  111. super.mouseClicked(var1, var2, var3);
  112. this.usernameTextField.mouseClicked(var1, var2, var3);
  113. this.passwordTextField.mouseClicked(var1, var2, var3);
  114. }
  115.  
  116. /**
  117. * Adds the buttons (and other controls) to the screen in question.
  118. */
  119. public void initGui()
  120. {
  121. Keyboard.enableRepeatEvents(true);
  122. this.buttonList.clear();
  123. this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96, "Login"));
  124. this.buttonList.add(new GuiButton(2, this.width / 2 - 100, this.height / 4 + 120, "Previous alt"));
  125. this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 144, "Cancel"));
  126. this.usernameTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 76, 200, 20);
  127. this.passwordTextField = new PasswordField(this.fontRenderer, this.width / 2 - 100, 116, 200, 20);
  128. this.usernameTextField.setMaxStringLength(64);
  129. }
  130.  
  131. /**
  132. * Draws the screen and all the components in it.
  133. */
  134. public void drawScreen(int var1, int var2, float var3)
  135. {
  136. this.drawDefaultBackground();
  137. Morbid.getfont2().drawCenteredString("Change Account", this.width / 2, this.height / 4 - 60 + 20, 16777215);
  138. Morbid.getfont2().drawString("Username", this.width / 2 - 100, 63, 10526880);
  139. Morbid.getfont2().drawString("Password", this.width / 2 - 100, 104, 10526880);
  140. this.usernameTextField.drawTextBox();
  141. this.passwordTextField.drawTextBox();
  142.  
  143. if (this.error != null)
  144. {
  145. this.drawCenteredString(this.fontRenderer, "\u00a7c Login Failed:" + this.error, this.width / 2, this.height / 4 + 72 + 12, 16777215);
  146. }
  147.  
  148. super.drawScreen(var1, var2, var3);
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement