Main klasa:
Code:
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import unos.*;
import tabele.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane pane = new BorderPane();
GridPane grid = new GridPane();
VBox topContainer = new VBox();
MenuBar mainMenu = new MenuBar();
ToolBar toolBar = new ToolBar();
topContainer.getChildren().add(mainMenu);
pane.setTop(topContainer);
Menu podaci = new Menu("_UNOS PODATAKA");
MenuItem ucenik_kurs = new MenuItem("Upisivanje učenika na kurs");
podaci.getItems().add(ucenik_kurs);
ucenik_kurs.setOnAction(e -> new UpisivanjeUcenikaNaKurs());
Menu izlaz = new Menu("_IZLAZ");
MenuItem izlazm = new MenuItem("Izlaz");
izlaz.getItems().add(izlazm);
izlaz.setOnAction(e -> System.exit(0));
mainMenu.getMenus().addAll(podaci, izlaz);
Scene scene = new Scene(pane, 800, 600);
primaryStage.setTitle("Aplikacija za evidenciju učenika škole stranih jezika");
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import unos.*;
import tabele.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane pane = new BorderPane();
GridPane grid = new GridPane();
VBox topContainer = new VBox();
MenuBar mainMenu = new MenuBar();
ToolBar toolBar = new ToolBar();
topContainer.getChildren().add(mainMenu);
pane.setTop(topContainer);
Menu podaci = new Menu("_UNOS PODATAKA");
MenuItem ucenik_kurs = new MenuItem("Upisivanje učenika na kurs");
podaci.getItems().add(ucenik_kurs);
ucenik_kurs.setOnAction(e -> new UpisivanjeUcenikaNaKurs());
Menu izlaz = new Menu("_IZLAZ");
MenuItem izlazm = new MenuItem("Izlaz");
izlaz.getItems().add(izlazm);
izlaz.setOnAction(e -> System.exit(0));
mainMenu.getMenus().addAll(podaci, izlaz);
Scene scene = new Scene(pane, 800, 600);
primaryStage.setTitle("Aplikacija za evidenciju učenika škole stranih jezika");
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Klasa "UpisivanjeUcenikaNaKurs":
Code:
package unos;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class UpisivanjeUcenikaNaKurs extends GridPane {
public UpisivanjeUcenikaNaKurs() {
GridPane grid = new GridPane();
Stage stage = new Stage();
Scene scene = new Scene(grid, 800, 600);
stage.setTitle("Upisavanje učenika na kurs");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
grid.setAlignment(Pos.CENTER);
grid.setPadding(new Insets(25, 25, 25, 25));
grid.setHgap(5);
grid.setVgap(5);
Label ime_kursa = new Label("Izaberite ime kursa: ");
ime_kursa.setFont(Font.font("Consolas", FontWeight.BOLD, 20));
grid.add(ime_kursa, 0, 0);
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setPrefWidth(100);
grid.add(comboBox, 1, 0);
Button btDodaj = new Button("Unesi podatke");
btDodaj.setFont(Font.font("Verdana", FontWeight.BOLD, 13));
btDodaj.setPrefSize(130, 30);
grid.add(btDodaj, 1, 7);
comboBox.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
java.sql.Connection con = null;
Statement statement = null;
String url = "jdbc:mysql://localhost/skola_jezika";
String username = "root";
String password = "";
ArrayList<String> comboBoxVrednosti = new ArrayList<String>();
ObservableList<String> data = FXCollections.observableArrayList();
try {
con = DriverManager.getConnection(url, username, password);
statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT ime_kursa FROM kurs");
while(rs.next()) {
String ime_kursa = rs.getString("ime_kursa");
comboBoxVrednosti.add(ime_kursa);
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
DefaultComboBoxModel model = new DefaultComboBoxModel(comboBoxVrednosti.toArray());
}
});
btDodaj.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
if(comboBox.getValue() != null) {
java.sql.Connection con = null;
Statement statement = null;
String url = "jdbc:mysql://localhost/skola_jezika";
String username = "root";
String password = "";
try {
con = DriverManager.getConnection(url, username, password);
Statement st = (Statement) con.createStatement();
st.execute("INSERT INTO kurs_ucenik (id_kursa)" +"VALUES ('" + comboBox.getValue() + "')");
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
Alert alert2 = new Alert(AlertType.INFORMATION);
alert2.setTitle("Dialog");
alert2.setHeaderText("Uspešno ste uneli id kursa!");
alert2.setContentText(null);
alert2.showAndWait();
} else {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Uzbuna");
String s = "Molimo Vas popunite sva polja!";
alert.setContentText(s);
alert.showAndWait();
}
}
});
}
}
package unos;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class UpisivanjeUcenikaNaKurs extends GridPane {
public UpisivanjeUcenikaNaKurs() {
GridPane grid = new GridPane();
Stage stage = new Stage();
Scene scene = new Scene(grid, 800, 600);
stage.setTitle("Upisavanje učenika na kurs");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
grid.setAlignment(Pos.CENTER);
grid.setPadding(new Insets(25, 25, 25, 25));
grid.setHgap(5);
grid.setVgap(5);
Label ime_kursa = new Label("Izaberite ime kursa: ");
ime_kursa.setFont(Font.font("Consolas", FontWeight.BOLD, 20));
grid.add(ime_kursa, 0, 0);
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setPrefWidth(100);
grid.add(comboBox, 1, 0);
Button btDodaj = new Button("Unesi podatke");
btDodaj.setFont(Font.font("Verdana", FontWeight.BOLD, 13));
btDodaj.setPrefSize(130, 30);
grid.add(btDodaj, 1, 7);
comboBox.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
java.sql.Connection con = null;
Statement statement = null;
String url = "jdbc:mysql://localhost/skola_jezika";
String username = "root";
String password = "";
ArrayList<String> comboBoxVrednosti = new ArrayList<String>();
ObservableList<String> data = FXCollections.observableArrayList();
try {
con = DriverManager.getConnection(url, username, password);
statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT ime_kursa FROM kurs");
while(rs.next()) {
String ime_kursa = rs.getString("ime_kursa");
comboBoxVrednosti.add(ime_kursa);
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
DefaultComboBoxModel model = new DefaultComboBoxModel(comboBoxVrednosti.toArray());
}
});
btDodaj.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
if(comboBox.getValue() != null) {
java.sql.Connection con = null;
Statement statement = null;
String url = "jdbc:mysql://localhost/skola_jezika";
String username = "root";
String password = "";
try {
con = DriverManager.getConnection(url, username, password);
Statement st = (Statement) con.createStatement();
st.execute("INSERT INTO kurs_ucenik (id_kursa)" +"VALUES ('" + comboBox.getValue() + "')");
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
Alert alert2 = new Alert(AlertType.INFORMATION);
alert2.setTitle("Dialog");
alert2.setHeaderText("Uspešno ste uneli id kursa!");
alert2.setContentText(null);
alert2.showAndWait();
} else {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Uzbuna");
String s = "Molimo Vas popunite sva polja!";
alert.setContentText(s);
alert.showAndWait();
}
}
});
}
}