diff --git a/src/main/java/ru/egspt/moodle/App.java b/src/main/java/ru/egspt/moodle/App.java index 23de895..54a1bd9 100644 --- a/src/main/java/ru/egspt/moodle/App.java +++ b/src/main/java/ru/egspt/moodle/App.java @@ -5,7 +5,7 @@ import javax.swing.JPanel; import javax.swing.WindowConstants; import ru.egspt.moodle.panel.Account; -import ru.egspt.moodle.panel.UserByTag; +import ru.egspt.moodle.panel.TagPane; /** * графический интерфейс для @@ -13,14 +13,15 @@ import ru.egspt.moodle.panel.UserByTag; * */ public class App extends JPanel { + Base base = new Base(); JFrame mainframe = new JFrame("moodle-anyreport"); - Account account = new Account(); - //Users pUsers = new Users(); - + Account accountPane = new Account(); + TagPane tagPane = new TagPane(base); //Заполняем панельку компонентами App(){ - this.add(account); + this.add(accountPane); + this.add(tagPane); } //устанавливаем панельку на форму public void init(){ @@ -36,7 +37,6 @@ public class App extends JPanel { System.out.println( "Работает подготовщик отчетов по результатам тестирования пользователей ..." ); App anyreport = new App(); anyreport.init(); - //System.out.println( "Работа с приложением завершена." ); } } diff --git a/src/main/java/ru/egspt/moodle/Base.java b/src/main/java/ru/egspt/moodle/Base.java index 5993d46..103bca5 100644 --- a/src/main/java/ru/egspt/moodle/Base.java +++ b/src/main/java/ru/egspt/moodle/Base.java @@ -39,6 +39,11 @@ public class Base { private ArrayList users; private ArrayList results; private ArrayList quizes; + + + public Base(){ + + } /** * @return the quizes @@ -439,7 +444,7 @@ public class Base { System.out.println("Пользователей (без дублирований): " + fusers.size()); System.out.println("Пользователей (balbesers): " + balbesers.size()); } - + /** * Главный метод, для проверки кода * @param args diff --git a/src/main/java/ru/egspt/moodle/BaseControls.java b/src/main/java/ru/egspt/moodle/BaseControls.java new file mode 100644 index 0000000..64b057e --- /dev/null +++ b/src/main/java/ru/egspt/moodle/BaseControls.java @@ -0,0 +1,55 @@ +package ru.egspt.moodle; + +import java.sql.Connection; +import java.sql.DriverManager; + +public class BaseControls { + private static Connection connaction = null; + /** + * @param connaction the connaction to set + */ + public static void setConnaction(Connection conn) { + connaction = conn; + } + /** + * @return the connaction + */ + public static Connection getConnaction() { + return connaction; + } + public static void connect(){ + System.out.println("Подключение к серверу баз данных ..."); + Connection conn = null; + try{ + //данные аккаунта + conn = DriverManager.getConnection (Access.getURL(), Access.getUserName(), Access.getPassword()); + System.out.println ("Подключение к серверу баз данных установлено ... "); + + + } + catch (Exception ex){ + System.err.println ("Подключение к серверу баз данных не установлено ... "); + ex.printStackTrace(); + System.out.println (ex); + } + setConnaction(conn); + } + + //отключение от базы + public static void disconnect(){ + if (getConnaction() != null){ + try{ + System.out.println("Попытка отключения от базы данных ... "); + getConnaction().close (); + System.out.println ("Подключение к базе данных завершено. "); + } + catch (Exception ex){ + System.out.println ("Подключение к серверу баз данных уже отсутствует."); + System.out.println (ex); + } + } + } + public static void main (String[] args){ + + } +} diff --git a/src/main/java/ru/egspt/moodle/events/ConnactionListener.java b/src/main/java/ru/egspt/moodle/events/ConnactionListener.java index eba6ea1..0c63d5c 100644 --- a/src/main/java/ru/egspt/moodle/events/ConnactionListener.java +++ b/src/main/java/ru/egspt/moodle/events/ConnactionListener.java @@ -4,6 +4,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import ru.egspt.moodle.Access; +import ru.egspt.moodle.BaseControls; import ru.egspt.moodle.panel.Account; public class ConnactionListener implements ActionListener{ @@ -16,9 +17,6 @@ public class ConnactionListener implements ActionListener{ Access.setUserName(account.getLoginField().getText()); Access.setPassword(String.valueOf(account.getPassField().getPassword())); Access.setUrl(account.getUrlField().getText()); - System.out.println(Access.getUserName()); - System.out.println(Access.getPassword()); - System.out.println(Access.getURL()); - account.getMainframe().dispose(); + BaseControls.connect();//подключиться к базе } } diff --git a/src/main/java/ru/egspt/moodle/events/DisconnectionListener.java b/src/main/java/ru/egspt/moodle/events/DisconnectionListener.java new file mode 100644 index 0000000..3954188 --- /dev/null +++ b/src/main/java/ru/egspt/moodle/events/DisconnectionListener.java @@ -0,0 +1,13 @@ +package ru.egspt.moodle.events; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import ru.egspt.moodle.BaseControls; + +public class DisconnectionListener implements ActionListener{ + public void actionPerformed(ActionEvent e) { + System.out.println("Нажата кнопка DisConnect"); + BaseControls.disconnect(); + } +} diff --git a/src/main/java/ru/egspt/moodle/events/TagButtonListener.java b/src/main/java/ru/egspt/moodle/events/TagButtonListener.java new file mode 100644 index 0000000..f859c0d --- /dev/null +++ b/src/main/java/ru/egspt/moodle/events/TagButtonListener.java @@ -0,0 +1,22 @@ +package ru.egspt.moodle.events; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import ru.egspt.moodle.Base; +import ru.egspt.moodle.BaseControls; + +public class TagButtonListener implements ActionListener{ + Base baseTagged; + public TagButtonListener(Base base){ + baseTagged = base; + } + public void actionPerformed(ActionEvent e) { + System.out.println("Нажата кнопка TagButton"); + //Добавляем выбранный тег в список, для возможности удаления + //фильтруем выборку пользователей и выводим в текстовую область + baseTagged.setUsersByTeg(BaseControls.getConnaction()); + System.out.println("Выборка пользователей изменена ... "); + + } +} diff --git a/src/main/java/ru/egspt/moodle/panel/Account.java b/src/main/java/ru/egspt/moodle/panel/Account.java index 526aa21..661b992 100644 --- a/src/main/java/ru/egspt/moodle/panel/Account.java +++ b/src/main/java/ru/egspt/moodle/panel/Account.java @@ -12,6 +12,7 @@ import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; import ru.egspt.moodle.events.ConnactionListener; +import ru.egspt.moodle.events.DisconnectionListener; public class Account extends JPanel{ @@ -23,7 +24,7 @@ public class Account extends JPanel{ private JLabel urlLabel = new JLabel("Адрес сервера: "); private JTextField urlField = new JTextField(25); private JButton connButton = new JButton("Подключиться"); - private JButton connCloseButton = new JButton("Отключиться"); + private JButton DisconnButton = new JButton("Отключиться"); public Account(){ loginField.setText("esoe");//значения по умолчанию @@ -35,7 +36,10 @@ public class Account extends JPanel{ this.add(urlLabel); this.add(urlField); this.add(connButton); - this.add(connCloseButton); + //настройка кнопки connButton + connButton.addActionListener(new ConnactionListener(this)); + this.add(DisconnButton); + DisconnButton.addActionListener(new DisconnectionListener()); TitledBorder border = new TitledBorder(new LineBorder(Color.black), "connection to mysql", TitledBorder.CENTER, TitledBorder.CENTER); this.setBorder(border); //this.setBorder(BorderFactory.createTitledBorder("аккаунт сервера базы данных")); @@ -48,8 +52,7 @@ public class Account extends JPanel{ mainframe.setSize(320, 240); mainframe.setVisible(true); - //настройка кнопки connButton - connButton.addActionListener(new ConnactionListener(this)); + } /** * @return the loginField diff --git a/src/main/java/ru/egspt/moodle/panel/CurrentTag.java b/src/main/java/ru/egspt/moodle/panel/CurrentTag.java deleted file mode 100644 index 0db07af..0000000 --- a/src/main/java/ru/egspt/moodle/panel/CurrentTag.java +++ /dev/null @@ -1,5 +0,0 @@ -package ru.egspt.moodle.panel; - -public class CurrentTag { - -} diff --git a/src/main/java/ru/egspt/moodle/panel/TagPane.java b/src/main/java/ru/egspt/moodle/panel/TagPane.java new file mode 100644 index 0000000..851740c --- /dev/null +++ b/src/main/java/ru/egspt/moodle/panel/TagPane.java @@ -0,0 +1,38 @@ +package ru.egspt.moodle.panel; + +import java.awt.Color; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import javax.swing.border.LineBorder; +import javax.swing.border.TitledBorder; + +import ru.egspt.moodle.Base; +import ru.egspt.moodle.events.TagButtonListener; + +public class TagPane extends JPanel{ + private JFrame mainframe = new JFrame("Настройка выборки"); + private JTextField tagField = new JTextField(20); + private JButton TagAddButton = new JButton("+"); + //private JButton TagDelButton = new JButton("-"); + + + public TagPane(Base base){ + TitledBorder border = new TitledBorder(new LineBorder(Color.black), "Настройки выборки", TitledBorder.CENTER, TitledBorder.CENTER); + this.setBorder(border); + tagField.setText("");//значения по умолчанию + this.add(tagField); + TagAddButton.addActionListener(new TagButtonListener(base)); + this.add(TagAddButton); + //this.add(TagDelButton); + } + public void init(){ + mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + mainframe.add(this); + mainframe.setSize(320, 240); + mainframe.setVisible(true); + } +} diff --git a/target/classes/ru/egspt/moodle/App.class b/target/classes/ru/egspt/moodle/App.class index 158246b..a5d928e 100644 Binary files a/target/classes/ru/egspt/moodle/App.class and b/target/classes/ru/egspt/moodle/App.class differ diff --git a/target/classes/ru/egspt/moodle/Base.class b/target/classes/ru/egspt/moodle/Base.class index b0856d5..fb71e3f 100644 Binary files a/target/classes/ru/egspt/moodle/Base.class and b/target/classes/ru/egspt/moodle/Base.class differ diff --git a/target/classes/ru/egspt/moodle/BaseControls.class b/target/classes/ru/egspt/moodle/BaseControls.class new file mode 100644 index 0000000..5dc0a64 Binary files /dev/null and b/target/classes/ru/egspt/moodle/BaseControls.class differ diff --git a/target/classes/ru/egspt/moodle/events/ConnactionListener.class b/target/classes/ru/egspt/moodle/events/ConnactionListener.class index c897233..e4fa061 100644 Binary files a/target/classes/ru/egspt/moodle/events/ConnactionListener.class and b/target/classes/ru/egspt/moodle/events/ConnactionListener.class differ diff --git a/target/classes/ru/egspt/moodle/events/DisconnectionListener.class b/target/classes/ru/egspt/moodle/events/DisconnectionListener.class new file mode 100644 index 0000000..4db78ad Binary files /dev/null and b/target/classes/ru/egspt/moodle/events/DisconnectionListener.class differ diff --git a/target/classes/ru/egspt/moodle/events/TagButtonListener.class b/target/classes/ru/egspt/moodle/events/TagButtonListener.class new file mode 100644 index 0000000..1e4f689 Binary files /dev/null and b/target/classes/ru/egspt/moodle/events/TagButtonListener.class differ diff --git a/target/classes/ru/egspt/moodle/panel/Account.class b/target/classes/ru/egspt/moodle/panel/Account.class index 6db73fd..20d2a55 100644 Binary files a/target/classes/ru/egspt/moodle/panel/Account.class and b/target/classes/ru/egspt/moodle/panel/Account.class differ diff --git a/target/classes/ru/egspt/moodle/panel/CurrentTag.class b/target/classes/ru/egspt/moodle/panel/CurrentTag.class deleted file mode 100644 index 8b69218..0000000 Binary files a/target/classes/ru/egspt/moodle/panel/CurrentTag.class and /dev/null differ diff --git a/target/classes/ru/egspt/moodle/panel/TagPane.class b/target/classes/ru/egspt/moodle/panel/TagPane.class new file mode 100644 index 0000000..59a5e3e Binary files /dev/null and b/target/classes/ru/egspt/moodle/panel/TagPane.class differ