Skip to content

Commit 4b6d3c6

Browse files
committed
test
1 parent eab2b5e commit 4b6d3c6

15 files changed

Lines changed: 546 additions & 9 deletions

src/Main.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1+
import fx.CustomControl;
12
import javafx.application.Application;
2-
import javafx.fxml.FXML;
33
import javafx.scene.Group;
44
import javafx.scene.Scene;
55
import javafx.stage.Stage;
66

7+
78
public class Main extends Application {
9+
810
public static void main(String[] args) {
9-
launch(args);
11+
launch();
1012
}
1113

1214
@Override
1315
public void start(Stage primaryStage) throws Exception {
16+
CustomControl customControl = new CustomControl();
1417

15-
Group group = new Group();
16-
primaryStage.setScene(new Scene(group, 400, 300));
18+
Group root = new Group();
19+
root.getChildren().addAll(customControl);
20+
primaryStage.setScene(new Scene(root, 500, 500));
1721
primaryStage.show();
1822
}
19-
20-
@FXML
21-
public void print() {
22-
System.out.println("bla");
23-
}
2423
}

src/fx/ChartLesson.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package fx;
2+
3+
import javafx.application.Application;
4+
import javafx.collections.FXCollections;
5+
import javafx.collections.ObservableList;
6+
import javafx.scene.Group;
7+
import javafx.scene.Scene;
8+
import javafx.scene.chart.PieChart;
9+
import javafx.stage.Stage;
10+
11+
/**
12+
* Created by max on 3/3/17.
13+
*/
14+
public class ChartLesson extends Application {
15+
public static void main(String[] args) {
16+
launch(args);
17+
}
18+
19+
@Override
20+
public void start(Stage primaryStage) throws Exception {
21+
ObservableList<PieChart.Data> data = FXCollections.observableArrayList(
22+
new PieChart.Data("Grapefruit", 13),
23+
new PieChart.Data("Oranges", 25),
24+
new PieChart.Data("Plums", 10),
25+
new PieChart.Data("Pears", 22),
26+
new PieChart.Data("Apples", 30));
27+
PieChart chart = new PieChart(data);
28+
chart.setTitle("products");
29+
30+
Group root = new Group();
31+
root.getChildren().addAll(chart);
32+
primaryStage.setScene(new Scene(root, 400, 300));
33+
primaryStage.show();
34+
}
35+
}

src/fx/CollectionsLesson.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fx;
2+
3+
import javafx.collections.FXCollections;
4+
import javafx.collections.ListChangeListener;
5+
import javafx.collections.ObservableList;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public class CollectionsLesson {
11+
12+
public static void main(String[] args) {
13+
List<String> list = new ArrayList<String>();
14+
15+
ObservableList<String> observableList = FXCollections.observableList(list);
16+
observableList.addListener(new ListChangeListener() {
17+
@Override
18+
public void onChanged(ListChangeListener.Change change) {
19+
System.out.println("Detected a change! ");
20+
}
21+
});
22+
observableList.add("item one");
23+
list.add("item two");
24+
25+
System.out.println("Size: "+observableList.size());
26+
27+
}
28+
}

src/fx/CustomConstrolLesson.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fx;
2+
3+
import javafx.application.Application;
4+
import javafx.scene.Group;
5+
import javafx.scene.Scene;
6+
import javafx.stage.Stage;
7+
8+
/**
9+
* Created by max on 3/3/17.
10+
*/
11+
public class CustomConstrolLesson extends Application {
12+
13+
public static void main(String[] args) {
14+
Application.launch(args);
15+
}
16+
17+
@Override
18+
public void start(Stage primaryStage) throws Exception {
19+
// CustomControl customControl = new CustomControl();
20+
// customControl.setText("Hello!");
21+
22+
NumberTextField customControl = new NumberTextField();
23+
24+
Group group = new Group();
25+
group.getChildren().addAll(customControl);
26+
primaryStage.setScene(new Scene(group, 400, 300));
27+
primaryStage.show();
28+
}
29+
}

src/fx/CustomControl.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fx;
2+
3+
import javafx.beans.property.StringProperty;
4+
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
6+
import javafx.scene.control.TextField;
7+
import javafx.scene.layout.VBox;
8+
9+
import java.io.IOException;
10+
11+
public class CustomControl extends VBox {
12+
@FXML private TextField textField;
13+
14+
public CustomControl() {
15+
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("custom_control.fxml"));
16+
fxmlLoader.setRoot(this);
17+
fxmlLoader.setController(this);
18+
19+
try {
20+
fxmlLoader.load();
21+
} catch (IOException exception) {
22+
throw new RuntimeException(exception);
23+
}
24+
}
25+
26+
public String getText() {
27+
return textProperty().get();
28+
}
29+
30+
public void setText(String value) {
31+
textProperty().set(value);
32+
}
33+
34+
public StringProperty textProperty() {
35+
return textField.textProperty();
36+
}
37+
38+
@FXML
39+
protected void doSomething() {
40+
System.out.println("The button was clicked!");
41+
}
42+
}

