je peux pas faire plus

master
Aurian JAULT 2 years ago
parent 4bfebb9df0
commit 2e71b6c76a

@ -1,4 +1,5 @@
package com.example.tp; package com.example.tp;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -9,10 +10,15 @@ import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView; import javafx.scene.control.TreeView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import javafx.util.converter.NumberStringConverter; import javafx.util.converter.NumberStringConverter;
@ -24,29 +30,40 @@ public class HelloController implements Initializable{
@FXML @FXML
private Label myLabel; private Label myLabel;
@FXML
private Spinner<Integer> mySpinner;
@FXML
private Label myLabel2;
@FXML
private Rectangle myRectangle;
int currentValue;
String currentFood; String currentFood;
@Override @Override@FXML
public void initialize(URL arg0, ResourceBundle arg1) { public void initialize(URL arg0, ResourceBundle arg1) {
iCaptor it1 = new Captor("remi"); iCaptor it1 = new Captor("Capteur 1");
iCaptor it2 = new Captor("boris"); iCaptor it2 = new Captor("Capteur 2");
iCaptor it3 = new Captor("tom"); iCaptor it3 = new Captor("Capteur 3");
iCaptor it4 = new Captor("albert"); iCaptor it4 = new Captor("Capteur 4");
iCaptor it5 = new Captor("teemo"); iCaptor it5 = new Captor("Capteur 5");
ArrayList<iCaptor> array = new ArrayList<iCaptor>(); ArrayList<iCaptor> array = new ArrayList<iCaptor>();
array.add(it1); array.add(it1);
array.add(it2); array.add(it2);
iCaptor capt = new CaptorVirtual(UUID.randomUUID().toString(),array); iCaptor capt = new CaptorVirtual("Capteur virtuel",array);
TreeItem<iCaptor> root = new TreeItem<iCaptor>(new Captor("toto")); TreeItem<iCaptor> root = new TreeItem<iCaptor>(new Captor("Capteur 6"));
root.getChildren().add(it3.display()); root.getChildren().add(it3.display());
root.getChildren().add(it4.display()); root.getChildren().add(it4.display());
root.getChildren().add(it5.display()); root.getChildren().add(it5.display());
@ -55,6 +72,47 @@ public class HelloController implements Initializable{
myListTreeView.setRoot(root); myListTreeView.setRoot(root);
myListTreeView.setShowRoot(false); myListTreeView.setShowRoot(false);
SpinnerValueFactory<Integer> valueFactory =
new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 30);
valueFactory.setValue(1);
mySpinner.setValueFactory(valueFactory);
currentValue = mySpinner.getValue();
myLabel2.setText(Integer.toString(currentValue));
mySpinner.valueProperty().addListener(new ChangeListener<Integer>() {
@Override
public void changed(ObservableValue<? extends Integer> arg0, Integer arg1, Integer arg2) {
currentValue = mySpinner.getValue();
update(mySpinner.getValue());
myLabel2.setText(Integer.toString(currentValue));
}
});
}
public void update(int value){
if (value < 5)
{
myRectangle.setFill(Color.BLUE);
}
else if (value < 15)
{
myRectangle.setFill(Color.ORANGE);
}
else
{
myRectangle.setFill(Color.RED);
}
} }
public void selectItem() { public void selectItem() {
@ -62,6 +120,7 @@ public class HelloController implements Initializable{
StringConverter<Number> coucou = new NumberStringConverter(); StringConverter<Number> coucou = new NumberStringConverter();
if (captorTreeItem == null)return; if (captorTreeItem == null)return;
myLabel.textProperty().bind(captorTreeItem.getValue().temp.asString()); myLabel.textProperty().bind(captorTreeItem.getValue().temp.asString());
}); });
} }
} }

@ -6,14 +6,31 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.control.TreeView?> <?import javafx.scene.control.TreeView?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="459.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.tp.HelloController"> <?import javafx.scene.control.Spinner?>
<?import javafx.scene.shape.Rectangle?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="459.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.example.tp.HelloController">
<padding> <padding>
<Insets right="10.0" /> <Insets right="10.0"/>
</padding> </padding>
<TreeView fx:id="myListTreeView" layoutX="130.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0" onMouseClicked="#selectItem"/> <TreeView fx:id="myListTreeView" layoutX="130.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0"
<Label fx:id="myLabel" alignment="CENTER" layoutY="33.0" prefHeight="43.0" prefWidth="459.0" text="Select a food"> onMouseClicked="#selectItem"/>
<font> <Label fx:id="myLabel" alignment="CENTER" layoutY="33.0" prefHeight="43.0" prefWidth="459.0" text="Select a Captor">
<Font size="29.0" /> <font>
</font> <Font size="29.0"/>
</Label> </font>
</Label>
<padding>
<Insets right="50.0"/>
</padding>
<Spinner fx:id="mySpinner" editable="true" layoutX="655.0" layoutY="188.0"/>
<Label fx:id="myLabel2" alignment="CENTER" layoutX="520.0" layoutY="97.0" prefHeight="45.0" prefWidth="459.0"
text="Label">
<font>
<Font size="30.0"/>
</font>
</Label>
<Rectangle fx:id="myRectangle" layoutX="520.0" layoutY="400.0" arcHeight="5.0" arcWidth="5.0" fill="blue" height="200.0" stroke="BLUE" strokeType="INSIDE" width="200"/>
</AnchorPane> </AnchorPane>

@ -6,14 +6,31 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.control.TreeView?> <?import javafx.scene.control.TreeView?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="459.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.tp.HelloController"> <?import javafx.scene.control.Spinner?>
<?import javafx.scene.shape.Rectangle?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="459.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.example.tp.HelloController">
<padding> <padding>
<Insets right="10.0" /> <Insets right="10.0"/>
</padding> </padding>
<TreeView fx:id="myListTreeView" layoutX="130.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0" onMouseClicked="#selectItem"/> <TreeView fx:id="myListTreeView" layoutX="130.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0"
<Label fx:id="myLabel" alignment="CENTER" layoutY="33.0" prefHeight="43.0" prefWidth="459.0" text="Select a food"> onMouseClicked="#selectItem"/>
<font> <Label fx:id="myLabel" alignment="CENTER" layoutY="33.0" prefHeight="43.0" prefWidth="459.0" text="Select a Captor">
<Font size="29.0" /> <font>
</font> <Font size="29.0"/>
</Label> </font>
</Label>
<padding>
<Insets right="50.0"/>
</padding>
<Spinner fx:id="mySpinner" editable="true" layoutX="655.0" layoutY="188.0"/>
<Label fx:id="myLabel2" alignment="CENTER" layoutX="520.0" layoutY="97.0" prefHeight="45.0" prefWidth="459.0"
text="Label">
<font>
<Font size="30.0"/>
</font>
</Label>
<Rectangle fx:id="myRectangle" layoutX="520.0" layoutY="400.0" arcHeight="5.0" arcWidth="5.0" fill="blue" height="200.0" stroke="BLUE" strokeType="INSIDE" width="200"/>
</AnchorPane> </AnchorPane>
Loading…
Cancel
Save