皆さん、おはようございます。私は Java プログラミングの初心者です。要するに、ボタンをクリックするだけで .txt ファイルを読み取ってコンパイルできるプログラムを作成しています。
ファイルの読み取りはすでに完了しています。私の問題は、プログラムが最初の JTextArea からのテキストをコンパイルせず、結果を 2 番目の JTextArea に表示しないことです。
私はこの問題を 4 日間抱えており、考えられるあらゆる方法でコードを変更しようとしています。誰かが私を啓発し、私のコードの何が問題なのか教えてもらえますか? それは確かに私を大いに助けます。
すべてに感謝します。
@SuppressWarnings("IncompatibleEquals")
private void executeCodeActionPerformed(java.awt.event.ActionEvent evt) {
String loadi = "Load";
String add = "Add";
String subt = "Subt";
String mult = "Mult";
String div = "Div";
String input = "Input";
String print = "Print";
int number = 0;
String txt = textAreaCode.getText();
String split = " ";
String [] text = txt.split(split);
String word = text[0];
int num = Integer.getInteger(text[1]);
int result = num;
int result1 = 0;
Scanner scan = new Scanner(txt);
scan.nextLine();
for (int count=0;count<txt.length();count++ ) {
if (loadi.equalsIgnoreCase(word)){
result1 = num + number;
}
else if (add.equalsIgnoreCase(word)){
result1 = num + result;
}
else if (subt.equalsIgnoreCase(word)){
result1 = num - result;
}
else if (mult.equalsIgnoreCase(word)){
result1 = num * result;
}
else if (div.equalsIgnoreCase(word)){
result1 = num / result;
}
else if (print.equalsIgnoreCase(word)){
textAreaOutput.setText(String.valueOf(result1));
}
else if (input.equalsIgnoreCase(word)){
String nmbr = inputField.getText();
int nmr = Integer.parseInt(nmbr);
result1 = nmr + number;
}
}