Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. package Lab1_Petrenko_OS_US312;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.geometry.Insets;
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.CheckBox;
  11. import javafx.scene.control.ColorPicker;
  12. import javafx.scene.control.RadioButton;
  13. import javafx.scene.control.Slider;
  14. import javafx.scene.control.TextArea;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.control.ToggleGroup;
  17. import javafx.scene.effect.DropShadow;
  18. import javafx.scene.layout.Border;
  19. import javafx.scene.layout.GridPane;
  20. import javafx.scene.layout.HBox;
  21. import javafx.scene.layout.Pane;
  22. import javafx.scene.layout.StackPane;
  23. import javafx.scene.layout.VBox;
  24. import javafx.scene.paint.Color;
  25. import javafx.scene.shape.Line;
  26. import javafx.scene.shape.PathElement;
  27. import javafx.scene.shape.StrokeLineCap;
  28. import javafx.scene.text.Font;
  29. import javafx.scene.text.FontWeight;
  30. import javafx.scene.text.Text;
  31. import javafx.stage.Stage;
  32. import javafx.stage.StageStyle;
  33.  
  34. public class Main extends Application {
  35.  
  36.  
  37.  
  38. Pane root_pane = new Pane();
  39. Group group = new Group();
  40. Slider slider;
  41. Button btn_inc;
  42. Button btn_dec;
  43. RadioButton rb_1;
  44. RadioButton rb_2;
  45. RadioButton rb_3;
  46. CheckBox cb_1;
  47. CheckBox cb_2;
  48. CheckBox cb_3;
  49. TextArea textArea;
  50. DropShadow dropShadow;
  51. Text text;
  52. int counter = 0;
  53. int MAX_VAL = 50;
  54.  
  55. private void Shadow() {
  56. dropShadow = new DropShadow();
  57. dropShadow.setRadius(5.0);
  58. dropShadow.setOffsetX(5.0);
  59. dropShadow.setOffsetY(5.0);
  60. dropShadow.setColor(Color.GRAY);
  61.  
  62. }
  63.  
  64. private void CreateGraphNodes () {
  65. Shadow();
  66. group.setEffect(dropShadow);
  67. text = new Text();
  68. text.setFont(Font.font("Arial", FontWeight.BOLD, 16));
  69. text.setFill(Color.BLUE);
  70. }
  71.  
  72. private void CreateControlNodes () {
  73. ToggleGroup tg = new ToggleGroup();
  74. rb_1 = new RadioButton("RadioButton 1");
  75. rb_1.setToggleGroup(tg);
  76.  
  77. rb_2 = new RadioButton("RadioButton 2");
  78. rb_2.setToggleGroup(tg);
  79. rb_2.setSelected(true);
  80.  
  81. rb_3 = new RadioButton("RadioButton 3");
  82. rb_3.setToggleGroup(tg);
  83.  
  84. cb_1 = new CheckBox("CheckBox 1");
  85. cb_2 = new CheckBox("CheckBox 2");
  86. cb_3 = new CheckBox("CheckBox 3");
  87.  
  88. btn_inc = new Button();
  89. btn_inc.setText("Increase");
  90. btn_inc.setLayoutX(120);
  91. btn_inc.setLayoutY(200);
  92. btn_inc.setTextFill(Color.BROWN);
  93. btn_inc.setFont(Font.font("Arial", FontWeight.BOLD, 12));
  94.  
  95. btn_dec = new Button();
  96. btn_dec.setText("Decrease");
  97. btn_dec.setLayoutX(20);
  98. btn_dec.setLayoutY(200);
  99. btn_dec.setTextFill(Color.BROWN);
  100. btn_dec.setFont(Font.font("Arial", FontWeight.BOLD, 12));
  101.  
  102. textArea = new TextArea();
  103. textArea.setLayoutX(290);
  104. textArea.setLayoutY(20);
  105. textArea.setPrefSize(200,150);
  106. textArea.setText("Lab №1");
  107. textArea.setWrapText(true);
  108.  
  109. slider = new Slider();
  110. slider.setLayoutX(290);
  111. slider.setLayoutY(200);
  112. slider.setPrefWidth(200);
  113. slider.setBlockIncrement(1.0);
  114. slider.setMajorTickUnit(10);
  115. slider.setMinorTickCount(5);
  116. slider.setMin(1);
  117. slider.setShowTickLabels(true);
  118. slider.setShowTickMarks(true);
  119. slider.setSnapToTicks(false);
  120. slider.setValue(counter);
  121.  
  122. GridPane gp = new GridPane();
  123. gp.setHgap(50);
  124. gp.setVgap(10);
  125. gp.setPadding(new Insets(25, 0, 0, 20));
  126. gp.add(rb_1, 0, 0);
  127. gp.add(rb_2, 0, 1);
  128. gp.add(rb_3, 0, 2);
  129.  
  130. gp.add(cb_1, 1, 0);
  131. gp.add(cb_2, 1, 1);
  132. gp.add(cb_3, 1, 2);
  133.  
  134. gp.add(text, 0, 8);
  135.  
  136.  
  137. group.getChildren().addAll(gp, slider, btn_dec, btn_inc, textArea);
  138. root_pane.getChildren().addAll(group);
  139.  
  140. toDisplay(counter);
  141. }
  142.  
  143. private void onAction() {
  144. btn_inc.setOnAction((ActionEvent event) -> {
  145. if (counter < MAX_VAL) {
  146. counter +=1;
  147. }
  148. toDisplay(counter);
  149. });
  150.  
  151. btn_dec.setOnAction((ActionEvent event) -> {
  152. if (counter > 1) {
  153. counter -=1;
  154. }
  155. toDisplay(counter);
  156. });
  157.  
  158. slider.valueProperty().addListener((observable -> {
  159. if (slider.isValueChanging()) {
  160. counter = (int) slider.getValue();
  161.  
  162. toDisplay(counter);
  163. }
  164. }));
  165.  
  166. cb_1.setOnAction((ActionEvent event) -> {
  167. if (cb_1.isSelected()) {
  168. textArea.appendText("\nInstalled CheckBox 1");
  169. }else{
  170. textArea.appendText("\nRemoved Checkbox 1");
  171. }
  172. });
  173.  
  174. cb_2.setOnAction((ActionEvent event) -> {
  175. if (cb_2.isSelected()) {
  176. textArea.appendText("\nInstalled CheckBox 2");
  177. }else{
  178. textArea.appendText("\nRemoved Checkbox 2");
  179. }
  180. });
  181.  
  182. cb_3.setOnAction((ActionEvent event) -> {
  183. if (cb_3.isSelected()) {
  184. textArea.appendText("\nInstalled CheckBox 3");
  185. }else{
  186. textArea.appendText("\nRemoved Checkbox 3");
  187. }
  188. });
  189.  
  190. rb_1.setOnAction((ActionEvent event) ->{
  191. textArea.appendText("\nInstalled RadioButton 1");
  192. });
  193.  
  194. rb_2.setOnAction((ActionEvent event) ->{
  195. textArea.appendText("\nInstalled RadioButton 2");
  196. });
  197.  
  198. rb_3.setOnAction((ActionEvent event) ->{
  199. textArea.appendText("\nInstalled RadioButton 3");
  200. });
  201.  
  202.  
  203. }
  204.  
  205. private void toDisplay(double val) {
  206. String s = Integer.toString(counter);
  207. text.setText("Counter: " + s);
  208. textArea.appendText("\nCounter: " + s);
  209. slider.setValue(counter);
  210. }
  211.  
  212. @Override
  213. public void start(Stage stage) {
  214. stage.setTitle("Lab №1, Petrenko O.S.");
  215. stage.setResizable(false);
  216. CreateGraphNodes();
  217. CreateControlNodes();
  218. onAction();
  219. Scene scene = new Scene(root_pane, 500, 250, Color.TRANSPARENT);
  220. stage.setScene(scene);
  221. stage.show();
  222. }
  223.  
  224. public static void main(String[] args) {
  225. launch(args);
  226. }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement