プログラミング演習の解答(第14章)の「Java言語とデータ構造をプログラミング」
英文名:Javaプログラミング入門とデータ構造、包括的なバージョン、第11版
P4
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Orientation;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
FlowPane pane = new FlowPane();
pane.setOrientation(Orientation.HORIZONTAL);
for(int i=0;i<5;i++){
Text tmp = new Text("Java");
tmp.setFont(Font.font("Times New Roman", FontWeight.BLACK, FontPosture.ITALIC,22));
Color jj = new Color(Math.random(),Math.random(),Math.random(),Math.random());
tmp.setFill(jj);
tmp.setRotate(90);
pane.getChildren().add(tmp);
}
//pane.setRotate(90);
Scene scene = new Scene(pane);
primaryStage.setTitle("problem 14.4");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
F5
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Pane pane = new StackPane();
String target = "WELCOME TO JAVA ";
for(int i=0;i<target.length();i++){
Text tmp = new Text(target.charAt(i)+"\n \n \n \n \n \n \n");
tmp.setRotate(24*i);
pane.getChildren().add(tmp);
}
Scene scene = new Scene(pane);
primaryStage.setTitle("Problem 14.5");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
P6
mport javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Pane pane = new Pane();
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
Rectangle tmp = new Rectangle();
tmp.xProperty().bind(pane.widthProperty().divide(8).multiply(j));
tmp.yProperty().bind(pane.heightProperty().divide(8).multiply(i));
tmp.widthProperty().bind(pane.widthProperty().divide(8));
tmp.heightProperty().bind(pane.heightProperty().divide(8));
if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
tmp.setFill(Color.WHITE);
else
tmp.setFill(Color.BLACK);
pane.getChildren().add(tmp);
}
}
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.setTitle("Problem 14.6");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
P7
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Pane pane = new Pane();
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
//rectangle tmp = new Rectangle();\
TextField tmp = new TextField();
//tmp.set().bind(pane.widthProperty().divide(8).multiply(j));
//tmp.yProperty().bind(pane.heightProperty().divide(8).multiply(i));
tmp.setLayoutX(40*j+5);
tmp.setLayoutY(25*i+5);
tmp.setMaxWidth(40);
tmp.setMaxHeight(10);
tmp.setText((int)(Math.random()*2)+"");
tmp.setCenterShape(true);
pane.getChildren().add(tmp);
}
}
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.setTitle("Problem 14.6");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
それを忘れて、JavaFXのが嫌、私はまだそれを振る使用