-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
101 lines (81 loc) · 3.79 KB
/
GUI.java
File metadata and controls
101 lines (81 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.io.*;
public class GUI extends Application{
private final TextEditor file = new TextEditor();
@Override
public void start(Stage window) throws Exception {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(40);
grid.setVgap(30);
Scene scene = new Scene(grid, 1000, 500);
window.setScene(scene);
Text windowTitle = new Text("Welcome");
windowTitle.setFont(Font.font("Tacoma", FontWeight.NORMAL, 30));
grid.add(windowTitle, 2, 0, 1, 1);
Button button1 = new Button("Swap two rows");
grid.add(button1, 0, 1);
Button button2 = new Button("Swap two words");
grid.add(button2 , 5, 1);
Label indexOfFirstRow = new Label("Index of first row:");
grid.add(indexOfFirstRow,0,2);
TextField indexOfFirstRowText = new TextField();
grid.add(indexOfFirstRowText , 1 , 2);
Label indexOfSecondRow = new Label("Index of second row:");
grid.add(indexOfSecondRow,0,3);
TextField indexOfSecondRowText = new TextField();
grid.add(indexOfSecondRowText , 1 , 3);
Label indexOfFirstRowWord = new Label("Index of first row:");
grid.add(indexOfFirstRowWord,5,2);
TextField indexOfFirstRowTextWord = new TextField();
grid.add(indexOfFirstRowTextWord , 6 , 2);
Label indexOfWord = new Label("Index of the first word:");
grid.add(indexOfWord,5,3);
TextField indexOfFirstWordText = new TextField();
grid.add(indexOfFirstWordText , 6 , 3);
Label indexOfSecondRowWord = new Label("Index of second row:");
grid.add(indexOfSecondRowWord,5,4);
TextField indexOfSecondRowTextWord = new TextField();
grid.add(indexOfSecondRowTextWord , 6 , 4);
Label indexOfSecondWord = new Label("Index of the second word:");
grid.add(indexOfSecondWord,5,5);
TextField indexOfSecondWordText = new TextField();
grid.add(indexOfSecondWordText , 6 , 5);
button1.setOnAction(action-> {
try {
Reader reader = new BufferedReader(new FileReader("filename.txt"));
int firstRow = Integer.parseInt(indexOfFirstRowText.getText());
int secondRow = Integer.parseInt(indexOfSecondRowText.getText());
file.swapTwoRows(firstRow , secondRow ,reader );
} catch (IOException e) {
throw new NumberFormatException("Use only numbers");
}
});
button2.setOnAction(action-> {
try {
Reader reader = new BufferedReader(new FileReader("filename.txt"));
int firstRow = Integer.parseInt(indexOfFirstRowTextWord.getText());
int indexFirstWord = Integer.parseInt(indexOfFirstWordText.getText());
int secondRow = Integer.parseInt(indexOfSecondRowTextWord.getText());
int indexSecondWord = Integer.parseInt(indexOfSecondWordText.getText());
file.swapTwoWords(firstRow , indexFirstWord , secondRow , indexSecondWord , reader);
} catch (NumberFormatException | IOException e) {
throw new NumberFormatException("Use only numbers");
}
});
window.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}