Guest User

Untitled

a guest
Sep 24th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /*package wholesale;
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import java.sql.*;
  10.  
  11. import javax.swing.AbstractButton;
  12. import javax.swing.Action;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JButton;
  15. import javax.swing.JFrame;
  16. import javax.swing.JLabel;
  17. import javax.swing.JOptionPane;
  18. import javax.swing.JPasswordField;
  19. import javax.swing.JTextField;
  20. import javax.swing.JWindow;
  21. import javax.swing.Timer;
  22. import javax.swing.JComboBox;
  23.  
  24. public class Wholesale {
  25.  
  26.  
  27. public static void main(String ar[]) throws SQLException
  28. {
  29. splash obj =new splash();
  30. }
  31. }
  32. class splash extends JWindow
  33. {
  34. public splash() throws SQLException
  35. {
  36. getContentPane().setBackground(Color.white);
  37. setLayout(new BorderLayout());
  38. JLabel background=new JLabel(new ImageIcon("splash.jpg"));
  39.  
  40. Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  41. setSize(428,250);
  42. // Determine the new location of the window
  43. int w = this.getSize().width;
  44. int h = this.getSize().height;
  45. int x = (dim.width-w)/2;
  46. int y = (dim.height-h)/2;
  47.  
  48. // Move the window
  49. this.setLocation(x, y);
  50.  
  51. add(background);
  52. background.setLayout(new FlowLayout());
  53. setVisible(true);
  54.  
  55. Timer timer = new Timer(10, new MyTimerActionListener());
  56. timer.start();
  57. try {
  58.  
  59. Thread.sleep(500);
  60. new login();
  61.  
  62. } catch (InterruptedException e) {
  63.  
  64. }
  65. setVisible(false);
  66.  
  67. //new login();
  68.  
  69. timer.stop();
  70.  
  71.  
  72. }
  73.  
  74. //@SuppressWarnings("serial")
  75. class MyTimerActionListener implements ActionListener
  76. {
  77. public void actionPerformed(ActionEvent actionevent)
  78. {
  79. }
  80. }
  81. }
  82.  
  83. class login extends JFrame implements ActionListener,KeyListener
  84. {
  85. JButton b1,b;
  86. JTextField t;
  87. JPasswordField p1;
  88. JLabel i,p;
  89. Connection con;
  90. Statement stmnt;
  91. ResultSet rst;
  92. public login() throws SQLException
  93. {
  94. Dimension dime = Toolkit.getDefaultToolkit().getScreenSize();
  95.  
  96. // Determine the new location of the window
  97. int ii = this.getSize().width;
  98. int c = this.getSize().height;
  99. int o = (dime.width-ii)/4;
  100. int n = (dime.height-c)/4;
  101.  
  102. getContentPane().setBackground(Color.white);
  103. setLayout(new BorderLayout());
  104. JLabel background=new JLabel(new ImageIcon("icon.jpg"));
  105.  
  106. try{
  107. //con=DriverManager.getConnection("jdbc:ucanaccess://rentcar.accdb");
  108. }
  109. catch(Exception e)
  110. {
  111. //System.out.print(e);
  112. }
  113. setLayout(null);
  114. i=new JLabel("Enter Username");
  115. i.setBounds(150,55,100,20);
  116. t=new JTextField();
  117. t.setBounds(250,55,170,20);
  118. p=new JLabel("Enter Password");
  119. p.setBounds(150,95,100,20);
  120. p1=new JPasswordField();
  121. p1.setBounds(250,95,170,20);
  122. p1.addKeyListener(this);
  123. b =new JButton ("Login");
  124. b.setBounds(250,145,70,26);
  125. b1 =new JButton ("Cancel");
  126. b1.setBounds(335,145,85,26);
  127. background.setBounds(0, 0, 143, 201);
  128. add(background);
  129. add(i);
  130. add(b1);
  131. add(p);
  132. add(t);
  133. add(p1);
  134. add(b);
  135. setSize(458,240);
  136. Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  137.  
  138. // Determine the new location of the window
  139. int w = this.getSize().width;
  140. int h = this.getSize().height;
  141. int x = (dim.width-w)/2;
  142. int y = (dim.height-h)/2;
  143.  
  144. this.setLocation(x, y);
  145. setVisible(true);
  146.  
  147. b1.addActionListener(this);
  148. b.addActionListener(this);
  149. }
  150. public void actionPerformed(ActionEvent e)
  151. {
  152.  
  153. if(e.getSource()==b1)
  154. {
  155. System.exit(0);
  156. setVisible(false);
  157. }
  158. if(e.getSource()==b)
  159. {
  160.  
  161.  
  162. try
  163. {
  164.  
  165. //stmnt=con.createStatement();
  166. //rst=stmnt.executeQuery("Select * from u_login where username='" + t.getText() + "' and password='" + p1.getText().toString() + "'");
  167.  
  168. if(rst.next())
  169. {
  170.  
  171. setVisible(false);
  172. //new carmain();
  173. }
  174. else
  175. {
  176. JOptionPane.showMessageDialog(null, "Invalid Username / Password");
  177. }
  178. }
  179.  
  180. catch(Exception e2){
  181. System.out.println(e2);
  182. }
  183.  
  184. }
  185. }
  186.  
  187. public void keyPressed(KeyEvent a)
  188. {
  189. if(a.getSource()==p1)
  190. {
  191. if(a.getKeyCode()==10)
  192. {
  193. try
  194. {
  195.  
  196. stmnt=con.createStatement();
  197. rst=stmnt.executeQuery("Select * from u_login where username='" + t.getText() + "' and password='" + p1.getText().toString() + "'");
  198.  
  199. if(rst.next())
  200. {
  201. setVisible(false);
  202. new carmain();
  203. }
  204. else
  205. {
  206. JOptionPane.showMessageDialog(null, "Invalid Username / Password");
  207. }
  208. }
  209.  
  210. catch(Exception e2){
  211. System.out.println(e2);
  212. }
  213. }
  214. else
  215. {
  216. //JOptionPane.showMessageDialog(null,"bye");
  217. }
  218. }
  219. }
  220.  
  221. public void keyReleased(KeyEvent a) {
  222.  
  223.  
  224. }
  225.  
  226. public void keyTyped(KeyEvent a) {
  227.  
  228.  
  229. }
  230. }
  231. */
Add Comment
Please, Sign In to add comment