Skip to content
Snippets Groups Projects
Commit bae079e8 authored by Torbjørn Antonsen's avatar Torbjørn Antonsen
Browse files

added cards, buttons and texts

parent aa6fe9e0
No related branches found
No related tags found
1 merge request!3Feat/gui
Showing
with 108 additions and 30 deletions
package edu.ntnu.idatt2001;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.util.ArrayList;
public class Main extends Application {
private final Color DARKGRAY = Color.rgb(54, 69, 79).deriveColor(
0.0, 1.0, 0.4, 1.0);
public static void main(String[] args) {
launch(args);
......@@ -17,39 +30,104 @@ public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Stage stage = new Stage();
stage.setMaxHeight(720);
stage.setMaxWidth(1280);
stage.setResizable(false);
Group root = new Group();
Color DARKGRAY = Color.rgb(54, 69, 79).deriveColor(0.0, 1.0, 0.4, 1.0);
Scene scene = new Scene(root, 1280, 720, DARKGRAY);
Text handText = new Text("Hand");
GridPane root = new GridPane();
root.setPrefSize(1280, 800);
root.setPadding(new Insets(10, 10, 10, 10));
root.setHgap(20);
root.setVgap(20);
root.setBackground(new Background(new BackgroundFill(DARKGRAY,
new CornerRadii(0), new Insets(0))));
root.setAlignment(Pos.CENTER);
BorderPane hand = new BorderPane(handText);
DialogPane handTitle = new DialogPane();
GridPane handImages = createHandImageViews(5);
handTitle.setHeader(handText);
hand.setTop(handTitle);
hand.setCenter(handImages);
root.add(hand, 0,0);
root.add(createTextsAndTextFields(), 0, 1);
root.add(createButtons(), 1, 0);
Scene scene = new Scene(root,1280, 800, DARKGRAY);
primaryStage.setTitle("CardGame");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
ImageView imageView = new ImageView();
Image icon = new Image("card_icon.png");
imageView.setImage(icon);
primaryStage.getIcons().add(icon);
primaryStage.show();
}
public VBox createButtons() {
Button dealHand = new Button("Deal hand");
dealHand.setPrefSize(100,40);
Button checkHand = new Button("Check hand");
dealHand.setLayoutY(400);
dealHand.setLayoutX(950);
checkHand.setLayoutY(400);
checkHand.setLayoutX(1070);
root.getChildren().add(dealHand);
root.getChildren().add(checkHand);
Image card = new Image("cardBackImage.png");
ImageView imageView = new ImageView(card);
imageView.setY(-100);
imageView.setX(800);
imageView.setScaleX(0.40);
imageView.setScaleY(0.40);
String icon1 = "card_icon.png";
Image icon = new Image(icon1);
root.getChildren().add(imageView);
stage.setScene(scene);
stage.setTitle("Card Game");
stage.getIcons().add(icon);
stage.show();
checkHand.setPrefSize(100,40);
VBox vBox = new VBox(dealHand, checkHand);
vBox.setSpacing(20);
vBox.setAlignment(Pos.CENTER);
return vBox;
}
public GridPane createTextsAndTextFields() {
GridPane gridPane = new GridPane();
gridPane.setHgap(5);
gridPane.setVgap(5);
ArrayList<Text> texts = new ArrayList<>();
texts.add(new Text("Sum of the faces: "));
texts.add(new Text("Cards of hearts: "));
texts.add(new Text("Flush: "));
texts.add(new Text("Queen of spades: "));
for (Text text : texts) {
text.setFill(Color.WHITE);
}
TextField textField1 = new TextField();
TextField textField2 = new TextField();
TextField textField3 = new TextField();
TextField textField4 = new TextField();
HBox hBox1 = new HBox(texts.get(0), textField1);
HBox hBox2 = new HBox(texts.get(1), textField2);
HBox hBox3 = new HBox(texts.get(2), textField3);
HBox hBox4 = new HBox(texts.get(3), textField4);
hBox1.setAlignment(Pos.CENTER);
gridPane.add(hBox1, 0,0);
gridPane.add(hBox2, 1,0);
gridPane.add(hBox3, 0,1);
gridPane.add(hBox4, 1,1);
gridPane.setAlignment(Pos.CENTER);
return gridPane;
}
public GridPane createHandImageViews(int n) {
GridPane gridPane = new GridPane();
for (int i = 0; i < n; i++) {
String path = "cardImages/0" + (i + 1) + "c.png";
Image image = new Image(path);
ImageView imageView = new ImageView(image);
imageView.setFitHeight(100);
imageView.setPreserveRatio(true);
gridPane.add(imageView, i, 0);
}
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(5);
gridPane.setVgap(5);
gridPane.setBackground(new Background(new BackgroundFill(DARKGRAY.darker(),
new CornerRadii(0), new Insets(0))));
return gridPane;
}
@Override
......
File deleted
target/classes/01c.png

41.5 KiB

target/classes/01d.png

35.9 KiB

target/classes/01h.png

43.1 KiB

target/classes/01s.png

59.6 KiB

target/classes/02c.png

23 KiB

target/classes/02d.png

19.4 KiB

target/classes/02h.png

19.7 KiB

target/classes/02s.png

21.4 KiB

target/classes/03c.png

28.5 KiB

target/classes/03d.png

23.7 KiB

target/classes/03h.png

24.2 KiB

target/classes/03s.png

26.3 KiB

target/classes/04c.png

28 KiB

target/classes/04d.png

23.6 KiB

target/classes/04h.png

24.1 KiB

target/classes/04s.png

25.8 KiB

target/classes/05c.png

34 KiB

target/classes/05d.png

28.6 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment