Advertisement
Guest User

Untitled

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