import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class AndroidApp extends JFrame implements ActionListener {
private AnswerButton questionOneButtonA;
private int totalScore;
private JButton finishButton;
private JLabel totalScoreLabel;
public AndroidApp(){
setSize(500,500);
setLayout(null);
questionOneButtonA = new AnswerButton("Choice 1",10);
questionOneButtonA.setActionCommand("questionOneChoice1");
questionOneButtonA.setBounds(50,50,100,20);
questionOneButtonA.addActionListener(this);
add(questionOneButtonA);
finishButton = new JButton("Done");
finishButton.setBounds(50,100,100,20);
finishButton.setActionCommand("done");
finishButton.addActionListener(this);
add(finishButton);
totalScoreLabel = new JLabel("0");
totalScoreLabel.setBounds(200,200,100,50);
add(totalScoreLabel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand().equals("questionOneChoice1")){
totalScore+=questionOneButtonA.getPointValue();
}
else if(ae.getActionCommand().equals("done")){
totalScoreLabel.setText(""+totalScore);
}
}
public static void main(String[]args){
AndroidApp test = new AndroidApp();
}
class AnswerButton extends JButton{
private int pointValue;
public AnswerButton(String buttonName, int p){
super(buttonName);
pointValue = p;
}
public int getPointValue(){
return pointValue;
}
}
}
Just give the correct Answer button a certain amount of points, and give the incorrect answer 0 points.