mardi 27 septembre 2016

How to get conditionally assigned value from another class

I'm having some issues on using a conditionally assigned value in more than one class. I want to apply the use of a value in one class if and only if a condition is met, then use it in some-other class to add up to a total score. this is my code!

        public class help extends JFrame {
            JPanel hold = new JPanel ();
            JTextField enter = new JTextField(10);
            JButton check = new JButton ("Check answer");
            JButton quest = new JButton ("See question");
            JLabel lunch = new JLabel ("Who is the current President of the United States?");

         public help () {

             hold.setLayout(new BorderLayout());

             hold.add(quest, BorderLayout.EAST);

             quest.addActionListener(new ActionListener () {
                 public void actionPerformed (ActionEvent f ) {

                hold.add(lunch, BorderLayout.NORTH);
                 hold.add(enter, BorderLayout.CENTER);
                hold.add(check, BorderLayout.SOUTH);
        }
        });

           check.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent h) {

                  if (enter.getText().equals("Barack Obama")) {

                        String o = "Correct";
                        JOptionPane.showMessageDialog(null, g);
                         int score = 3;
        }
              else {
                      String p = "Wrong, the answer is Barack Obama";
                      JOptionPane.showMessageDialog(null, p);
                             int fail = 0;
        //I also prepared about 10 more classes in the same way, 
    I want to get all the fails (if any) and add them to the scores (if any), then project it as a total, 
    but this has to be done in another class. 
    What do I do, how do I do it! I need help.....!
        }
}
});

   hold.setSize(400,500);
   hold.setOpaque(false);
   hold.setVisible(true);
   hold.setLocation(100,50);
   add(hold, BorderLayout.CENTER);
}
public static void main (String [] args) {
  help helo = new help();
  helo.setSize(500, 600);
  helo.setVisible(true);
  helo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  helo.setResizable(false);
  helo.pack();
}
}

Aucun commentaire:

Enregistrer un commentaire