Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.EventQueue;
  3. import java.awt.Font;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.MouseAdapter;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.awt.font.TextAttribute;
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.ResultSet;
  13. import java.sql.Statement;
  14. import java.util.Map;
  15.  
  16. import javax.swing.ButtonGroup;
  17. import javax.swing.GroupLayout.Group;
  18. import javax.swing.JButton;
  19. import javax.swing.JComboBox;
  20. import javax.swing.JFrame;
  21. import javax.swing.JLabel;
  22. import javax.swing.JTextField;
  23. import javax.swing.JRadioButton;
  24.  
  25. public class Controller extends JFrame implements ActionListener{
  26.  
  27. public JLabel lblController;
  28. private JLabel doc3, doc4, doc5, lblError;
  29. private JLabel doc_name3, doc_name4, doc_name5;
  30. private JRadioButton rbY3, rbY4, rbY5, rbN3, rbN4, rbN5;
  31. private String selectedTemplate;
  32. private String path = "jdbc:mysql://localhost:8889/DocumentsWork";
  33. private Connection connection;
  34. private Statement statement;
  35. private JTextField username;
  36.  
  37. public static void main(String[] args) {
  38. EventQueue.invokeLater(new Runnable() {
  39. public void run() {
  40. try {
  41. Controller frame = new Controller();
  42. frame.setVisible(true);
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. });
  48. }
  49.  
  50. public Controller() {
  51. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52. setBounds(100, 100, 500, 300);
  53. getContentPane().setLayout(null);
  54.  
  55. JLabel controllerLabel = new JLabel("Контролер:");
  56. controllerLabel.setBounds(12, 10, 100, 30);
  57. getContentPane().add(controllerLabel);
  58.  
  59. lblController = new JLabel();
  60. lblController.setBounds(85, 10, 169, 30);
  61. getContentPane().add(lblController);
  62.  
  63. JLabel userLabel = new JLabel("Пользователь:");
  64. userLabel.setBounds(12,40, 100, 30);
  65. getContentPane().add(userLabel);
  66.  
  67. JLabel patternLabel = new JLabel("Шаблон:");
  68. patternLabel.setBounds(244, 9, 65, 30);
  69. getContentPane().add(patternLabel);
  70.  
  71. username = new JTextField();
  72. username.setBounds(105, 40, 127, 30);
  73. getContentPane().add(username);
  74.  
  75. JButton button = new JButton("Получить данные");
  76. button.addActionListener(new ActionListener() {
  77. public void actionPerformed(ActionEvent e) {
  78. GetData();
  79. }
  80. });
  81. button.setBounds(280, 41, 138, 31);
  82. getContentPane().add(button);
  83.  
  84. JLabel doc1 = new JLabel("Паспорт:");
  85. doc1.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  86. doc1.setBounds(12, 90, 100, 30);
  87. getContentPane().add(doc1);
  88.  
  89. JLabel doc2 = new JLabel("Заявление:");
  90. doc2.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  91. doc2.setBounds(12, 115, 100, 30);
  92. getContentPane().add(doc2);
  93.  
  94. doc3 = new JLabel("СНИЛС:");
  95. doc3.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  96. doc3.setBounds(12, 140, 100, 30);
  97. getContentPane().add(doc3);
  98.  
  99. doc4 = new JLabel("Регистрация:");
  100. doc4.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  101. doc4.setBounds(12, 165, 100, 30);
  102. getContentPane().add(doc4);
  103.  
  104. doc5 = new JLabel("Полис:");
  105. doc5.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  106. doc5.setBounds(12, 190, 100, 30);
  107. getContentPane().add(doc5);
  108.  
  109. MouseListener hyperLink = new MouseListener() {
  110. public void mouseClicked(MouseEvent e) {}
  111. public void mouseEntered(MouseEvent e)
  112. {
  113. Font font = e.getComponent().getFont();
  114. Map attributes = font.getAttributes();
  115. e.getComponent().setForeground(Color.BLUE);
  116. attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  117. e.getComponent().setFont(font.deriveFont(attributes));
  118. }
  119. public void mouseExited(MouseEvent e)
  120. {
  121. Font font = e.getComponent().getFont();
  122. Map attributes = font.getAttributes();
  123. e.getComponent().setForeground(Color.BLACK);
  124. attributes.put(TextAttribute.UNDERLINE, -1);
  125. e.getComponent().setFont(font.deriveFont(attributes));
  126. }
  127. public void mousePressed(MouseEvent e) {}
  128. public void mouseReleased(MouseEvent e) {}
  129. };
  130.  
  131. JLabel doc_name1 = new JLabel("Документ отсутствует");
  132. doc_name1.setFont(new Font("Lucida Grande",Font.ITALIC, 13));
  133. doc_name1.setBounds(110, 90, 200, 30);
  134. Font font = doc_name1.getFont();
  135. Map attributes = font.getAttributes();
  136. doc_name1.addMouseListener(hyperLink);
  137. getContentPane().add(doc_name1);
  138.  
  139. JLabel doc_name2 = new JLabel("Документ отсутствует");
  140. doc_name2.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
  141. doc_name2.setBounds(110, 115, 200, 30);
  142. doc_name2.addMouseListener(hyperLink);
  143. getContentPane().add(doc_name2);
  144.  
  145. doc_name3 = new JLabel("Документ отсутствует");
  146. doc_name3.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
  147. doc_name3.setBounds(110, 140, 200, 30);
  148. doc_name3.addMouseListener(hyperLink);
  149. getContentPane().add(doc_name3);
  150.  
  151. doc_name4 = new JLabel("Документ отсутствует");
  152. doc_name4.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
  153. doc_name4.setBounds(110, 165, 200, 30);
  154. doc_name4.addMouseListener(hyperLink);
  155. getContentPane().add(doc_name4);
  156.  
  157. doc_name5 = new JLabel("Документ отсутствует");
  158. doc_name5.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
  159. doc_name5.setBounds(110, 190, 200, 30);
  160. doc_name5.addMouseListener(hyperLink);
  161. getContentPane().add(doc_name5);
  162.  
  163. JLabel isRight = new JLabel("Верно?");
  164. isRight.setBounds(379, 69, 50, 30);
  165. getContentPane().add(isRight);
  166.  
  167. JButton btnAddAll = new JButton("Отправить отчет");
  168. btnAddAll.setBounds(165, 235, 170, 25);
  169. getContentPane().add(btnAddAll);
  170.  
  171. JRadioButton rbY1 = new JRadioButton("Да");
  172. rbY1.setBounds(335, 90, 50, 25);
  173. getContentPane().add(rbY1);
  174.  
  175. JRadioButton rbY2 = new JRadioButton("Да");
  176. rbY2.setBounds(335, 115, 50, 25);
  177. getContentPane().add(rbY2);
  178.  
  179. rbY3 = new JRadioButton("Да");
  180. rbY3.setBounds(335, 140, 50, 25);
  181. getContentPane().add(rbY3);
  182.  
  183. rbY4 = new JRadioButton("Да");
  184. rbY4.setBounds(335, 165, 50, 25);
  185. getContentPane().add(rbY4);
  186.  
  187. rbY5 = new JRadioButton("Да");
  188. rbY5.setBounds(335, 190, 50, 25);
  189. getContentPane().add(rbY5);
  190.  
  191. JRadioButton rbN1 = new JRadioButton("Нет");
  192. rbN1.setBounds(410, 92, 57, 25);
  193. getContentPane().add(rbN1);
  194.  
  195. JRadioButton rbN2 = new JRadioButton("Нет");
  196. rbN2.setBounds(410, 115, 57, 25);
  197. getContentPane().add(rbN2);
  198.  
  199. rbN3 = new JRadioButton("Нет");
  200. rbN3.setBounds(410, 140, 57, 25);
  201. getContentPane().add(rbN3);
  202.  
  203. rbN4 = new JRadioButton("Нет");
  204. rbN4.setBounds(410, 165, 57, 25);
  205. getContentPane().add(rbN4);
  206.  
  207. rbN5 = new JRadioButton("Нет");
  208. rbN5.setBounds(410, 190, 57, 25);
  209. getContentPane().add(rbN5);
  210.  
  211. ButtonGroup bg1 = new ButtonGroup();
  212. bg1.add(rbY1);
  213. bg1.add(rbN1);
  214.  
  215. ButtonGroup bg2 = new ButtonGroup();
  216. bg2.add(rbY2);
  217. bg2.add(rbN2);
  218.  
  219. ButtonGroup bg3 = new ButtonGroup();
  220. bg3.add(rbY3);
  221. bg3.add(rbN3);
  222.  
  223. ButtonGroup bg4 = new ButtonGroup();
  224. bg4.add(rbY4);
  225. bg4.add(rbN4);
  226.  
  227. ButtonGroup bg5 = new ButtonGroup();
  228. bg5.add(rbY5);
  229. bg5.add(rbN5);
  230.  
  231. String[] currentTemplate = { "Дарственная", "Бракосочетание", "Страхование жизни" };
  232. JComboBox comboBox = new JComboBox(currentTemplate);
  233. comboBox.setSelectedIndex(0);
  234. selectedTemplate = comboBox.getSelectedItem().toString();
  235. SetVisibility();
  236. comboBox.addActionListener(new ActionListener(){
  237. public void actionPerformed(ActionEvent e)
  238. {
  239. selectedTemplate = comboBox.getSelectedItem().toString();
  240. SetVisibility();
  241. }
  242. });
  243. comboBox.setBounds(322, 10, 138, 30);
  244. getContentPane().add(comboBox);
  245.  
  246. JButton btnExit = new JButton("Выход");
  247. btnExit.addActionListener(new ActionListener() {
  248. public void actionPerformed(ActionEvent e) {
  249. System.exit(0);
  250. }
  251. });
  252. btnExit.setBounds(408, 243, 86, 29);
  253. getContentPane().add(btnExit);
  254.  
  255. lblError = new JLabel("Пользователь отсутствует");
  256. lblError.setBounds(12, 73, 180, 16);
  257. lblError.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  258. lblError.setForeground(Color.RED);
  259. lblError.setVisible(false);
  260. getContentPane().add(lblError);
  261. }
  262.  
  263. @Override
  264. public void actionPerformed(ActionEvent arg0) {
  265. // TODO Auto-generated method stub
  266.  
  267. }
  268.  
  269. public void SetVisibility()
  270. {
  271. if (selectedTemplate == "Дарственная")
  272. {
  273. doc3.setVisible(false);
  274. doc4.setVisible(false);
  275. doc5.setVisible(false);
  276. doc_name3.setVisible(false);
  277. doc_name4.setVisible(false);
  278. doc_name5.setVisible(false);
  279. rbY3.setVisible(false);
  280. rbY4.setVisible(false);
  281. rbY5.setVisible(false);
  282. rbN3.setVisible(false);
  283. rbN4.setVisible(false);
  284. rbN5.setVisible(false);
  285. }
  286. else if (selectedTemplate == "Страхование жизни")
  287. {
  288. doc3.setVisible(true);
  289. doc4.setVisible(true);
  290. doc5.setVisible(true);
  291. doc_name3.setVisible(true);
  292. doc_name4.setVisible(true);
  293. doc_name5.setVisible(true);
  294. rbY3.setVisible(true);
  295. rbY4.setVisible(true);
  296. rbY5.setVisible(true);
  297. rbN3.setVisible(true);
  298. rbN4.setVisible(true);
  299. rbN5.setVisible(true);
  300. }
  301. else if (selectedTemplate == "Бракосочетание")
  302. {
  303. doc3.setVisible(true);
  304. doc4.setVisible(true);
  305. doc5.setVisible(false);
  306. doc_name3.setVisible(true);
  307. doc_name4.setVisible(true);
  308. doc_name5.setVisible(false);
  309. rbY3.setVisible(true);
  310. rbN3.setVisible(true);
  311. rbY4.setVisible(true);
  312. rbN4.setVisible(true);
  313. rbY5.setVisible(false);
  314. rbN5.setVisible(false);
  315. }
  316. }
  317.  
  318. public void GetData()
  319. {
  320. try
  321. {
  322. Class.forName("com.mysql.cj.jdbc.Driver");
  323. connection = DriverManager.getConnection(path, "admin", "");
  324. statement = connection.createStatement();
  325. String sql = "Select * from Users where Username='" + username.getText().toString() + "' and Type='User'";
  326. ResultSet rs = statement.executeQuery(sql);
  327. if (!rs.next())
  328. lblError.setVisible(true);
  329. else
  330. lblError.setVisible(false);
  331. connection.close();
  332. }
  333. catch(Exception e)
  334. {
  335. System.out.print(e);
  336. }
  337. }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement