を許可していません。私の立場からすれば、私のコードは合格点を得るのにかなり良いですが、簡単なリフレッシュ/シャッフルボタンを追加するのに問題があります。 JOptionPaneの補助を使用しないでください。 Eclipseは、ボタンが実際にノードであり、それが作成されているノードに関する何かを私に伝えているので、私が意味をなさないボタンを作成したことを認識しているようです。しかし、私が別のクラスに入り、3行の例で別のボタンを追加すると、それは単に機能します。しかし、私が宿題プログラムに移動すると、プログラム全体を壊すaddメソッドにエラーが表示されるだけです! はJavaで単純なボタンを追加しても、Javaは私に
誰もが、私は私のコードで間違って行くことができどこのいくつかの光を当てるか?「(ボタン)メソッドがタイプ一覧で(ノード)を追加arguementsには適用されません」
は言いますかそれは、文字列変換へのノードに沿った何かでなければならないか、私はそれを理解できないようである。私に与えられたヒントはありますが、私には問題を解決してはいけません。
基本的に本の質問です。 "ユーザーがリフレッシュボタンをクリックすると、54枚のカードのデッキから4枚のカードを表示できるプログラムを作成します。"
私はちょうどボタンthatsすべての助けが必要です。私は文字通り残りを持っています。
ここまでは私のコードです。 私は輸入品をあまりにも多く含んでいます。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import java.awt.Button;
import java.io.File;
import java.util.ArrayList;
public class Cards extends Application
{
public void start(Stage primaryStage)
{
ArrayList<String> cards = new ArrayList<>(); //Array list
Shuffle(cards); //Shuffles the Cards
String file1 = new File("cards" + "/" + cards.get(1) + ".png").toURI().toString();
String file2 = new File("cards" + "/" + cards.get(2) + ".png").toURI().toString();
String file3 = new File("cards" + "/" + cards.get(3) + ".png").toURI().toString();
String file4 = new File("cards" + "/" + cards.get(4) + ".png").toURI().toString();
Pane pane = new HBox(20); //Creates the Box for the Images
pane.setPadding(new Insets(5, 5, 5, 5)); //Spreads the Images out
Image image = new Image(file1); //Creates the String Image
Image image2 = new Image(file2);
Image image3 = new Image(file3);
Image image4 = new Image(file4);
pane.getChildren().add(new ImageView(image)); //Adds the First Image
ImageView view1 = new ImageView(image);
view1.setFitHeight(100);
view1.setFitWidth(100);
pane.getChildren().add(new ImageView(image2)); //Adds the Second Image
ImageView view2 = new ImageView(image2);
view2.setFitHeight(100);
view2.setFitWidth(100);
pane.getChildren().add(new ImageView(image3)); //Add the Third Image
ImageView view3 = new ImageView(image3);
view3.setFitHeight(100);
view3.setFitWidth(100);
pane.getChildren().add(new ImageView(image4)); //Add the Fourth Image
ImageView view4 = new ImageView(image4);
view4.setFitHeight(100);
view4.setFitWidth(100);
HBox hbox = new HBox(5); //Creates the Box for the Button
Button shuffle = new Button("Shuffle"); //Creates the Button
hbox.getChildren().add(shuffle); //Should add the button but doesn't
shuffle.addActionListener(e -> //Listener for the button
{
Shuffle(cards);
});
BorderPane pane2 = new BorderPane();/ /Creates the Pane for the Button
pane2.setCenter(pane); //Sets the cards in the Center
pane2.setBottom(hbox); //Sets the Button on the bottom
BorderPane.setAlignment(hbox, Pos.CENTER);
hbox.setAlignment(Pos.BOTTOM_CENTER);//Aligns the Button to BOT_CENTER
Scene scene = new Scene(pane2); //Creates the Scene
primaryStage.setTitle("Cards");
primaryStage.setScene(scene);
primaryStage.show();
}
public void Shuffle(ArrayList<String> cards)
//Allows the cards to Shuffle when called.
{
for (int i = 0; i <= 53; i++) //Sets the Number of Cards in Deck
cards.add(String.valueOf(i+1));
java.util.Collections.shuffle(cards);
}
public static void main(String[] args)
{
launch(args);
}
}
わからないけど、以前のコード内を与える
を、あなたは 'ペインペインは=新しいのHBox(20)を行います。 pane.setPadding(新しいInsets(5,5,5、5)); 'このパターンに従う必要がありますか? –
@ScaryWombat私は、ボタンを適切にプログラムに挿入する方法を見つけたら、リフレッシュボタンの上に適切にカードを設定するので、そこにペインが必要なのです。プログラムにコメントを追加します。 – Vinnie
あなたの__import__声明を教えてください。私はSwing開発者ではありませんが、Java Swing(https://docs.oracle.com/javase/7/docs/api/javax/swing/ButtonModel.html#addActionListener(java)を使用していると思います。 awt.event.ActionListener))ではなく、JavaFXボタン... – SSchuette