Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. package com.intech.gui;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9.  
  10. import com.intech.engine.users;
  11.  
  12. import javax.swing.JTextField;
  13. import javax.swing.JLabel;
  14. import java.awt.Font;
  15. import java.awt.Color;
  16. import javax.swing.JButton;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.ActionEvent;
  19.  
  20. public class adduser extends JFrame {
  21.  
  22. private JPanel contentPane;
  23. private JTextField tusername;
  24. private JTextField tpassword;
  25. private JTextField tfullname;
  26.  
  27. /**
  28. * Launch the application.
  29. */
  30. public static void main(String[] args) {
  31. EventQueue.invokeLater(new Runnable() {
  32. public void run() {
  33. try {
  34. adduser frame = new adduser();
  35. frame.setVisible(true);
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. });
  41. }
  42.  
  43. /**
  44. * Create the frame.
  45. */
  46. public adduser() {
  47. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48. setBounds(100, 100, 450, 300);
  49. contentPane = new JPanel();
  50. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  51. setContentPane(contentPane);
  52. contentPane.setLayout(null);
  53.  
  54. JLabel label = new JLabel("User Name");
  55. label.setFont(new Font("Tahoma", Font.PLAIN, 20));
  56. label.setBounds(57, 44, 105, 25);
  57. contentPane.add(label);
  58.  
  59. JLabel label_1 = new JLabel("Password");
  60. label_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
  61. label_1.setBounds(57, 91, 105, 25);
  62. contentPane.add(label_1);
  63.  
  64. tusername = new JTextField();
  65. tusername.setFont(new Font("Tahoma", Font.PLAIN, 18));
  66. tusername.setColumns(10);
  67. tusername.setBounds(193, 44, 184, 25);
  68. contentPane.add(tusername);
  69.  
  70. tpassword = new JTextField();
  71. tpassword.setFont(new Font("Tahoma", Font.PLAIN, 18));
  72. tpassword.setColumns(10);
  73. tpassword.setBounds(193, 91, 184, 25);
  74. contentPane.add(tpassword);
  75.  
  76. JLabel err = new JLabel("");
  77. err.setForeground(Color.RED);
  78. err.setFont(new Font("Tahoma", Font.BOLD, 14));
  79. err.setBounds(57, 212, 320, 25);
  80. contentPane.add(err);
  81.  
  82. JLabel lblFullname = new JLabel("Fullname");
  83. lblFullname.setFont(new Font("Tahoma", Font.PLAIN, 20));
  84. lblFullname.setBounds(57, 133, 105, 25);
  85. contentPane.add(lblFullname);
  86.  
  87. tfullname = new JTextField();
  88. tfullname.setFont(new Font("Tahoma", Font.PLAIN, 18));
  89. tfullname.setColumns(10);
  90. tfullname.setBounds(193, 133, 184, 25);
  91. contentPane.add(tfullname);
  92.  
  93. JButton btnadd = new JButton("Add User");
  94. btnadd.addActionListener(new ActionListener() {
  95. public void actionPerformed(ActionEvent e) {
  96. if(tusername.getText().length()==0 || tpassword.getText().length()==0 || tfullname.getText().length()==0)
  97. {
  98. err.setText("username or password or fullname is missing");
  99. }
  100. else
  101. {
  102. users user=new users();
  103. user.init();
  104. user.opencon();
  105. if(user.adduser(tusername.getText().toString(), tpassword.getText().toString(),tfullname.getText().toString()))
  106. {
  107. err.setText("User inserted successfully");
  108. }
  109. else
  110. {
  111. err.setText("User not inserted");
  112. }
  113. user.closecon();
  114. }
  115.  
  116. }
  117. });
  118. btnadd.setFont(new Font("Tahoma", Font.BOLD, 18));
  119. btnadd.setBounds(57, 180, 320, 23);
  120. contentPane.add(btnadd);
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement