Home > Back-end > For years, some directions little girl!!!! Image is the use of random Numbers, and Numbers and pictu
For years, some directions little girl!!!! Image is the use of random Numbers, and Numbers and pictu
Time:09-19
Now want to do a small game, mora (, there are three button interface, point the first button, random draw two pictures, and according to the rules in the interface to the winning party scores increase 1, after the three innings before will score compared to the results,
Click on the round 1, produce two images, according to the rules, the winners scores increase or tie,
Problems now is that I don't know how to click on the round 1 generating images, and according to the rules of the comparison, fraction increased?? Click in round 2 to regenerate the pictures,,,, I don't know how to put the following together??
The following is a block of code rule If (j.i ndex==1 & amp; & W.i ndex==1) { JOptionPane. ShowMessageDialog (null, "the bureau draw"); } If (j.i ndex==1 & amp; & W.i ndex==2) { J.s. core++; JOptionPane. ShowMessageDialog (null, "this machine brother win"); } If (j.i ndex==1 & amp; & W.i ndex==3) { Baron core++; JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win"); } If (j.i ndex==2 & amp; & W.i ndex==1) { Baron core++; JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win"); } If (j.i ndex==2 & amp; & W.i ndex==2) { JOptionPane. ShowMessageDialog (null, "the bureau draw"); } If (j.i ndex==2 & amp; & W.i ndex==3) { J.s. core++; JOptionPane. ShowMessageDialog (null, "this machine brother win"); } If (j.i ndex==3 & amp; & W.i ndex==1) { J.s. core++; JOptionPane. ShowMessageDialog (null, "this machine brother win"); } If (j.i ndex==3 & amp; & W.i ndex==2) { Baron core++; JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win"); } If (j.i ndex==3 & amp; & W.i ndex==3) { JOptionPane. ShowMessageDialog (null, "the bureau draw"); }
The event monitor code @ Override Public void actionPerformed (an ActionEvent e) { //TODO Auto - generated method stub If (um participant etSource ()==play01) {
Judge ();
}
If (um participant etSource ()==play02) {
Judge ();
}
If (um participant etSource ()==play03) { Judge (); }
}
Drawing @ Override Public void paint (Graphics g) { //TODO Auto - generated method stub Super. Paint (g); G.s etColor (Color BLACK); G.s etFont (new Font (" regular script ", the Font, BOLD, 30));
Img first of all, you should be associated with the index, so should be an array or a hashmap Should look like this when you take pictures j.i mg [j.i ndex - 1] w.i mg [w.i ndex - 1]
Then you judge () method begins to j.i ndex and w.i ndex fu random value Similar to this: The Random ran=new Random (); J.i ndex=ran. NextInt (3) + 1; W.i ndex=ran. NextInt (3) + 1;
Finally, the judge () method is the last call repaint (); The method, redrawn panel
CodePudding user response:
I and your ideas about the same, but, I don't know what happened, I always have a question, may I ask you, I send you my code