Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.font.TextAttribute;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.Enumeration;
- import java.util.Map;
- import javax.swing.ButtonGroup;
- import javax.swing.GroupLayout.Group;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- public class Controller extends JFrame implements ActionListener{
- public JLabel lblController;
- private JLabel doc3, doc4, doc5, lblError;
- private JLabel doc_name3, doc_name4, doc_name5;
- private JRadioButton rbY1, rbY2, rbY3, rbY4, rbY5, rbN3, rbN4, rbN5;
- private String selectedTemplate;
- private String path = "jdbc:mysql://localhost:3307/kekes";
- private Connection connection;
- private Statement statement;
- private JTextField username;
- private boolean[] booleans;
- private JRadioButton[] buttons = {rbY1, rbY2, rbY3, rbY4, rbY5};
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Controller frame = new Controller();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Controller() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 500, 300);
- getContentPane().setLayout(null);
- JLabel controllerLabel = new JLabel("Контролер:");
- controllerLabel.setBounds(12, 10, 100, 30);
- getContentPane().add(controllerLabel);
- lblController = new JLabel();
- lblController.setBounds(85, 10, 169, 30);
- getContentPane().add(lblController);
- JLabel userLabel = new JLabel("Пользователь:");
- userLabel.setBounds(12,40, 100, 30);
- getContentPane().add(userLabel);
- JLabel patternLabel = new JLabel("Шаблон:");
- patternLabel.setBounds(244, 9, 65, 30);
- getContentPane().add(patternLabel);
- username = new JTextField();
- username.setBounds(105, 40, 127, 30);
- getContentPane().add(username);
- JButton button = new JButton("Получить данные");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- GetData();
- }
- });
- button.setBounds(280, 41, 138, 31);
- getContentPane().add(button);
- JLabel doc1 = new JLabel("Паспорт:");
- doc1.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc1.setBounds(12, 90, 100, 30);
- getContentPane().add(doc1);
- JLabel doc2 = new JLabel("Заявление:");
- doc2.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc2.setBounds(12, 115, 100, 30);
- getContentPane().add(doc2);
- doc3 = new JLabel("СНИЛС:");
- doc3.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc3.setBounds(12, 140, 100, 30);
- getContentPane().add(doc3);
- doc4 = new JLabel("Регистрация:");
- doc4.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc4.setBounds(12, 165, 100, 30);
- getContentPane().add(doc4);
- doc5 = new JLabel("Полис:");
- doc5.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc5.setBounds(12, 190, 100, 30);
- getContentPane().add(doc5);
- MouseListener hyperLink = new MouseListener() {
- public void mouseClicked(MouseEvent e) {}
- public void mouseEntered(MouseEvent e)
- {
- Font font = e.getComponent().getFont();
- Map attributes = font.getAttributes();
- e.getComponent().setForeground(Color.BLUE);
- attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
- e.getComponent().setFont(font.deriveFont(attributes));
- }
- public void mouseExited(MouseEvent e)
- {
- Font font = e.getComponent().getFont();
- Map attributes = font.getAttributes();
- e.getComponent().setForeground(Color.BLACK);
- attributes.put(TextAttribute.UNDERLINE, -1);
- e.getComponent().setFont(font.deriveFont(attributes));
- }
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
- };
- JLabel doc_name1 = new JLabel("Документ отсутствует");
- doc_name1.setFont(new Font("Lucida Grande",Font.ITALIC, 13));
- doc_name1.setBounds(110, 90, 200, 30);
- Font font = doc_name1.getFont();
- Map attributes = font.getAttributes();
- doc_name1.addMouseListener(hyperLink);
- getContentPane().add(doc_name1);
- JLabel doc_name2 = new JLabel("Документ отсутствует");
- doc_name2.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name2.setBounds(110, 115, 200, 30);
- doc_name2.addMouseListener(hyperLink);
- getContentPane().add(doc_name2);
- doc_name3 = new JLabel("Документ отсутствует");
- doc_name3.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name3.setBounds(110, 140, 200, 30);
- doc_name3.addMouseListener(hyperLink);
- getContentPane().add(doc_name3);
- doc_name4 = new JLabel("Документ отсутствует");
- doc_name4.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name4.setBounds(110, 165, 200, 30);
- doc_name4.addMouseListener(hyperLink);
- getContentPane().add(doc_name4);
- doc_name5 = new JLabel("Документ отсутствует");
- doc_name5.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name5.setBounds(110, 190, 200, 30);
- doc_name5.addMouseListener(hyperLink);
- getContentPane().add(doc_name5);
- JLabel isRight = new JLabel("Верно?");
- isRight.setBounds(379, 69, 50, 30);
- getContentPane().add(isRight);
- JButton btnAddAll = new JButton("Отправить отчет");
- btnAddAll.setBounds(165, 235, 170, 25);
- btnAddAll.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- for(JRadioButton a : buttons)
- if(a.isSelected())
- {
- }
- }
- });
- getContentPane().add(btnAddAll);
- rbY1 = new JRadioButton("Да");
- rbY1.setBounds(335, 90, 50, 25);
- getContentPane().add(rbY1);
- rbY2 = new JRadioButton("Да");
- rbY2.setBounds(335, 115, 50, 25);
- getContentPane().add(rbY2);
- rbY3 = new JRadioButton("Да");
- rbY3.setBounds(335, 140, 50, 25);
- getContentPane().add(rbY3);
- rbY4 = new JRadioButton("Да");
- rbY4.setBounds(335, 165, 50, 25);
- getContentPane().add(rbY4);
- rbY5 = new JRadioButton("Да");
- rbY5.setBounds(335, 190, 50, 25);
- getContentPane().add(rbY5);
- JRadioButton rbN1 = new JRadioButton("Нет");
- rbN1.setBounds(410, 92, 57, 25);
- getContentPane().add(rbN1);
- JRadioButton rbN2 = new JRadioButton("Нет");
- rbN2.setBounds(410, 115, 57, 25);
- getContentPane().add(rbN2);
- rbN3 = new JRadioButton("Нет");
- rbN3.setBounds(410, 140, 57, 25);
- getContentPane().add(rbN3);
- rbN4 = new JRadioButton("Нет");
- rbN4.setBounds(410, 165, 57, 25);
- getContentPane().add(rbN4);
- rbN5 = new JRadioButton("Нет");
- rbN5.setBounds(410, 190, 57, 25);
- getContentPane().add(rbN5);
- ButtonGroup bg1 = new ButtonGroup();
- bg1.add(rbY1);
- bg1.add(rbN1);
- ButtonGroup bg2 = new ButtonGroup();
- bg2.add(rbY2);
- bg2.add(rbN2);
- ButtonGroup bg3 = new ButtonGroup();
- bg3.add(rbY3);
- bg3.add(rbN3);
- ButtonGroup bg4 = new ButtonGroup();
- bg4.add(rbY4);
- bg4.add(rbN4);
- ButtonGroup bg5 = new ButtonGroup();
- bg5.add(rbY5);
- bg5.add(rbN5);
- String[] currentTemplate = { "Дарственная", "Бракосочетание", "Страхование жизни" };
- JComboBox comboBox = new JComboBox(currentTemplate);
- comboBox.setSelectedIndex(0);
- selectedTemplate = comboBox.getSelectedItem().toString();
- SetVisibility();
- comboBox.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- selectedTemplate = comboBox.getSelectedItem().toString();
- SetVisibility();
- }
- });
- comboBox.setBounds(322, 10, 138, 30);
- getContentPane().add(comboBox);
- JButton btnExit = new JButton("Выход");
- btnExit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- btnExit.setBounds(408, 243, 86, 29);
- getContentPane().add(btnExit);
- lblError = new JLabel("Пользователь отсутствует");
- lblError.setBounds(12, 73, 180, 16);
- lblError.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- lblError.setForeground(Color.RED);
- lblError.setVisible(false);
- getContentPane().add(lblError);
- }
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void SetVisibility()
- {
- if (selectedTemplate == "Дарственная")
- {
- doc3.setVisible(false);
- doc4.setVisible(false);
- doc5.setVisible(false);
- doc_name3.setVisible(false);
- doc_name4.setVisible(false);
- doc_name5.setVisible(false);
- rbY3.setVisible(false);
- rbY4.setVisible(false);
- rbY5.setVisible(false);
- rbN3.setVisible(false);
- rbN4.setVisible(false);
- rbN5.setVisible(false);
- }
- else if (selectedTemplate == "Страхование жизни")
- {
- doc3.setVisible(true);
- doc4.setVisible(true);
- doc5.setVisible(true);
- doc_name3.setVisible(true);
- doc_name4.setVisible(true);
- doc_name5.setVisible(true);
- rbY3.setVisible(true);
- rbY4.setVisible(true);
- rbY5.setVisible(true);
- rbN3.setVisible(true);
- rbN4.setVisible(true);
- rbN5.setVisible(true);
- }
- else if (selectedTemplate == "Бракосочетание")
- {
- doc3.setVisible(true);
- doc4.setVisible(true);
- doc5.setVisible(false);
- doc_name3.setVisible(true);
- doc_name4.setVisible(true);
- doc_name5.setVisible(false);
- rbY3.setVisible(true);
- rbN3.setVisible(true);
- rbY4.setVisible(true);
- rbN4.setVisible(true);
- rbY5.setVisible(false);
- rbN5.setVisible(false);
- }
- }
- public void GetData()
- {
- try
- {
- Class.forName("com.mysql.cj.jdbc.Driver");
- connection = DriverManager.getConnection(path, "admin", "");
- statement = connection.createStatement();
- String sql = "Select * from Users where Username='" + username.getText().toString() + "' and Type='User'";
- ResultSet rs = statement.executeQuery(sql);
- if (!rs.next())
- lblError.setVisible(true);
- else
- lblError.setVisible(false);
- connection.close();
- }
- catch(Exception e)
- {
- System.out.print(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement