Home > Back-end >  Why was added a value after the application is not successful?
Why was added a value after the application is not successful?

Time:12-23

CodePudding user response:

Can post code, and you did not indicate where don't run,,,

CodePudding user response:

reference 1/f, viewgroup response:
can post code,, and you did not indicate where don't run,,,

Import the Java. The awt. Dimension;
Import the Java. The awt. Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

The import input. WindowInput;

Public class One {

Public static void main (String [] args) {
JFrame JFrame=new JFrame (" arithmetic test program ");//define a window

Int with=200;//wide
Int height=380;//high
Dimension Dimension=Toolkit. GetDefaultToolkit (.) getScreenSize ();
//dimension is a Java class that encapsulates a component the height and width of the
JFrame. SetBounds (((int) dimension. GetWidth () - with)/2, ((int) dimension. GetHeight () - height)/2, with, height);//set the initial position
JFrame. SetResizable (false);//Settings window cannot adjust size
JFrame. SetLayout (null);//set an empty layout
JFrame. SetDefaultCloseOperation (jFrame. EXIT_ON_CLOSE);
//after the close icon to do
Random random=new Random();//set a random number
Final JLabel [] lablesA=new JLabel [10].//set the tag
Final JLabel [] lablesB=new JLabel [10].
Final JLabel [] lablesC=new JLabel [10].
Final JTextField texts []=new JTextField [10].//10 input text box
String [] operates={" + ", "-"};//add and subtract Numbers
int n=1;
WindowInput h=new WindowInput ();//input the topic number
N=h.T ran ();//assignment
for(int i=0; I & lt; n; I++) {
Int a=random. NextInt (100);//to produce random number from 0 to 100
LablesA [I]=new JLabel (" "+ a);
LablesA [I] setBounds (0, I * 30, 20, 30);//put the size and location of the
JFrame. Add (lablesA [I]);//add the component

Int operateNumber=random. NextInt (operates. Length);//set a random number 0 or 1
LablesB [I]=new JLabel (operates [operateNumber]);
LablesB [I] setBounds (30, I * 30, 20, 30);
JFrame. Add (lablesB [I]);

Int b=0;
If (operateNumber==0) {
B=random. NextInt (100 - a);//make a + b<=100
} else {
B=random. NextInt (a);//make b<=a
}
LablesC [I]=new JLabel (" "+ b);
LablesC [I] setBounds (20, 30, 60, I * 30);
JFrame. Add (lablesC [I]);

JLabel label=new JLabel ("=");
Label. SetBounds (90, I * 30, 20, 30);
JFrame. Add (label);

Texts [I]=new JTextField ();
Texts [I] setBounds (120, I * 30 + 5, 70, 20).
JFrame. Add (texts [I]);//add input text box
}

JButton button=new JButton (" score ");//set button
Button. The setBounds (0, 300, 190, 50);//the location and size of button
Button. AddActionListener (new ActionListener () {
Public void actionPerformed (an ActionEvent e) {
int count=0;
for(int i=0; I & lt; 5; I++) {
Try {
Int result=Integer. ParseInt (texts [I] getText ());//obtain the int value
Int a=Integer. ParseInt (lablesA [I] getText ());
Int c=Integer. ParseInt (lablesC [I] getText ());
If ((" + ". The equals (lablesB [I] getText ()) & amp; & A + c==result)
| | (" - ". The equals (lablesB [I] getText ()) & amp; & A - c==result)) {
count++;
}
{} the catch (Exception ex)
}
}
JOptionPane. ShowMessageDialog (null, "you got:" + count * 10 + "points", "prompt", JOptionPane. INFORMATION_MESSAGE);
}
});
JFrame. Add (button);
JFrame. SetVisible (true);
}

}

CodePudding user response:

Can run, but there is no function

CodePudding user response:

WindowInput h=new WindowInput ();//input the topic number
N=h.T ran (); What is this used for? I n fixation of 10, is a function,, is it because your h.T ran ()==0,,, see you

CodePudding user response:

refer to the second floor price by autumn response:
Quote: refer to 1st floor viewgroup response:
can post code,, and you did not indicate where don't run,,,



Look at the top, learn to code, and then mark where there is a problem,

CodePudding user response:

The
reference 4 floor viewgroup response:
WindowInput h=new WindowInput ();//input the topic number
N=h.T ran (); What is this used for? I n fixation of 10, is a function,, is it because your h.T ran ()==0,,, you look at the

I also started n is 10, yes, WindowInput h, is to define a class variable, quoting the JTextField variables in WindowInput inputNumber, I want to enter a number, and then appear as the number of questions and input digital, WindowInput is custom class, this also want to post? Or explain it?

CodePudding user response:

reference 5 floor qq_39936465 reply:
Quote: refer to the second floor price by autumn response:
Quote: refer to 1st floor viewgroup response:
can post code,, and you did not indicate where don't run,,,



Look at the top, learn to code, and then mark where there are problems,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related