質問編集履歴

1

ソースを追加

2018/06/10 07:08

投稿

makoto-n
makoto-n

スコア436

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,221 @@
23
23
  画面遷移をjavaアプリケーションで行いたいです。
24
24
 
25
25
  解決策をご教授お願いします。
26
+
27
+
28
+
29
+ //---追記拝見しました。
30
+
31
+
32
+
33
+ [Main.java]
34
+
35
+ ```java
36
+
37
+ package application;
38
+
39
+
40
+
41
+ import javafx.application.Application;
42
+
43
+ import javafx.fxml.FXMLLoader;
44
+
45
+ import javafx.scene.Scene;
46
+
47
+ import javafx.scene.layout.BorderPane;
48
+
49
+ import javafx.stage.Stage;
50
+
51
+
52
+
53
+ public class Main extends Application {
54
+
55
+ @Override
56
+
57
+ public void start(Stage primaryStage) {
58
+
59
+ try {
60
+
61
+ BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
62
+
63
+ Scene scene = new Scene(root,600,500);
64
+
65
+ scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
66
+
67
+ primaryStage.setScene(scene);
68
+
69
+ primaryStage.show();
70
+
71
+ } catch(Exception e) {
72
+
73
+ e.printStackTrace();
74
+
75
+ }
76
+
77
+ }
78
+
79
+
80
+
81
+ public static void main(String[] args) {
82
+
83
+ launch(args);
84
+
85
+ }
86
+
87
+ }
88
+
89
+ ```
90
+
91
+
92
+
93
+ [MainController.java](イベントコントローラ)
94
+
95
+ ```java
96
+
97
+ package application;
98
+
99
+
100
+
101
+ import javafx.event.ActionEvent;
102
+
103
+ import javafx.fxml.FXML;
104
+
105
+
106
+
107
+ public class MainController extends DefaultController {
108
+
109
+ protected void dbMake(ActionEvent e) {}
110
+
111
+ protected void dbShow(ActionEvent e) {}
112
+
113
+ protected void dbDelt(ActionEvent e) {}
114
+
115
+ @Override
116
+
117
+ protected void retHome(ActionEvent e) {}
118
+
119
+
120
+
121
+ }
122
+
123
+ ```
124
+
125
+
126
+
127
+ [DefaultController.java](全ての画面に共通するイベントを記載)
128
+
129
+ ```java
130
+
131
+ package application;
132
+
133
+
134
+
135
+ import javafx.event.ActionEvent;
136
+
137
+
138
+
139
+ abstract class DefaultController {
140
+
141
+ abstract protected void retHome(ActionEvent e);
142
+
143
+ }
144
+
145
+ ```
146
+
147
+ [sample.fxml]
148
+
149
+ ```xml
150
+
151
+ <?xml version="1.0" encoding="UTF-8"?>
152
+
153
+
154
+
155
+ <?import javafx.scene.control.Button?>
156
+
157
+ <?import javafx.scene.control.CheckBox?>
158
+
159
+ <?import javafx.scene.control.Hyperlink?>
160
+
161
+ <?import javafx.scene.control.Label?>
162
+
163
+ <?import javafx.scene.control.ScrollPane?>
164
+
165
+ <?import javafx.scene.layout.AnchorPane?>
166
+
167
+ <?import javafx.scene.layout.BorderPane?>
168
+
169
+
170
+
171
+ <BorderPane stylesheets="@application.css" xmlns="http://javafx.com/javafx/9.0.4" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
172
+
173
+ <center>
174
+
175
+ <AnchorPane prefHeight="500.0" prefWidth="600.0" BorderPane.alignment="CENTER">
176
+
177
+ <children>
178
+
179
+ <AnchorPane fx:id="main" prefHeight="500.0" prefWidth="600.0">
180
+
181
+ <children>
182
+
183
+ <Label layoutX="240.0" layoutY="60.0" styleClass="title" text="DB管理メイン画面" />
184
+
185
+ <Button layoutX="370.0" layoutY="200.0" mnemonicParsing="false" onAction="#dbDelt" styleClass="deltBtn" text="DB削除" />
186
+
187
+ <Button layoutX="260.0" layoutY="200.0" mnemonicParsing="false" onAction="#dbShow" styleClass="showBtn" text="DB閲覧" />
188
+
189
+ <Button layoutX="150.0" layoutY="200.0" mnemonicParsing="false" onAction="#dbMake" styleClass="makeBtn" text="DB作成" />
190
+
191
+ </children>
192
+
193
+ </AnchorPane>
194
+
195
+ <AnchorPane disable="true" prefHeight="500.0" prefWidth="600.0">
196
+
197
+ <children>
198
+
199
+ <ScrollPane prefHeight="300.0" prefWidth="400.0" AnchorPane.leftAnchor="100.0" AnchorPane.topAnchor="80.0">
200
+
201
+ <content>
202
+
203
+ <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="300.0" prefWidth="400.0" styleClass="DB-List">
204
+
205
+ <children>
206
+
207
+ <CheckBox layoutX="10.0" mnemonicParsing="false" prefHeight="20.0" text="DBname" />
208
+
209
+ </children>
210
+
211
+ </AnchorPane>
212
+
213
+ </content>
214
+
215
+ </ScrollPane>
216
+
217
+ <Button layoutX="180.0" mnemonicParsing="false" prefWidth="90.0" styleClass="deltDB-cxlBtn" text="キャンセル" AnchorPane.bottomAnchor="50.0" />
218
+
219
+ <Button layoutX="350.0" mnemonicParsing="false" styleClass="deltDB-dltBtn" text="削除" AnchorPane.bottomAnchor="50.0" />
220
+
221
+ </children>
222
+
223
+ </AnchorPane>
224
+
225
+ <Hyperlink layoutX="220.0" styleClass="retHome" text="メイン画面に戻る" AnchorPane.bottomAnchor="20.0" />
226
+
227
+
228
+
229
+ </children>
230
+
231
+ </AnchorPane>
232
+
233
+ </center>
234
+
235
+ </BorderPane>
236
+
237
+ ```
238
+
239
+
240
+
241
+ と書いています。
242
+
243
+ DB管理デスクトップアプリを作りたいです。