Advertisement
Guest User

kod uczelnia

a guest
Dec 7th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.78 KB | None | 0 0
  1. package testfx;
  2.  
  3. import java.sql.*;
  4. import javafx.application.Application;
  5. import javafx.beans.property.SimpleStringProperty;
  6. import javafx.beans.property.StringProperty;
  7. import javafx.beans.value.ChangeListener;
  8. import javafx.beans.value.ObservableValue;
  9. import javafx.event.Event;
  10. import javafx.event.EventHandler;
  11. import javafx.geometry.Insets;
  12. import javafx.geometry.Pos;
  13. import javafx.geometry.VPos;
  14. import javafx.scene.Scene;
  15. import javafx.scene.control.Button;
  16. import javafx.scene.control.Label;
  17. import javafx.scene.control.ListView;
  18. import javafx.scene.control.PasswordField;
  19. import javafx.scene.control.ScrollPane;
  20. import javafx.scene.control.TextArea;
  21. import javafx.scene.control.TextAreaBuilder;
  22. import javafx.scene.control.TextField;
  23. import javafx.scene.image.Image;
  24. import javafx.scene.image.ImageView;
  25. import javafx.scene.input.MouseEvent;
  26. import javafx.scene.layout.GridPane;
  27. import javafx.scene.layout.HBox;
  28. import javafx.scene.layout.StackPane;
  29. import javafx.scene.layout.VBox;
  30. import javafx.scene.paint.Color;
  31. import javafx.scene.text.Font;
  32. import javafx.scene.text.FontWeight;
  33. import javafx.scene.text.Text;
  34. import javafx.stage.Stage;
  35.  
  36. import java.awt.event.ActionEvent;
  37. import java.awt.event.ActionListener;
  38. import java.io.FileInputStream;
  39. import java.io.FileNotFoundException;
  40. import java.util.Properties;
  41.  
  42. import javax.swing.JFrame;
  43. import javax.swing.SwingUtilities;
  44.  
  45. //import com.sun.corba.se.pept.transport.Connection;
  46.  
  47. public class HelloWorld extends Application{
  48.  
  49. Stage window;
  50. Scene main, scena1, scena2, scena3, scena_student_wyswietl_oceny,scena_student_proponuj_temat;
  51. String typ_konta = "brak";
  52. String sql, imie;
  53. TextField tfName = new TextField();
  54. PasswordField pfPwd = new PasswordField();
  55. Label lblImie = new Label();
  56. Label lblImie2 = new Label();
  57. String user,haslo;
  58. int id;
  59. Label blad = new Label();
  60.  
  61.  
  62. int ilosc_tematow;
  63.  
  64. StringProperty textRecu = new SimpleStringProperty();
  65.  
  66.  
  67. public static void main(String[] args) {
  68. launch(args);
  69. }
  70.  
  71. public void start(Stage primaryStage) throws Exception{
  72. window = primaryStage;
  73. //blad.setBackground(Color.RED);
  74.  
  75. GridPane maingrid = new GridPane();
  76. maingrid.setAlignment(Pos.CENTER);
  77. maingrid.setHgap(10);
  78. maingrid.setVgap(12);
  79. HBox mainButtons = new HBox();
  80. mainButtons.setSpacing(10.0);
  81.  
  82. FileInputStream input = new FileInputStream("resources/images/profesor.png");
  83. Image image = new Image(input);
  84. ImageView imageView = new ImageView(image);
  85.  
  86. FileInputStream input2 = new FileInputStream("resources/images/student.png");
  87. Image image2 = new Image(input2);
  88. ImageView imageView2 = new ImageView(image2);
  89.  
  90. FileInputStream input3 = new FileInputStream("resources/images/admin.png");
  91. Image image3 = new Image(input3);
  92. ImageView imageView3 = new ImageView(image3);
  93.  
  94. Button btn_student = new Button("", imageView2);
  95.  
  96. Button btn_wykladowca = new Button("", imageView);
  97.  
  98. Button btn_admin = new Button("", imageView3);
  99.  
  100. btn_student.setMinWidth(100);
  101. btn_wykladowca.setMinWidth(100);
  102. mainButtons.getChildren().addAll(btn_student, btn_wykladowca, btn_admin);
  103. mainButtons.setAlignment(Pos.CENTER);
  104.  
  105. maingrid.add(mainButtons, 0, 2, 2, 1);
  106. main = new Scene(maingrid, 690,300);
  107.  
  108. Label lblName = new Label("Nazwa Użytkownika");
  109. //TextField tfName = new TextField();
  110. Label lblPwd = new Label("Hasło");
  111.  
  112. btn_student.addEventHandler(MouseEvent.MOUSE_CLICKED,
  113. new EventHandler<MouseEvent>() {
  114. @Override public void handle(MouseEvent e) {
  115. window.setScene(scena1);
  116. typ_konta = "student";
  117. lblName.setText("Nr indeksu: ");
  118. }
  119. });
  120.  
  121. btn_wykladowca.addEventHandler(MouseEvent.MOUSE_CLICKED,
  122. new EventHandler<MouseEvent>() {
  123. @Override public void handle(MouseEvent e) {
  124. window.setScene(scena1);
  125. typ_konta = "prowadzacy";
  126. lblName.setText("Email: ");
  127. }
  128. });
  129.  
  130. btn_admin.addEventHandler(MouseEvent.MOUSE_CLICKED,
  131. new EventHandler<MouseEvent>() {
  132. @Override public void handle(MouseEvent e) {
  133. window.setScene(scena1);
  134. typ_konta = "admin";
  135. lblName.setText("Login: ");
  136. }
  137. });
  138.  
  139. // btn_student.setOnAction(e-> window.setScene(scena1));
  140. // btn_wykladowca.setOnAction(e-> window.setScene(scena1));
  141. // btn_admin.setOnAction(e-> window.setScene(scena1));
  142.  
  143.  
  144. GridPane grid = new GridPane();
  145. grid.setAlignment(Pos.CENTER);
  146. grid.setHgap(10);
  147. grid.setVgap(12);
  148.  
  149. HBox hbButtons = new HBox();
  150. hbButtons.setSpacing(10.0);
  151. HBox backButton = new HBox();
  152. backButton.setSpacing(10.0);
  153.  
  154. Button btnLogin = new Button("Zaloguj");
  155. Button btnBack = new Button("Cofnij");
  156. Button btnTest = new Button("Test");
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. //PasswordField pfPwd = new PasswordField();
  165. //Button btnback = new Button();
  166. backButton.getChildren().addAll(btnBack, btnLogin);
  167. backButton.setAlignment(Pos.TOP_RIGHT);
  168.  
  169. btnBack.addEventHandler(MouseEvent.MOUSE_CLICKED,
  170. new EventHandler<MouseEvent>() {
  171. @Override public void handle(MouseEvent e) {
  172. window.setScene(main);
  173. pfPwd.clear();
  174. tfName.clear();
  175. }
  176. });
  177.  
  178. //btnLogin.setOnAction(e-> window.setScene(main));
  179.  
  180.  
  181. btnLogin.addEventHandler(MouseEvent.MOUSE_CLICKED,
  182. new EventHandler<MouseEvent>() {
  183. @Override public void handle(MouseEvent e) {
  184. // lblName.setText("dyiaaśś");
  185. user = tfName.getText();
  186. //try (Connection conn = DriverManager.getConnection(connectionURL, properties)) {
  187. Connection con = null;
  188. try {
  189. //Class.forName("com.mysql.cj.jdbc.Driver");
  190. con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  191. if(con!=null) {
  192. System.out.println("Pomyślnie połączono z bazą daych");
  193. }
  194.  
  195. Statement stmt=con.createStatement();
  196. if(typ_konta == "student") {
  197. sql="Select * from student where nr_indeksu='"+user+"'";
  198. System.out.println(typ_konta);
  199.  
  200. }else if(typ_konta == "prowadzacy") {
  201. sql="Select * from prowadzacy where PR_imie='"+user+"'";
  202. System.out.println(typ_konta);
  203. }
  204. else {
  205. sql="Select * from admin where Admin_login='"+user+"'";
  206. System.out.println(typ_konta);
  207. }
  208.  
  209. ResultSet rs=stmt.executeQuery(sql);
  210. //System.out.println(lblName.getText());
  211. if(rs.next()) {
  212. System.out.println("Pomyślnie zalogowano");
  213. if(typ_konta == "student") {
  214.  
  215. try {
  216. textRecu.setValue("");
  217. Connection con2 = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  218. Statement stmt2=con2.createStatement();
  219. sql="select Stu_imie, STU_nazwisko, STU_haslo from Student where nr_indeksu = '"+user+"'";
  220. // System.out.println("Test" + user);
  221.  
  222. ResultSet rs2=stmt2.executeQuery(sql);
  223. // if(rs!=null){
  224. // while (rs.next()){
  225. if(rs2.next()) {
  226. imie = rs2.getString(1) +" "+rs2.getString(2);
  227. haslo = rs2.getString(3);
  228. //System.out.println(imie);
  229. // lblImie.setText(imie);
  230. //System.out.println(pfPwd.getText());
  231. lblImie.setText(imie);
  232. lblImie2.setText(imie);
  233. }
  234.  
  235. // }
  236. con2.close();
  237. } catch (SQLException e1) {
  238. // TODO Auto-generated catch block
  239. e1.printStackTrace();
  240. }
  241.  
  242. if(pfPwd.getText().equals(haslo)) {
  243. window.setScene(scena_student_wyswietl_oceny);
  244. System.out.println("Zalogowano na konto");
  245. }else {
  246. System.out.println("Złe hasło");
  247. }
  248.  
  249.  
  250. }
  251. // if (typ_konta == "prowadzacy") {
  252. //
  253. // }if (typ_konta == "admin") {
  254. //
  255. // }
  256. //lblImie.setText(imie);
  257. }else {
  258. System.out.println("zły login");
  259. }
  260. con.close();
  261.  
  262. }catch(Exception f) {
  263. System.out.println(f);
  264. }
  265. //lblImie.setText(imie);
  266. }
  267.  
  268. });
  269.  
  270.  
  271.  
  272.  
  273. // hbButtons.getChildren().addAll(btnTest);
  274. // btnTest.setDefaultButton(true);
  275. // hbButtons.setAlignment(Pos.BASELINE_RIGHT);
  276. // btnTest.setOnAction(e-> window.setScene(scena1));
  277. grid.add(lblName, 0, 0);
  278. grid.add(tfName, 1, 0);
  279. grid.add(lblPwd, 0, 1);
  280. grid.add(pfPwd, 1, 1);
  281. grid.add(hbButtons, 0, 2, 2, 1);
  282. grid.add(backButton, 0, 2, 2, 2);
  283. //layout1.getChildren().addAll(label1, button1);
  284. scena1 = new Scene(grid, 690,300);
  285.  
  286. scena3 = new Scene(addGridPane(), 1000,600);
  287. //scena_student = new Scene(student(primaryStage), 1000,600);
  288. scena_student_wyswietl_oceny = new Scene(Student_wyswietl_oceny(), 1000,600);
  289. scena_student_proponuj_temat = new Scene(Student_proponuj_temat(), 1000,600);
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. Button button0 = new Button("Go to scene 1");
  299. button0.setOnAction(e-> window.setScene(scena1));
  300.  
  301. StackPane layout2 = new StackPane();
  302. layout2.getChildren().add(button0);
  303. scena2 = new Scene(layout2, 690,300);
  304.  
  305. window.setScene(main);
  306. window.setTitle("Aplikacja");
  307. window.show();
  308.  
  309. }
  310.  
  311. public HBox Student_wyswietl_oceny() {
  312. blad.setText(" ");
  313. HBox h = new HBox();
  314. VBox v = new VBox();
  315.  
  316.  
  317. FileInputStream input = null;
  318. try {
  319. input = new FileInputStream("resources/images/student.png");
  320.  
  321. } catch (FileNotFoundException e2) {
  322. // TODO Auto-generated catch block
  323. e2.printStackTrace();
  324. }
  325. Image image = new Image(input);
  326. ImageView imageView = new ImageView(image);
  327.  
  328. TextArea field = new TextArea();
  329.  
  330. Label margines = new Label();
  331.  
  332. //Label lblImie1 = new Label();
  333.  
  334.  
  335.  
  336. Button btn_stu_1 = new Button("Wyświetl Oceny");
  337. //btn_stu_1.setOnAction(e -> window.setScene(scena_student_wyswietl_oceny));
  338. btn_stu_1.addEventHandler(MouseEvent.MOUSE_CLICKED,
  339. new EventHandler<MouseEvent>() {
  340. @Override public void handle(MouseEvent e) {
  341. window.setScene(scena_student_wyswietl_oceny);
  342.  
  343. Connection con = null;
  344. try {
  345. textRecu.setValue("Przedmioty: " + System.lineSeparator());
  346. con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  347. Statement stmt=con.createStatement();
  348. // sql="select Student.STU_nazwisko, projekt.PRO_ocena from Student,projekt\r\n" +
  349. // "where Student.ID_studenta = projekt.ID_studenta\r\n" +
  350. // "AND nr_indeksu='"+user+"'";
  351.  
  352. // sql = "select projekty.temat, projekt.PRO_ocena, student.nr_indeksu from Student,projekt, projekty\r\n" +
  353. // " where Student.ID_studenta = projekt.ID_studenta\r\n" +
  354. // " AND projekt.ID_projektu = projekty.ID_projektu\r\n" +
  355. // " AND Student.nr_indeksu = '"+user+"'";
  356.  
  357. sql = "select przedmiot.PRZ_nazwa, przedmiot2.PRO_ocena, student.nr_indeksu from Student,przedmiot,przedmiot2 where Student.ID_studenta = przedmiot2.ID_studenta AND przedmiot.ID_przedmiotu = przedmiot2.ID_przedmiotu And student.nr_indeksu = '"+user+"'";
  358.  
  359.  
  360.  
  361.  
  362. ResultSet rs=stmt.executeQuery(sql);
  363. //System.out.println(lblName.getText());
  364. if(rs!=null){
  365. System.out.println("Pomyślnie wyświetlono");
  366. //textRecu.setValue(textRecu.getValue() +rs);
  367.  
  368. while (rs.next()){
  369. int i = 1;
  370. String temp = rs.getString(i) +" \t "+rs.getString(i+1) + System.lineSeparator();
  371. i=i+2;
  372. textRecu.setValue(textRecu.getValue() +temp);
  373. //textRecu.setValue(textRecu.getValue() + " Koniec");
  374. //System.out.println(rs.getString(1) +" \t "+rs.getString(2));
  375. //System.out.println(textRecu.getValue());
  376. //lblImie.setText(imie);
  377.  
  378. //System.out.println("Tutaj jest moje imie + temat"+imie);
  379. //+" \t "+rs.getString(4)+" \t "+rs.getString(5)+" \t "+rs.getString(6));
  380. //System.out.println(rs.getString(2));
  381. //System.out.println(rs.getString(3));
  382.  
  383. }
  384.  
  385. }
  386. textRecu.setValue(textRecu.getValue() + "Projekty: " + System.lineSeparator());
  387. Statement stmt2=con.createStatement();
  388. sql ="select projekty.temat, projekt.PRO_ocena, student.nr_indeksu from Student, projekt, projekty where Student.ID_studenta = projekt.ID_studenta and projekt.ID_projektu = projekty.ID_projektu and student.nr_indeksu = '"+user+"'";
  389. ResultSet rs2=stmt2.executeQuery(sql);
  390.  
  391. if(rs2!=null){
  392. System.out.println("Pomyślnie wyświetlono");
  393. //textRecu.setValue(textRecu.getValue() +rs);
  394.  
  395. while (rs2.next()){
  396. int i = 1;
  397. String temp = rs2.getString(i) +" \t "+rs2.getString(i+1) + System.lineSeparator();
  398. System.out.println(temp);
  399. i=i+2;
  400. textRecu.setValue(textRecu.getValue() +temp);
  401.  
  402.  
  403. }
  404.  
  405.  
  406. }
  407.  
  408. con.close();
  409.  
  410. } catch (SQLException e1) {
  411. // TODO Auto-generated catch block
  412. e1.printStackTrace();
  413. }
  414. }
  415.  
  416. });
  417.  
  418.  
  419.  
  420.  
  421.  
  422. btn_stu_1.setMaxSize(200, 40);
  423. btn_stu_1.setAlignment(Pos.CENTER);
  424. Button btn_stu_2 = new Button("Proponuj Temat");
  425. //btn_stu_2.setOnAction(e -> window.setScene(scena_student_proponuj_temat));
  426.  
  427.  
  428. btn_stu_2.setMaxSize(200, 40);
  429. btn_stu_2.setAlignment(Pos.CENTER);
  430.  
  431.  
  432. btn_stu_2.addEventHandler(MouseEvent.MOUSE_CLICKED,
  433. new EventHandler<MouseEvent>() {
  434. @Override public void handle(MouseEvent e) {
  435.  
  436.  
  437.  
  438. //==========
  439. window.setScene(scena_student_proponuj_temat);
  440. textRecu.setValue(" ");
  441. blad.setText(" ");
  442. Connection con2;
  443. try {
  444. con2 = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  445.  
  446. //id = Integer.parseInt(rs2.getString(4));
  447.  
  448. Statement stmt4=con2.createStatement();
  449. sql="select * from student where nr_indeksu = '"+user+"'";
  450. ResultSet rs4=stmt4.executeQuery(sql);
  451.  
  452. while (rs4.next()){
  453. id = Integer.parseInt(rs4.getString(4));
  454.  
  455. }
  456.  
  457. Statement stmt3=con2.createStatement();
  458. sql="select * from temat_propozycja where ID_studenta = '"+id+"'";
  459. ResultSet rs3=stmt3.executeQuery(sql);
  460. if(rs3!=null){
  461. System.out.println("Pomyślnie wyświetlono");
  462. //textRecu.setValue(textRecu.getValue() +rs);
  463. int i = 1;
  464. while (rs3.next()){
  465.  
  466. String temp = rs3.getString(6) + System.lineSeparator();
  467. System.out.println(temp);
  468. i++;
  469. textRecu.setValue(textRecu.getValue() +temp);
  470.  
  471.  
  472. }
  473.  
  474.  
  475. }
  476. } catch (SQLException e2) {
  477. // TODO Auto-generated catch block
  478. e2.printStackTrace();
  479. }
  480.  
  481.  
  482. //===========
  483.  
  484. }
  485.  
  486. });
  487.  
  488.  
  489. Button btn_stu_3 = new Button("Wyloguj");
  490.  
  491.  
  492. btn_stu_3.addEventHandler(MouseEvent.MOUSE_CLICKED,
  493. new EventHandler<MouseEvent>() {
  494. @Override public void handle(MouseEvent e) {
  495. window.setScene(main);
  496. pfPwd.clear();
  497. tfName.clear();
  498. }
  499. });
  500.  
  501. // btn_stu_3.setOnAction(e -> window.setScene(main));
  502. btn_stu_3.setMaxSize(200, 40);
  503. btn_stu_3.setAlignment(Pos.CENTER);
  504.  
  505. v.setSpacing(10.0);
  506.  
  507. v.getChildren().addAll(margines,imageView, lblImie, btn_stu_1, btn_stu_2, btn_stu_3);
  508. v.setAlignment(Pos.TOP_CENTER);
  509. v.setPrefWidth(300);
  510. field.setPrefWidth(700);
  511. h.getChildren().addAll(v, field);
  512. field.textProperty().bind(textRecu);
  513.  
  514. //here you also add listener to the textRecu
  515. textRecu.addListener(new ChangeListener<Object>() {
  516. public void changed(ObservableValue<?> observable, Object oldValue,
  517. Object newValue) {
  518. // from stackoverflow.com/a/30264399/1032167
  519. // for some reason setScrollTop will not scroll properly
  520. //consoleTextArea.setScrollTop(Double.MAX_VALUE);
  521. field.selectPositionCaret(field.getLength());
  522. field.deselect();
  523. }
  524. });
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. return h;
  533.  
  534. }
  535.  
  536. public HBox Student_proponuj_temat() {
  537. blad.setText(" ");
  538. HBox h = new HBox();
  539. HBox nazwa_tematu = new HBox();
  540. VBox v = new VBox();
  541. VBox wynik = new VBox();
  542.  
  543.  
  544.  
  545. FileInputStream input = null;
  546. try {
  547. input = new FileInputStream("resources/images/student.png");
  548.  
  549. } catch (FileNotFoundException e2) {
  550. // TODO Auto-generated catch block
  551. e2.printStackTrace();
  552. }
  553. Image image = new Image(input);
  554. ImageView imageView = new ImageView(image);
  555.  
  556. TextArea field = new TextArea();
  557.  
  558. Label margines = new Label();
  559. Label margines2 = new Label();
  560.  
  561. Label blad = new Label();
  562.  
  563. Label lbl_Temat = new Label();
  564. lbl_Temat.setText("Zaproponowane Tematy:");
  565.  
  566.  
  567. blad.setText(" ");
  568.  
  569.  
  570. Button btn_stu_1 = new Button("Wyświetl Oceny");
  571. //btn_stu_1.setOnAction(e -> window.setScene(scena_student_wyswietl_oceny));
  572. btn_stu_1.addEventHandler(MouseEvent.MOUSE_CLICKED,
  573. new EventHandler<MouseEvent>() {
  574. @Override public void handle(MouseEvent e) {
  575. window.setScene(scena_student_wyswietl_oceny);
  576. blad.setText(" ");
  577. Connection con = null;
  578. try {
  579. textRecu.setValue("Przedmioty: " + System.lineSeparator());
  580. con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  581. Statement stmt=con.createStatement();
  582. // sql="select Student.STU_nazwisko, projekt.PRO_ocena from Student,projekt\r\n" +
  583. // "where Student.ID_studenta = projekt.ID_studenta\r\n" +
  584. // "AND nr_indeksu='"+user+"'";
  585.  
  586. // sql = "select projekty.temat, projekt.PRO_ocena, student.nr_indeksu from Student,projekt, projekty\r\n" +
  587. // " where Student.ID_studenta = projekt.ID_studenta\r\n" +
  588. // " AND projekt.ID_projektu = projekty.ID_projektu\r\n" +
  589. // " AND Student.nr_indeksu = '"+user+"'";
  590.  
  591. sql = "select przedmiot.PRZ_nazwa, przedmiot2.PRO_ocena, student.nr_indeksu from Student,przedmiot,przedmiot2 where Student.ID_studenta = przedmiot2.ID_studenta AND przedmiot.ID_przedmiotu = przedmiot2.ID_przedmiotu And student.nr_indeksu = '"+user+"'";
  592.  
  593.  
  594.  
  595.  
  596. ResultSet rs=stmt.executeQuery(sql);
  597. //System.out.println(lblName.getText());
  598. if(rs!=null){
  599. System.out.println("Pomyślnie wyświetlono");
  600. //textRecu.setValue(textRecu.getValue() +rs);
  601.  
  602. while (rs.next()){
  603. int i = 1;
  604. String temp = rs.getString(i) +" \t "+rs.getString(i+1) + System.lineSeparator();
  605. i=i+2;
  606. textRecu.setValue(textRecu.getValue() +temp);
  607. //textRecu.setValue(textRecu.getValue() + " Koniec");
  608. //System.out.println(rs.getString(1) +" \t "+rs.getString(2));
  609. //System.out.println(textRecu.getValue());
  610. //lblImie.setText(imie);
  611.  
  612. //System.out.println("Tutaj jest moje imie + temat"+imie);
  613. //+" \t "+rs.getString(4)+" \t "+rs.getString(5)+" \t "+rs.getString(6));
  614. //System.out.println(rs.getString(2));
  615. //System.out.println(rs.getString(3));
  616.  
  617. }
  618.  
  619. }
  620. textRecu.setValue(textRecu.getValue() + "Projekty: " + System.lineSeparator());
  621. Statement stmt2=con.createStatement();
  622. sql ="select projekty.temat, projekt.PRO_ocena, student.nr_indeksu from Student, projekt, projekty where Student.ID_studenta = projekt.ID_studenta and projekt.ID_projektu = projekty.ID_projektu and student.nr_indeksu = '"+user+"'";
  623. ResultSet rs2=stmt2.executeQuery(sql);
  624.  
  625. if(rs2!=null){
  626. System.out.println("Pomyślnie wyświetlono");
  627. //textRecu.setValue(textRecu.getValue() +rs);
  628.  
  629. while (rs2.next()){
  630. int i = 1;
  631. String temp = rs2.getString(i) +" \t "+rs2.getString(i+1) + System.lineSeparator();
  632. System.out.println(temp);
  633. i=i+2;
  634. textRecu.setValue(textRecu.getValue() +temp);
  635.  
  636.  
  637. }
  638.  
  639.  
  640. }
  641.  
  642. con.close();
  643.  
  644. } catch (SQLException e1) {
  645. // TODO Auto-generated catch block
  646. e1.printStackTrace();
  647. }
  648. }
  649.  
  650. });
  651.  
  652.  
  653.  
  654.  
  655.  
  656. btn_stu_1.setMaxSize(200, 40);
  657. btn_stu_1.setAlignment(Pos.CENTER);
  658. Button btn_stu_2 = new Button("Proponuj Temat");
  659. btn_stu_2.setOnAction(e -> window.setScene(scena_student_proponuj_temat));
  660. btn_stu_2.setMaxSize(200, 40);
  661. btn_stu_2.setAlignment(Pos.CENTER);
  662.  
  663. Button btn_stu_3 = new Button("Wyloguj");
  664.  
  665.  
  666. btn_stu_3.addEventHandler(MouseEvent.MOUSE_CLICKED,
  667. new EventHandler<MouseEvent>() {
  668. @Override public void handle(MouseEvent e) {
  669. window.setScene(main);
  670. pfPwd.clear();
  671. tfName.clear();
  672. }
  673. });
  674. //btn_stu_3.setOnAction(e -> window.setScene(main));
  675. btn_stu_3.setMaxSize(200, 40);
  676. btn_stu_3.setAlignment(Pos.CENTER);
  677.  
  678. TextField tf_nazwa_tematu = new TextField();
  679. Label lbl_nazwa_tematu = new Label("Temat: ");
  680. Button btn_nazwa_temat = new Button("Zaproponuj temat");
  681.  
  682.  
  683.  
  684.  
  685.  
  686. btn_nazwa_temat.addEventHandler(MouseEvent.MOUSE_CLICKED,
  687. new EventHandler<MouseEvent>() {
  688. @Override public void handle(MouseEvent e) {
  689.  
  690.  
  691.  
  692. // =========================================================================
  693.  
  694. textRecu.setValue(" ");
  695. blad.setText(" ");
  696. try {
  697. Connection con2 = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/uczelnia","root","root");
  698. Statement stmt2=con2.createStatement();
  699. sql="select * from student where nr_indeksu = '"+user+"'";
  700. ResultSet rs2=stmt2.executeQuery(sql);
  701.  
  702. while (rs2.next()){
  703. System.out.println(rs2.getString(1) + " "+ rs2.getString(2) + " "+ rs2.getString(3)+ " "+rs2.getString(4)+ " "+rs2.getString(5)+ " "+rs2.getString(6)+ " "+rs2.getString(7));
  704. if(tf_nazwa_tematu.getText().equals("")) {
  705. //System.out.println("Nie Uzupełniono");
  706. blad.setTextFill(Color.web("#FF0000"));
  707. blad.setText("Uzupełnij temat");
  708.  
  709.  
  710.  
  711. }else {
  712. System.out.println("Uzupełniono");
  713. blad.setText(" ");
  714. Statement stmt3=con2.createStatement();
  715. sql = "SELECT ID_Temat FROM temat_propozycja ORDER BY ID_Temat ASC";
  716. ResultSet rs3=stmt3.executeQuery(sql);
  717. while (rs3.next()){
  718. //System.out.println(rs3.getString(1));
  719. ilosc_tematow = Integer.parseInt(rs3.getString(1));
  720. System.out.println(ilosc_tematow);
  721. }
  722. //
  723.  
  724.  
  725.  
  726. //ResultSet rs4=stmt4.executeQuery(sql);
  727. }
  728. id = Integer.parseInt(rs2.getString(4));
  729. System.out.println("a= "+ilosc_tematow);
  730. ilosc_tematow++;
  731. System.out.println("b= "+ilosc_tematow);
  732. Statement stmt4=con2.createStatement();
  733. sql="INSERT INTO temat_propozycja (ID_Temat ,ID_wydzialu ,ID_kierunku ,ID_grupy ,ID_studenta ,Temat_nazwa ) VALUES ('"+ilosc_tematow+"','"+rs2.getString(1)+"','"+rs2.getString(2)+"','"+rs2.getString(3)+"','"+rs2.getString(4)+"','"+tf_nazwa_tematu.getText()+"')";
  734. stmt4.executeUpdate(sql);
  735.  
  736. }
  737.  
  738. Statement stmt3=con2.createStatement();
  739. sql="select * from temat_propozycja where ID_studenta = '"+id+"'";
  740. ResultSet rs3=stmt3.executeQuery(sql);
  741. if(rs3!=null){
  742. System.out.println("Pomyślnie wyświetlono");
  743. //textRecu.setValue(textRecu.getValue() +rs);
  744.  
  745. while (rs3.next()){
  746.  
  747. String temp = rs3.getString(6) + System.lineSeparator();
  748. //System.out.println(temp);
  749.  
  750. textRecu.setValue(textRecu.getValue() +temp);
  751.  
  752.  
  753. }
  754.  
  755.  
  756. }
  757.  
  758. con2.close();
  759. } catch (SQLException e1) {
  760. // TODO Auto-generated catch block
  761. e1.printStackTrace();
  762. }
  763.  
  764.  
  765.  
  766.  
  767. //=========================================================================
  768. System.out.println(tf_nazwa_tematu.getText());
  769. }
  770.  
  771. });
  772.  
  773. field.setPrefHeight(300);
  774. field.setPrefWidth(600);
  775. field.textProperty().bind(textRecu);
  776.  
  777. //here you also add listener to the textRecu
  778. textRecu.addListener(new ChangeListener<Object>() {
  779. public void changed(ObservableValue<?> observable, Object oldValue,
  780. Object newValue) {
  781. // from stackoverflow.com/a/30264399/1032167
  782. // for some reason setScrollTop will not scroll properly
  783. //consoleTextArea.setScrollTop(Double.MAX_VALUE);
  784. field.selectPositionCaret(field.getLength());
  785. field.deselect();
  786. }
  787. });
  788. wynik.getChildren().addAll(margines2, nazwa_tematu,blad, lbl_Temat, field);
  789. nazwa_tematu.getChildren().addAll(lbl_nazwa_tematu, tf_nazwa_tematu, btn_nazwa_temat);
  790.  
  791. v.setSpacing(10.0);
  792.  
  793. v.getChildren().addAll( margines,imageView, lblImie2, btn_stu_1, btn_stu_2, btn_stu_3);
  794. v.setAlignment(Pos.TOP_CENTER);
  795. v.setPrefWidth(300);
  796.  
  797. h.getChildren().addAll(v, wynik);
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806. return h;
  807.  
  808. }
  809.  
  810.  
  811. public VBox student(Stage primaryStage) throws Exception{
  812. VBox root = new VBox();
  813. StringProperty textRecu = new SimpleStringProperty();
  814. Button btn_stu_1 = new Button("KLIK");
  815. Button btn_stu_2 = new Button("Go to scene 1");
  816. Button btn_stu_3 = new Button("Go to scene 1");
  817. Button btn_stu_4 = new Button("Go to scene 1");
  818. Button btn_stu_5 = new Button("Go to scene 1");
  819. Button btn_stu_6 = new Button("Go to scene 1");
  820. TextArea field = new TextArea();
  821.  
  822. HBox btn_student_group = new HBox();
  823. btn_student_group.setPadding(new Insets(0, 10, 10, 10));
  824. btn_student_group.setSpacing(10);
  825. btn_student_group.getChildren().addAll(btn_stu_1, btn_stu_2);
  826.  
  827.  
  828.  
  829.  
  830. // root.set
  831. // root.setTop(btn_student_group);
  832. // border.setLeft(addVBox());
  833.  
  834. btn_stu_1.setOnMouseClicked(new EventHandler<MouseEvent>() {
  835. @Override
  836. public void handle(MouseEvent event) {
  837. //here you change textRecu and not consoleTextArea.textProperty()
  838. textRecu.setValue(textRecu.getValue() +"New Line\n");
  839. }
  840. });
  841.  
  842. root.getChildren().addAll(field, btn_student_group);
  843. field.textProperty().bind(textRecu);
  844.  
  845. //here you also add listener to the textRecu
  846. textRecu.addListener(new ChangeListener<Object>() {
  847. public void changed(ObservableValue<?> observable, Object oldValue,
  848. Object newValue) {
  849. // from stackoverflow.com/a/30264399/1032167
  850. // for some reason setScrollTop will not scroll properly
  851. //consoleTextArea.setScrollTop(Double.MAX_VALUE);
  852. field.selectPositionCaret(field.getLength());
  853. field.deselect();
  854. }
  855. });
  856.  
  857. //primaryStage.setScene(new Scene(root, 300, 275));
  858.  
  859.  
  860. return root;
  861.  
  862. }
  863.  
  864. public GridPane addGridPane() {
  865.  
  866.  
  867.  
  868. GridPane grid = new GridPane();
  869. grid.setAlignment(Pos.TOP_LEFT);
  870. grid.setHgap(12);
  871. grid.setVgap(12);
  872. grid.setPadding(new Insets(20, 20, 20, 20));
  873.  
  874. // GridPane grid = new GridPane();
  875. // grid.setHgap(10);
  876. // grid.setVgap(10);
  877. // // grid.setPadding(new Insets(0, 10, 0, 10));
  878. // grid.setPadding(new Insets(0,0,0,0));
  879.  
  880. // Category in column 2, row 1
  881. Button btn_stu_1 = new Button("Go to scene 1");
  882. // grid.add(btn_stu_1, 1, 1);
  883. //btn_stu_1.setLayoutX(250);
  884. //btn_stu_1.setLayoutY(250);
  885. Button btn_stu_2 = new Button("Go to scene 1");
  886. //grid.add(btn_stu_2, 1, 2);
  887. Button btn_stu_3 = new Button("Go to scene 1");
  888. // grid.add(btn_stu_3, 1, 3);
  889. Button btn_stu_4 = new Button("Go to scene 1");
  890. //grid.add(btn_stu_4, 1, 4);
  891. Button btn_stu_5 = new Button("Go to scene 1");
  892. //grid.add(btn_stu_5, 1, 5);
  893. Button btn_stu_6 = new Button("Go to scene 1");
  894. // grid.add(btn_stu_6, 1, 6);
  895.  
  896. TextArea field = new TextArea();
  897.  
  898. // Title in column 3, row 1
  899.  
  900.  
  901. // Subtitle in columns 2-3, row 2
  902. ListView listView = new ListView();
  903. grid.add(listView,2, 1);
  904.  
  905. // House icon in column 1, rows 1-2
  906. // ImageView imageHouse = new ImageView(
  907. // new Image(LayoutSample.class.getResourceAsStream("graphics/house.png")));
  908. // grid.add(imageHouse, 0, 0, 1, 2);
  909.  
  910. // // Left label in column 1 (bottom), row 3
  911. // Text goodsPercent = new Text("Goods\n80%");
  912. // GridPane.setValignment(goodsPercent, VPos.BOTTOM);
  913. // grid.add(goodsPercent, 0, 2);
  914.  
  915. // Chart in columns 2-3, row 3
  916. // ImageView imageChart = new ImageView(
  917. // new Image(LayoutSample.class.getResourceAsStream("graphics/piechart.png")));
  918. // grid.add(imageChart, 1, 2, 2, 1);
  919.  
  920. // // Right label in column 4 (top), row 3
  921. // Text servicesPercent = new Text("Services\n20%");
  922. // GridPane.setValignment(servicesPercent, VPos.TOP);
  923. // grid.add(servicesPercent, 3, 2);
  924.  
  925. return grid;
  926. }
  927. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement