さて、スキャナーからSystem.inを取得し、入力を文字列に配置し、入力に基づいてボタンレイアウトを作成するプログラムを作成しようとしています。私は Java の初心者で、多少独学なので、これがファンキーに見える場合は、私がプロではないためです。
else if(wordReader.endsWith("\r")){
//Create grid layout (one below other)
GridLayout buttonReturn = new GridLayout(0,i);
contentPane.setLayout(buttonReturn);
System.out.println("This has a new line value");
i++;
wordReader.replaceAll("\r","");
buttonVal = new JButton (wordReader);
buttonVal.addActionListener(new ButtonListener());
buttonVal.setEnabled(true);
contentPane.add(buttonVal, BorderLayout.NORTH);
Border emptyBorder = BorderFactory.createEmptyBorder();
buttonVal.setBorder(emptyBorder);
}
else {
//Create button layout(side by side)
FlowLayout buttonLayout = new FlowLayout();
contentPane.setLayout(buttonLayout);
contentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
buttonVal = new JButton (wordReader);
buttonVal.addActionListener(new ButtonListener());
buttonVal.setEnabled(true);
contentPane.add(buttonVal, BorderLayout.NORTH);
Border emptyBorder = BorderFactory.createEmptyBorder();
buttonVal.setBorder(emptyBorder);
}
私の質問: 私がやりたいのは、すべての単語のボタンを作成することですが、それらのボタンを紙の形式に似た形式で表示します。つまり、人がキャリッジ リターン ボタンを押すと、FlowLayout (横並び) はもう必要ありませんが、前のボタンの下にキャリッジ リターンがある次のボタンを移動したいと考えています。これは可能ですか?FlowLayout から GridLayout に移動して次のボタンを下に移動しようとしていましたが、読んでもそれが可能かどうかはわかりません。これを行う方法はありますか?
コンソールで実行せずにキャリッジ リターン ボタンを検出する方法はありますか?
多数の指示、記事、フォーラム、および Q&A 投稿 (このサイトを含む) に目を通しましたが、やりたいことを実行できるものを見つけることができないようです。後で System.in の代わりにファイルから読み取るためにこれを行うので、それが説明しやすい場合は、自由に試してみてください:) 繰り返しますが、私はこれにかなり慣れておらず、正式なトレーニングがほとんどないため、ばかげています。専門用語を省略していただければ幸いです。どうもありがとうございました。