Guest User

Untitled

a guest
Feb 13th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. package loginapp;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.*;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8.  
  9. public class Login_App extends JFrame {
  10.  
  11. public static void main(String[] args) {
  12.  
  13.  
  14. JFrame frame = new JFrame("Mo Garage Login");
  15. //frame setup
  16. frame.setSize(500, 600);
  17. frame.setVisible(true);
  18.  
  19. //Label and Text boxes
  20.  
  21. JLabel usernamelbl = new JLabel("Username");
  22. usernamelbl.setBounds(100,100, 100,20);
  23. frame.add(usernamelbl);
  24. frame.setLayout(null);
  25. frame.setVisible(true);
  26.  
  27.  
  28. JLabel passwordlbl = new JLabel("Password");
  29. passwordlbl.setBounds(100,200,100,20);
  30. frame.add(passwordlbl);
  31. frame.setLayout(null);
  32. frame.setVisible(true);
  33.  
  34.  
  35.  
  36. JTextField username = new JTextField();
  37. username.setBounds(200,100,100,20);
  38. frame.add(username);
  39. frame.setLayout(null);//using no layout managers
  40. frame.setVisible(true);
  41.  
  42.  
  43.  
  44. JPasswordField pass = new JPasswordField();
  45. pass.setBounds(200,200,100,20);
  46. frame.add(pass);
  47. frame.setLayout(null);
  48. frame.setVisible(true);
  49.  
  50.  
  51.  
  52. //Buttons
  53.  
  54. JButton log=new JButton("Login");
  55. log.setBounds(200,500,100,40);
  56.  
  57. frame.add(log);
  58. frame.setLayout(null);//using no layout managers
  59. frame.setVisible(true);
  60. //login button action
  61. log.addActionListener(new ActionListener() {
  62. public void actionPerformed (ActionEvent arg0) {
  63.  
  64. String uname=username.getText();
  65. String passwd=pass.getText();
  66.  
  67. if (uname.equals("") && passwd.equals(""))
  68. {
  69. JOptionPane.showMessageDialog(frame, "Login Successfull");
  70.  
  71. MainMenu mainmenu =new MainMenu();
  72.  
  73. mainmenu.setVisible(true);
  74.  
  75. frame.setVisible(false);
  76.  
  77. }
  78. else {
  79. JOptionPane.showMessageDialog(frame, "Incorrect Credentials");
  80. }
  81.  
  82.  
  83. }
  84. }
  85. );
  86.  
  87. JButton clear=new JButton("Clear");
  88. clear.setBounds(50,500,100,40);
  89.  
  90. frame.add(clear);
  91. frame.setLayout(null);
  92. frame.setVisible(true);
  93. //clear button action
  94.  
  95. clear.addActionListener(new ActionListener() {
  96.  
  97. public void actionPerformed(ActionEvent arg0) {
  98.  
  99. username.setText("");
  100. pass.setText("");
  101.  
  102. }
  103. }
  104. );
  105.  
  106. }
  107.  
  108.  
  109. }
  110.  
  111. package loginapp;
  112. import java.awt.event.ActionEvent;
  113. import java.awt.event.ActionListener;
  114. import javax.swing.*;
  115.  
  116.  
  117. public class MainMenu extends JFrame {
  118.  
  119. public static void main(String[] args) {
  120. JFrame frame= new JFrame("Main Menu");
  121. frame.setSize(500,600);
  122. frame.setVisible(true);
  123.  
  124. JButton client= new JButton("Add new Client");
  125. client.setBounds(200,100,120,30);
  126. frame.add(client);
  127. frame.setLayout(null);
  128. frame.setVisible(true);
  129.  
  130. JButton Mod= new JButton("Update Database");
  131. Mod.setBounds(190,200,140,30);
  132. frame.add(Mod);
  133. frame.setLayout(null);
  134. frame.setVisible(true);
  135.  
  136. JButton info= new JButton("Information");
  137. info.setBounds(200,300,120,30);
  138. frame.add(info);
  139. frame.setLayout(null);
  140. frame.setVisible(true);
  141.  
  142. JButton exit= new JButton("Quit");
  143. exit.setBounds(200,400,120,30);
  144. frame.add(exit);
  145. frame.setLayout(null);
  146. frame.setVisible(true);
  147. }
  148. }
Add Comment
Please, Sign In to add comment