多くの調査と試行錯誤の後、 aString
からランダムに選択された a を正確に取得し、 aを押した後に文字ごとに a に印刷するString Array
方法を見つけることができません。私はこれがぎこちなく聞こえることを知っています...ぎこちなく聞こえるようにするためにそれをどのように表現するか正確にはわかりませんでした. だから、これが私が作ったクラスで、 をにします。Array
String Array
JTextField Array
JButton
JTextField Array
JPanel
package wheelOfFortune;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.*;
import java.util.List;
import java.util.ArrayList;
public class letterBoard extends JPanel
implements ActionListener
{
private static JTextField[] fields;
private static final String wheelFoods[] = {"PASTRAMI SANDWICH","PEANUT BUTTER","JAR OF PICKLES","NUTELLA SPREAD","SPAGHETTI AND MEATBALLS","BUTTERED LOBSTER","KING CRAB","PIRATES BOOTY","ORANGE JUICE","GRILLED STEAK","MOLTEN LAVA CAKE"};
private static final String wheelHouse[] = {"BURNT OUT LIGHTBULB", "VACUUM CLEANER","DESKTOP COMPUTER", "ANTIQUE FURNITURE","FLATSCREEN TELEVISION","COFFEE TABLE","MAHOGANY DESK","GARDENING SUPPLIES","REMOTE CONTROLLER"};
private static final String wheelMovies[] = {"SAVING PRIVATE RYAN","THE GREAT GATSBY", "ZOOLANDER","ANCHORMAN","STEP BROTHERS","THE DARK NIGHT RISES",
"PULP FICTION","FIGHT CLUB","THE SIXTH SENSE","DJANGO UNCHAINED","SHUTTER ISLAND","THE EVIL DEAD","THE NOTEBOOK","FORREST GUMP","HAPPY GILMORE","THE CHRONICLES OF NARNIA",
"BILL AND TEDS MOST EXCELLENT ADVENTURE","HAROLD AND KUMAR","HARRY POTTER","THE SHAWSHANK REDEMPTION", "THE TERMINATOR", "THE BLUES BROTHERS", "V FOR VENDETTA"};
private static final String wheelPeople[] = {"OPRAH WINFREY","SPONGEBOB SQUAREPANTS","PATRICK STAR", "LEONARDO DICAPRIO","WILL FERRELL", "NEIL ARMSTRONG", "BARACK OBAMA", "JON TRAVOLTA", "ARNOLD SCHWARZENEGGER", "JAMES FRANCIS RYAN", "MS VOLDSTAD",
"BILLY MAYS", "EDWARD SCISSORHANDS","BILL GATES", "STEVE JOBS", "GANDOLF THE GRAY","TWOCHAINZ","RICK ASTLEY"};
private static final String wheelPlaces[] = {"THE EIFFEL TOWER","MOUNT RUSHMORE","THE MOON", "THE GREAT WALL OF CHINA", "FISHERMANS WARF", "DISNEYLAND", "UNDERNEATH A DESK IN A CLASSROOM", "THE GREAT PLAINS", "THE GREAT BARRIER REEF", "AMERISTRALIA", "THE EMPIRE STATE BUILDING",
"THE NORTH POLE", "THE SPACE NEEDLE", "THE KRUSTY KRAB","WEENIE HUT JUNIOR","THE FORBIDDEN PALACE","MORDOR", "NARNIA","THE LAST STALL ON THE LEFT", "INSIDE OF A BOUNCY HOUSE"};
private static final String wheelRandom[] = {"A BOWL OF OATMEAL","LEMON PLEDGE","GREASY HAMBURGERS", "STAINED PANTS", "A CUP OF CHOCOLATE MILK", "ROLLY CHAIRS", "BENDY STRAWS", "WIENER DOGS", "AN ANGRY OSTRICH", "BART SIMPSON","A CONFUSED MOUNTAIN COW",
"BIGFOOT", "THE ILLUMINATI", "THE C HALL BATHROOMS", "A SHAVED BABOON", "THE SPICE GIRLS", "I AM STUPID"};
private Box[] boxes = new Box[SUIT_COUNT];
private static int TEXT_FIELD_COUNT = 14;
private static int SUIT_COUNT = 1;
Color yungMoney = new Color(0, 180, 100);
private static String puzzle;
private static List<JTextField> field;
private static String[][] puzzles = {wheelFoods, wheelHouse, wheelMovies, wheelPeople, wheelPlaces, wheelRandom};
private static String[] puzzless;
private static JPanel panel;
public letterBoard()
{
fields = new JTextField[TEXT_FIELD_COUNT];
setPreferredSize(new Dimension(1,299));
setBackground(yungMoney);
JPanel panel = new JPanel(new GridLayout(0,14));
panel.setBackground(yungMoney);
for(int t=0; t<4; t++)
{
for (int i =0; i < boxes.length; i++)
{
boxes[i] = Box.createHorizontalBox();
for (int j=0; j< TEXT_FIELD_COUNT/SUIT_COUNT; j++)
{
int index = i * (TEXT_FIELD_COUNT/SUIT_COUNT) + j;
fields[index] = new JTextField(" ");
fields[index].setEditable(false);
fields[index].setPreferredSize(new Dimension(50, 50));
fields[index].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
panel.add(fields[index]);
}
}
}
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,2),"WHEEL OF FORTUNE"));
add(panel);
}
public static String findPuzzle()
{
for(int i=0; i<puzzles.length;i++)
{
puzzless = puzzles[(int) Math.round(Math.random() * (puzzles.length-1))];
for(int j=0; j<puzzless.length; j++)
{
puzzle = puzzless[(int) Math.round(Math.random() * (puzzless.length-1))];
}
}
return puzzle;
}
public static void reset()
{
findPuzzle();
field = new ArrayList<>(puzzle.length());
for(int k=0;k<puzzle.length();k++)
{
field.add(fields[k]);
}
}
public void actionPerformed(ActionEvent e)
{
//game logic
}
}
したがって、JTextField Array
は class のコンストラクター内で形成されますletterBoard
。コンストラクターは機能しており、想定どおりに動作します。ただし、String puzzles[][]
パズルがファイリングされるさまざまな配列を保持する (これは運命の輪ゲームです。各個人array
は、内部にパズルがあるカテゴリなどです) は、私が望むようには機能しません。私が本質的にやりたいことはこれです: メソッドreset()
は、コンストラクターで形成された letterBoard を取り、メソッドでString
選択されたもので埋めfindPuzzle()
ます。そこからActionListener
、メイン クラスのwheelGUI
が に接続されJButton reset
、押されたときにreset()
からメソッドを呼び出す必要があります。letterBoard
クラスを作成し、ボードから現在のパズルを消去し、からランダムに選択された新しい文字列で埋めて、puzzles[][]
ゲームプレイの新しいラウンドを可能にします。これが少し混乱している場合は申し訳ありません。私はそれで混乱しています。に書き込むためのチュートリアルをいくつか見ましたStrings
がJTextFields
、私の設定は少し異なり、その方法が機能しません。これをご覧いただきありがとうございます。必要に応じてクラス コードを投稿しwheelGUI
ますが、この問題に関連する情報が含まれているとは思いません。再度、感謝します。