Я работаю с javafx и начал работать над стилей формы. Я создал программу, которая создала бы слабое шифрование для вашего текста, но это не сделано полностью.Styling Javafx с CSS
Вот код Java -
public class encryption extends Application {
private static StringBuffer password;
private static int key;
public void setValue(String value) {
password = new StringBuffer(value);
}
public void encryption() {
RNG();
for(int i = 0; i < password.length(); i++) {
int cValue = (int)password.charAt(i);
int nValue = cValue^key;
password.setCharAt(i, (char)nValue);
}
System.out.println(password);
System.out.println("");
}
public void RNG() {
Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
key = rand.nextInt(((222 - 8) + 1) + 8)^26;
}
public void decryption() {
for(int i = 0; i < password.length(); i++) {
int nValue = key^password.charAt(i);
password.setCharAt(i, (char)nValue);
}
System.out.println(password);
}
public void start(Stage arg0) throws Exception {
StringBuffer eLabel = new StringBuffer();
Scene scene;
VBox container = new VBox();
HBox root = new HBox();
HBox rootA = new HBox();
HBox rootB = new HBox();
Label instructions;
Button submit;
Button reveal;
PasswordField message;
Label encryption;
Label typed;
instructions = new Label("Submit Label that you want to encrypt");
root.getChildren().add(instructions);
message = new PasswordField();
message.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent e) {
if(e.getCode() == KeyCode.ENTER) {
System.out.println(message.getText());
setValue(message.getText());
encryption();
decryption();
}
}
});
submit = new Button("Click to Submit");
typed = new Label();
typed.setId("value");
rootA.getChildren().add(message);
rootA.getChildren().add(submit);
reveal = new Button("Show Text");
reveal.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent arg0) {
typed.setText(message.getText());
}
});
rootB.getChildren().add(reveal);
rootB.getChildren().add(typed);
container.getChildren().add(root);
container.getChildren().add(rootA);
container.getChildren().add(rootB);
scene = new Scene(container, 1000, 500);
String css = "encryption.css";
scene.getStylesheets().add(css);
Stage stage = new Stage();
stage.setScene(scene);
stage.setTitle("Javafx Encryption");
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Вот CSS -
.root {
-fx-text-fill: rgb(49, 89, 23);
-fx-background-color: #202020;
}
.button {
-fx-background-color: red;
-fx-text-fill: black;
}
.vbox {
-fx-background-color: white;
-fx-spacing: 10;
-fx-height: 100%;
}
.hbox {
-fx-background-color: #502576;
-fx-spacing: 10;
}
#value {
-fx-font-size: 12px;
}
.label {
-fx-font-size: 20px;
-fx-text-fill: white;
}
HBox не получает примененные изменения наряду с VBox.
Почему hbox и vbox не получают изменений из css?
На самом деле, есть способ сделать это. Просто взгляните на этот [вопрос] (http://stackoverflow.com/questions/35290665/javafx-style-all-nodes-of-the-same-type-eg-vbox/35291537#35291537) – Amin