src/fx/EventLesson.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fx;
2+
3+
import javafx.application.Application;
4+
import javafx.event.ActionEvent;
5+
import javafx.event.EventHandler;
6+
import javafx.scene.Group;
7+
import javafx.scene.Scene;
8+
import javafx.scene.control.Button;
9+
import javafx.stage.Stage;
10+
11+
/**
12+
* Created by max on 3/4/17.
13+
*/
14+
public class EventLesson extends Application {
15+
16+
public static void main(String[] args) {
17+
launch();
18+
}
19+
20+
@Override
21+
public void start(Stage primaryStage) throws Exception {
22+
23+
Button button = new Button("press");
24+
button.setOnAction(new EventHandler<ActionEvent>() {
25+
@Override
26+
public void handle(ActionEvent event) {
27+
System.out.println("action");
28+
}
29+
});
30+
button.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
31+
@Override
32+
public void handle(ActionEvent event) {
33+
System.out.println("event handler");
34+
}
35+
});
36+
37+
Group root = new Group();
38+
root.getChildren().addAll(button);
39+
primaryStage.setScene(new Scene(root, 500, 500));
40+
primaryStage.show();
41+
}
42+
}

src/fx/MediaPlayerLesson.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package fx;
2+
3+
import javafx.application.Application;
4+
import javafx.scene.Group;
5+
import javafx.scene.Scene;
6+
import javafx.scene.media.Media;
7+
import javafx.scene.media.MediaPlayer;
8+
import javafx.scene.media.MediaView;
9+
import javafx.stage.Stage;
10+
11+
/**
12+
* Created by max on 3/3/17.
13+
*/
14+
public class MediaPlayerLesson extends Application {
15+
public static void main(String[] args) {
16+
launch(args);
17+
}
18+
19+
@Override
20+
public void start(Stage primaryStage) throws Exception {
21+
22+
// Media media = new Media("file:///home/max/Downloads/sound.mp3");
23+
Media media = new Media("file:///mnt/788051CF8051950A/MyJavaVideoLessons/avi/101Swing6WindowLisener.mp4");
24+
MediaPlayer mediaPlayer = new MediaPlayer(media);
25+
//mediaPlayer.setAutoPlay(true);
26+
MediaView mediaView = new MediaView(mediaPlayer);
27+
mediaPlayer.play();
28+
29+
30+
Group group = new Group();
31+
group.getChildren().add(mediaView);
32+
primaryStage.setScene(new Scene(group, 400, 300));
33+
primaryStage.show();
34+
}
35+
}

src/fx/NumberTextField.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fx;
2+
3+
import javafx.scene.control.TextField;
4+
5+
public class NumberTextField extends TextField {
6+
String numberRegEx = "[0-9]*";
7+
8+
@Override
9+
public void replaceText(int start, int end, String text) {
10+
String oldValue = getText();
11+
if ((validate(text))) {
12+
super.replaceText(start, end, text);
13+
String newText = super.getText();
14+
if (!validate(newText)) {
15+
super.setText(oldValue);
16+
}
17+
}
18+
}
19+
20+
private boolean validate(String text) {
21+
return ("".equals(text) || text.matches(numberRegEx));
22+
}
23+
}

src/fx/PieChartLesson.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fx;
2+
3+
import javafx.application.Application;
4+
import javafx.collections.FXCollections;
5+
import javafx.collections.ObservableList;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
import javafx.scene.chart.*;
9+
import javafx.scene.Group;
10+
11+
public class PieChartLesson extends Application {
12+
13+
@Override public void start(Stage stage) {
14+
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
15+
new PieChart.Data("Grapefruit", 13),
16+
new PieChart.Data("Oranges", 25),
17+
new PieChart.Data("Plums", 10),
18+
new PieChart.Data("Pears", 22),
19+
new PieChart.Data("Apples", 30));
20+
PieChart chart = new PieChart(pieChartData);
21+
chart.setTitle("Imported Fruits");
22+
23+
Group root = new Group();
24+
root.getChildren().add(chart);
25+
stage.setScene(new Scene(root, 500, 500));
26+
stage.show();
27+
}
28+
29+
public static void main(String[] args) {
30+
launch(args);
31+
}
32+
}

0 commit comments

Comments
 (0)