質問編集履歴
2
コードを見やすくした
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
しかし、イベント用のコードをどのように挿入したらよいのかわかりません。
|
7
7
|
未熟なコードとなり大変申し訳ございませんが、ご意見いただければ幸いです。
|
8
8
|
以下に私の現状を添付致します。
|
9
|
-
|
9
|
+
```ここに言語を入力
|
10
10
|
import javafx.application.Application;
|
11
11
|
import javafx.fxml.FXMLLoader;
|
12
12
|
import javafx.scene.Parent;
|
@@ -33,9 +33,11 @@
|
|
33
33
|
launch(args);
|
34
34
|
}
|
35
35
|
}
|
36
|
+
```
|
37
|
+
|
36
38
|
|
37
39
|
以下 Mainframe.java
|
38
|
-
|
40
|
+
```ここに言語を入力
|
39
41
|
import java.net.URL;
|
40
42
|
import java.util.ResourceBundle;
|
41
43
|
import javafx.event.ActionEvent;
|
@@ -83,7 +85,11 @@
|
|
83
85
|
|
84
86
|
}
|
85
87
|
|
88
|
+
```
|
89
|
+
|
86
90
|
Mainframe.fxml
|
91
|
+
```ここに言語を入力
|
92
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
87
93
|
|
88
94
|
<!--
|
89
95
|
Copyright (c) 2015, 2019, Gluon and/or its affiliates.
|
@@ -183,3 +189,5 @@
|
|
183
189
|
</children>
|
184
190
|
</VBox>
|
185
191
|
|
192
|
+
```
|
193
|
+
|
1
Mainframe の情報を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
プログラミング初心者です。
|
1
|
+
ヘディングのテキストプログラミング初心者です。
|
2
2
|
|
3
3
|
vscodeでscene builderを使用してguiを作成したいと考えています。
|
4
4
|
いくつかのサイトを参考にして、javafx、scene builderの設定を行い、vscodeで使用できる設定ができていると思います。
|
@@ -34,4 +34,152 @@
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
+
以下 Mainframe.java
|
38
|
+
|
39
|
+
import java.net.URL;
|
40
|
+
import java.util.ResourceBundle;
|
41
|
+
import javafx.event.ActionEvent;
|
42
|
+
import javafx.fxml.FXML;
|
43
|
+
import javafx.scene.control.Button;
|
44
|
+
import javafx.scene.control.TextField;
|
45
|
+
import java.util.Optional;
|
46
|
+
import javafx.scene.control.Alert;
|
47
|
+
import javafx.scene.control.Alert.AlertType;
|
48
|
+
import javafx.scene.control.ButtonType;
|
49
|
+
|
50
|
+
public class Mainframe {
|
51
|
+
|
52
|
+
@FXML
|
53
|
+
private ResourceBundle resources;
|
54
|
+
|
55
|
+
@FXML
|
56
|
+
private URL location;
|
57
|
+
|
58
|
+
@FXML
|
59
|
+
private Button button1;
|
60
|
+
|
61
|
+
@FXML
|
62
|
+
private TextField textFiled1;
|
63
|
+
|
64
|
+
@FXML
|
65
|
+
void handleButtonAction(ActionEvent event) {
|
66
|
+
Alert alert = new Alert(AlertType.CONFIRMATION);
|
67
|
+
alert.setTitle("Title!");
|
68
|
+
alert.setHeaderText("Header!");
|
69
|
+
alert.setContentText("You entered: " + textFiled1.getText());
|
70
|
+
Optional<ButtonType> result = alert.showAndWait();
|
71
|
+
if (result.isPresent() && result.get() == ButtonType.OK) {
|
72
|
+
System.out.println("You clicked OK");
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
@FXML
|
78
|
+
void initialize() {
|
37
|
-
|
79
|
+
assert button1 != null : "fx:id=\"button1\" was not injected: check your FXML file 'Mainframe.fxml'.";
|
80
|
+
assert textFiled1 != null : "fx:id=\"textFiled1\" was not injected: check your FXML file 'Mainframe.fxml'.";
|
81
|
+
|
82
|
+
}
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
Mainframe.fxml
|
87
|
+
|
88
|
+
<!--
|
89
|
+
Copyright (c) 2015, 2019, Gluon and/or its affiliates.
|
90
|
+
All rights reserved. Use is subject to license terms.
|
91
|
+
|
92
|
+
This file is available and licensed under the following license:
|
93
|
+
|
94
|
+
Redistribution and use in source and binary forms, with or without
|
95
|
+
modification, are permitted provided that the following conditions
|
96
|
+
are met:
|
97
|
+
|
98
|
+
- Redistributions of source code must retain the above copyright
|
99
|
+
notice, this list of conditions and the following disclaimer.
|
100
|
+
- Redistributions in binary form must reproduce the above copyright
|
101
|
+
notice, this list of conditions and the following disclaimer in
|
102
|
+
the documentation and/or other materials provided with the distribution.
|
103
|
+
- Neither the name of Oracle Corporation nor the names of its
|
104
|
+
contributors may be used to endorse or promote products derived
|
105
|
+
from this software without specific prior written permission.
|
106
|
+
|
107
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
108
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
109
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
110
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
111
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
112
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
113
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
114
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
115
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
116
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
117
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
118
|
+
-->
|
119
|
+
|
120
|
+
<?import javafx.scene.control.Button?>
|
121
|
+
<?import javafx.scene.control.Label?>
|
122
|
+
<?import javafx.scene.control.Menu?>
|
123
|
+
<?import javafx.scene.control.MenuBar?>
|
124
|
+
<?import javafx.scene.control.MenuItem?>
|
125
|
+
<?import javafx.scene.control.SeparatorMenuItem?>
|
126
|
+
<?import javafx.scene.control.TextField?>
|
127
|
+
<?import javafx.scene.layout.AnchorPane?>
|
128
|
+
<?import javafx.scene.layout.VBox?>
|
129
|
+
<?import javafx.scene.text.Font?>
|
130
|
+
|
131
|
+
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Mainframe">
|
132
|
+
<children>
|
133
|
+
<MenuBar VBox.vgrow="NEVER">
|
134
|
+
<menus>
|
135
|
+
<Menu mnemonicParsing="false" text="File">
|
136
|
+
<items>
|
137
|
+
<MenuItem mnemonicParsing="false" text="New" />
|
138
|
+
<MenuItem mnemonicParsing="false" text="Open…" />
|
139
|
+
<Menu mnemonicParsing="false" text="Open Recent" />
|
140
|
+
<SeparatorMenuItem mnemonicParsing="false" />
|
141
|
+
<MenuItem mnemonicParsing="false" text="Close" />
|
142
|
+
<MenuItem mnemonicParsing="false" text="Save" />
|
143
|
+
<MenuItem mnemonicParsing="false" text="Save As…" />
|
144
|
+
<MenuItem mnemonicParsing="false" text="Revert" />
|
145
|
+
<SeparatorMenuItem mnemonicParsing="false" />
|
146
|
+
<MenuItem mnemonicParsing="false" text="Preferences…" />
|
147
|
+
<SeparatorMenuItem mnemonicParsing="false" />
|
148
|
+
<MenuItem mnemonicParsing="false" text="Quit" />
|
149
|
+
</items>
|
150
|
+
</Menu>
|
151
|
+
<Menu mnemonicParsing="false" text="Edit">
|
152
|
+
<items>
|
153
|
+
<MenuItem mnemonicParsing="false" text="Undo" />
|
154
|
+
<MenuItem mnemonicParsing="false" text="Redo" />
|
155
|
+
<SeparatorMenuItem mnemonicParsing="false" />
|
156
|
+
<MenuItem mnemonicParsing="false" text="Cut" />
|
157
|
+
<MenuItem mnemonicParsing="false" text="Copy" />
|
158
|
+
<MenuItem mnemonicParsing="false" text="Paste" />
|
159
|
+
<MenuItem mnemonicParsing="false" text="Delete" />
|
160
|
+
<SeparatorMenuItem mnemonicParsing="false" />
|
161
|
+
<MenuItem mnemonicParsing="false" text="Select All" />
|
162
|
+
<MenuItem mnemonicParsing="false" text="Unselect All" />
|
163
|
+
</items>
|
164
|
+
</Menu>
|
165
|
+
<Menu mnemonicParsing="false" text="Help">
|
166
|
+
<items>
|
167
|
+
<MenuItem mnemonicParsing="false" text="About MyHelloApp" />
|
168
|
+
</items>
|
169
|
+
</Menu>
|
170
|
+
</menus>
|
171
|
+
</MenuBar>
|
172
|
+
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
|
173
|
+
<children>
|
174
|
+
<Label alignment="CENTER" layoutX="155.0" layoutY="177.0" style=" " textAlignment="CENTER" textFill="#9f9f9f" wrapText="false">
|
175
|
+
<font>
|
176
|
+
<Font size="18.0" />
|
177
|
+
</font>
|
178
|
+
</Label>
|
179
|
+
<Button fx:id="button1" layoutX="14.0" layoutY="76.0" mnemonicParsing="false" onAction="#handleButtonAction" text="OK" textFill="#d7064c" />
|
180
|
+
<TextField fx:id="textFiled1" layoutX="14.0" layoutY="38.0" />
|
181
|
+
</children>
|
182
|
+
</AnchorPane>
|
183
|
+
</children>
|
184
|
+
</VBox>
|
185
|
+
|