我在寫一個測驗應用程序,當您回答正確的問題並且分數增加時,您會得到分數,我必須使用if語句。請任何人知道如何在if語句中使用if語句中的值!我有點困惑,它讓我在這裏工作......感謝您的幫助!...這是一個小小的代碼示例;在if語句中使用if語句的結果
int x = 3;
String xy = Integer.toString(x);
int y = 0;
String yy = Integer.toString(y);
JButton one = new JButton ("Quest 1");
one.addActionListener (new ActionListener(){
public void actionPerformed(ActionEvent p) {
JFrame ex = new JFrame();
ex.setTitle("Question 1);
ex.setSize(400, 400);
ex.setLayout(new FlowLayout());
ex.setBackground(Color.WHITE);
JLabel ey = new JLabel ("What is the capital of Japan?);
Font tan = new Font ("Script MT Bold", Font.BOLD, 18);
ey.setFont(tan);
ey.setForeground(Color.BLACK);
ex.add(ey, BorderLayout.NORTH);
JButton answ = new JButton("submit");
JTextField g = new JTextField (10);
g.setFont(tan);
String ans = "Tokyo";
String merit = "Correct";
String flop = "wrong";
String mer = merit + ans;
String flip = flop + ans;
answ.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent p) {
if (g.getText.equals("Tokyo") {
JOptionPane.showMessageDialog(null, mer);
one.setText(xy);
}
else {
JOptionPane.showMessageDialog(null,flip);
one.setText(yy);
}
//In my next Action Listener, I would love to
//pick the score from the previous listener....and add to the next score....
//So that we have something like ....
//x(updated from previous listener) + x
ex.add(g, BorderLayout.SOUTH);
}
});
}
});
請多花一點時間和精力來解釋您的問題,因爲由於您提供的信息很少,所以這是相當混亂的。 –
爲什麼再次下臺?......關於這個問題還不清楚嗎? –
我不能肯定地說,但你還沒有發佈[mcve],還沒有澄清你是否在一個位上。 –