Advertisement
fptf8fpt2018

Untitled

Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.45 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 Bai3;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11. *
  12. * @author DELL
  13. */
  14. public class Bai3 extends javax.swing.JFrame {
  15.  
  16. /**
  17. * Creates new form Bai3
  18. */
  19. public Bai3() {
  20. initComponents();
  21. jPanel1.setVisible(false);
  22. setLocationRelativeTo(this);
  23. setResizable(false);
  24. }
  25.  
  26. /**
  27. * This method is called from within the constructor to initialize the form.
  28. * WARNING: Do NOT modify this code. The content of this method is always
  29. * regenerated by the Form Editor.
  30. */
  31. @SuppressWarnings("unchecked")
  32. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  33. private void initComponents() {
  34.  
  35. jPanel1 = new javax.swing.JPanel();
  36. jLabel1 = new javax.swing.JLabel();
  37. jLabel2 = new javax.swing.JLabel();
  38. jTextField1 = new javax.swing.JTextField();
  39. jCheckBox1 = new javax.swing.JCheckBox();
  40. jLabel3 = new javax.swing.JLabel();
  41. jLabel4 = new javax.swing.JLabel();
  42. jLabel5 = new javax.swing.JLabel();
  43. jButton1 = new javax.swing.JButton();
  44. jPasswordField1 = new javax.swing.JPasswordField();
  45. jScrollPane1 = new javax.swing.JScrollPane();
  46. jTextArea1 = new javax.swing.JTextArea();
  47. jMenuBar1 = new javax.swing.JMenuBar();
  48. jMenu1 = new javax.swing.JMenu();
  49. jMenuItem1 = new javax.swing.JMenuItem();
  50.  
  51. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  52.  
  53. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  54.  
  55. jLabel1.setText("User name : ");
  56.  
  57. jLabel2.setText("Password : ");
  58.  
  59. jCheckBox1.setText("Math case");
  60. jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
  61. public void actionPerformed(java.awt.event.ActionEvent evt) {
  62. jCheckBox1ActionPerformed(evt);
  63. }
  64. });
  65.  
  66. jLabel3.setText("Username must be TrieuDD");
  67.  
  68. jLabel4.setText("Password must be trieuDZ");
  69.  
  70. jLabel5.setText("Dont discriminate Upper and Lower Case");
  71.  
  72. jButton1.setText("Log in");
  73. jButton1.addActionListener(new java.awt.event.ActionListener() {
  74. public void actionPerformed(java.awt.event.ActionEvent evt) {
  75. jButton1ActionPerformed(evt);
  76. }
  77. });
  78.  
  79. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  80. jPanel1.setLayout(jPanel1Layout);
  81. jPanel1Layout.setHorizontalGroup(
  82. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  83. .addGroup(jPanel1Layout.createSequentialGroup()
  84. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  85. .addComponent(jButton1)
  86. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  87. .addGroup(jPanel1Layout.createSequentialGroup()
  88. .addGap(23, 23, 23)
  89. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  90. .addComponent(jLabel1)
  91. .addComponent(jLabel2)))
  92. .addGroup(jPanel1Layout.createSequentialGroup()
  93. .addContainerGap()
  94. .addComponent(jCheckBox1))
  95. .addGroup(jPanel1Layout.createSequentialGroup()
  96. .addContainerGap()
  97. .addComponent(jLabel5))))
  98. .addGap(26, 26, 26)
  99. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100. .addComponent(jTextField1)
  101. .addGroup(jPanel1Layout.createSequentialGroup()
  102. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  103. .addComponent(jLabel4)
  104. .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  105. .addComponent(jPasswordField1))
  106. .addGap(0, 0, Short.MAX_VALUE))))
  107. );
  108. jPanel1Layout.setVerticalGroup(
  109. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addGroup(jPanel1Layout.createSequentialGroup()
  111. .addGap(32, 32, 32)
  112. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  113. .addComponent(jLabel1)
  114. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  115. .addGap(50, 50, 50)
  116. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  117. .addComponent(jLabel2)
  118. .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  119. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
  120. .addComponent(jButton1)
  121. .addGap(18, 18, 18)
  122. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  123. .addComponent(jCheckBox1)
  124. .addComponent(jLabel3))
  125. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  126. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  127. .addComponent(jLabel4)
  128. .addComponent(jLabel5))
  129. .addContainerGap())
  130. );
  131.  
  132. jTextArea1.setColumns(20);
  133. jTextArea1.setRows(5);
  134. jScrollPane1.setViewportView(jTextArea1);
  135.  
  136. jMenu1.setText("File");
  137.  
  138. jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
  139. jMenuItem1.setText("jMenuItem1");
  140. jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  141. public void actionPerformed(java.awt.event.ActionEvent evt) {
  142. jMenuItem1ActionPerformed(evt);
  143. }
  144. });
  145. jMenu1.add(jMenuItem1);
  146.  
  147. jMenuBar1.add(jMenu1);
  148.  
  149. setJMenuBar(jMenuBar1);
  150.  
  151. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  152. getContentPane().setLayout(layout);
  153. layout.setHorizontalGroup(
  154. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  155. .addGroup(layout.createSequentialGroup()
  156. .addGap(41, 41, 41)
  157. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  158. .addComponent(jScrollPane1)
  159. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  160. .addContainerGap(114, Short.MAX_VALUE))
  161. );
  162. layout.setVerticalGroup(
  163. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  164. .addGroup(layout.createSequentialGroup()
  165. .addGap(70, 70, 70)
  166. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  167. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
  168. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
  169. );
  170.  
  171. pack();
  172. }// </editor-fold>
  173.  
  174. private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
  175. jPanel1.setVisible(true);
  176. }
  177.  
  178. private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
  179. // TODO add your handling code here:
  180. }
  181.  
  182. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  183. if (jTextField1.getText().length() == 0 || jTextField1.getText() == null) {
  184. JOptionPane.showMessageDialog(null, "Account not blank !!");
  185. } else if (jTextField1.getText().equals("trieuDD")) {
  186. if (jPasswordField1.getText().length() == 0 || jPasswordField1 == null) {
  187. JOptionPane.showMessageDialog(null, "Password not blank !!!");
  188. } else if (jCheckBox1.isSelected()) {
  189. if (jPasswordField1.getText().equals("trieuDZ")) {
  190. jTextArea1.setText("Welcome " + jTextField1.getText());
  191. } else {
  192. jPasswordField1.requestFocus();
  193. jPasswordField1.setText("");
  194. JOptionPane.showMessageDialog(null, "Wrong password");
  195. }
  196. } else if (jPasswordField1.getText().equalsIgnoreCase("trieuDZ")) {
  197. jTextArea1.setText("Welcome " + jTextField1.getText());
  198. } else {
  199. jPasswordField1.requestFocus();
  200. jPasswordField1.setText("");
  201. JOptionPane.showMessageDialog(null, "Wrong password");
  202. }
  203. } else {
  204. jTextField1.setText("");
  205. jTextField1.requestFocus();
  206. JOptionPane.showMessageDialog(null, "Account has not existed !!");
  207. }
  208. }
  209.  
  210. /**
  211. * @param args the command line arguments
  212. */
  213. public static void main(String args[]) {
  214. /* Set the Nimbus look and feel */
  215. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  216. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  217. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  218. */
  219. try {
  220. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  221. if ("Nimbus".equals(info.getName())) {
  222. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  223. break;
  224. }
  225. }
  226. } catch (ClassNotFoundException ex) {
  227. java.util.logging.Logger.getLogger(Bai3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  228. } catch (InstantiationException ex) {
  229. java.util.logging.Logger.getLogger(Bai3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  230. } catch (IllegalAccessException ex) {
  231. java.util.logging.Logger.getLogger(Bai3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  232. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  233. java.util.logging.Logger.getLogger(Bai3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  234. }
  235. //</editor-fold>
  236.  
  237. /* Create and display the form */
  238. java.awt.EventQueue.invokeLater(new Runnable() {
  239. public void run() {
  240. new Bai3().setVisible(true);
  241. }
  242. });
  243. }
  244.  
  245. // Variables declaration - do not modify
  246. private javax.swing.JButton jButton1;
  247. private javax.swing.JCheckBox jCheckBox1;
  248. private javax.swing.JLabel jLabel1;
  249. private javax.swing.JLabel jLabel2;
  250. private javax.swing.JLabel jLabel3;
  251. private javax.swing.JLabel jLabel4;
  252. private javax.swing.JLabel jLabel5;
  253. private javax.swing.JMenu jMenu1;
  254. private javax.swing.JMenuBar jMenuBar1;
  255. private javax.swing.JMenuItem jMenuItem1;
  256. private javax.swing.JPanel jPanel1;
  257. private javax.swing.JPasswordField jPasswordField1;
  258. private javax.swing.JScrollPane jScrollPane1;
  259. private javax.swing.JTextArea jTextArea1;
  260. private javax.swing.JTextField jTextField1;
  261. // End of variables declaration
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement