Bonjour tous le monde,
J'ai décidé de passer un projet console en mode fenêtre, je me suis donc tourné vers JavaFX (j'avais déjà utilisé Swing, mais j'ai décidé de me tourner vers quelque chose plus d'actualité)
le problème, c'est cette histoire d’événement qui ne fonctionne pas (rien ne se passe) ,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package serveurChat; import java.io.IOException; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; public class UImain extends Application { @Override public void start(Stage primaryStage) throws IOException { Parent root = FXMLLoader.load(getClass().getResource("UIfxml.fxml")); Scene scene = new Scene(root, 600, 300); primaryStage.setTitle("TelnetChat Server"); primaryStage.setScene(scene); primaryStage.show(); Thread srvthread = new Thread(new Serveur()); srvthread.start(); } public void startserv(ActionEvent event) { System.out.println("test"); } public void stopserv(ActionEvent event) { System.out.println("test"); } public static void main(String[] args) { launch(args); } }
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.ContextMenu?> <?import javafx.scene.control.MenuItem?> <?import javafx.scene.control.Tab?> <?import javafx.scene.control.TabPane?> <?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableView?> <?import javafx.scene.control.TextArea?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.Pane?> <AnchorPane prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1"> <children> <Pane layoutX="61.0" layoutY="31.0" prefHeight="300.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <children> <TabPane prefHeight="300.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE"> <tabs> <Tab text="Server"> <content> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"> <children> <TextArea editable="false" layoutX="56.0" layoutY="43.0" text="Server started" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <contextMenu> <ContextMenu> <items> <MenuItem mnemonicParsing="false" onAction="#stopserv" text="stop" /> <MenuItem mnemonicParsing="false" onAction="#startserv" text="start" /> </items> </ContextMenu> </contextMenu> </TextArea> </children> </AnchorPane> </content> </Tab> <Tab text="Ban list"> <content> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"> <children> <TableView layoutX="24.0" layoutY="25.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <columns> <TableColumn prefWidth="75.0" text="ip address" /> <TableColumn prefWidth="75.0" text="reason" /> <TableColumn prefWidth="75.0" text="date" /> </columns> <contextMenu> <ContextMenu> <items> <MenuItem mnemonicParsing="false" text="add" /> <MenuItem mnemonicParsing="false" text="delete" /> </items> </ContextMenu> </contextMenu> </TableView> </children> </AnchorPane> </content> </Tab> </tabs> </TabPane> </children> </Pane> </children> </AnchorPane>
Merci
Partager