Home > Back-end >  Cooking chicken online for help
Cooking chicken online for help

Time:09-30

Want to find a more than take a calculator, but have been an error that dividend is equal to zero (run time dial a number, then take more than just an error say zero dividend) as shown in figure is the code of the program. The

CodePudding user response:

quoted rookie of the building Lord what also won't reply:
want to find a more than take a calculator, but have been an error that dividend is equal to zero (run time dial a number, then take more than just an error say zero dividend) as shown in figure is program code


Initialization because your number is zero, this is your program logic problems, according to the arithmetic operations must not! Order at least 2 after the number of input lines,

CodePudding user response:

reference 1st floor qq_39936465 response:
Quote: refer to the original poster what rookie will not reply:

Want to find a more than take a calculator, but have been an error that dividend is equal to zero (run time dial a number, then take more than just an error say zero dividend) as shown in figure is program code


Initialization because your number is zero, this is your program logic problems, according to the arithmetic operations must not! Order at least 2 after the number of input lines,
no, text box does 0 initial content?? After pressing a button, but the content of the text box becomes according to all the number, then press operation button by value, thus currentNumber values into the figures in the text box, and the result is equal to the press before more than take forever

CodePudding user response:

refer to the second floor what rookie will not reply:
no, text box does 0 initial content?? After pressing a button, but the content of the text box becomes according to all the number, then press operation button by value, thus currentNumber values into the figures in the text box, and the operation result always equal to the press before taking more than the value of the



You don't see your error is on line 81? Your program logic has a problem, your program and you want to achieve is 2, before of your compute method for '? 'there is no true, so your number has been zero,

CodePudding user response:

Your program look really hard to change the actionPerformed to the following good, why would monitor cycle!
 
Public void actionPerformed (an ActionEvent arg0) {
//TODO Auto - generated method stub
String STR=JTF. GetText ();
JButton BTN=(JButton) arg0. GetSource ();
If (BTN. GetText () equals ("=")) {
Compute ('=');
Equal=true;
} else if (BTN. GetText () equals (" % ")) {
Compute (' % ');
JTF. SetText (" 0 ");
Equal=false;
} else if (STR) equals (" 0 ")) {
JTF. SetText (" "+ BTN. GetText ());
{} else if (operate)
JTF. SetText (" "+ BTN. GetText ());
Operate=false;
} else {
JTF. SetText (STR + BTN. GetText ());
}

}

CodePudding user response:

reference 4 floor qq_39936465 response:
your program look really hard to change the actionPerformed to the following, why would monitor cycle!
 
Public void actionPerformed (an ActionEvent arg0) {
//TODO Auto - generated method stub
String STR=JTF. GetText ();
JButton BTN=(JButton) arg0. GetSource ();
If (BTN. GetText () equals ("=")) {
Compute ('=');
Equal=true;
} else if (BTN. GetText () equals (" % ")) {
Compute (' % ');
JTF. SetText (" 0 ");
Equal=false;
} else if (STR) equals (" 0 ")) {
JTF. SetText (" "+ BTN. GetText ());
{} else if (operate)
JTF. SetText (" "+ BTN. GetText ());
Operate=false;
} else {
JTF. SetText (STR + BTN. GetText ());
}

}

I tried, do you like this method of work, because I according to the text box will be displayed when==sign, so you have erreo

CodePudding user response:

reference qq_39936465 reply: 3/f
Quote: refer to the second floor what rookie will not reply:

No, initial content of 0 indeed text box?? After pressing a button, but the content of the text box becomes according to all the number, then press operation button by value, thus currentNumber values into the figures in the text box, and the operation result always equal to the press before taking more than the value of the



You don't see your error is on line 81? Your program logic has a problem, your program and you want to achieve is 2, before of your compute method for '? 'there is no true, so your number has been 0,
on study, I still don't quite understand why wrong, at first? , and then after I press the Numbers, symbols or? , and then press the operator, or a temporary sign? , meet the first if statement, assignment, number from 0 to the number in the text box, and then compute method finally give before the press operation assignment, so before became a operator, and then according to the second time according to Numbers, then compute method according to the equal sign call operation

CodePudding user response:

what won't refer to 5 floor novice response:
I tried, do you like this method of work, because I according to the text box will be displayed when==sign, so you have erreo


 
@ SuppressWarnings (" serial ")
Public class MyFrame extends JFrame implements ActionListener {
String [] s={" 1 ", "2", "3", "4", "5", "6", "7", "eight" and "9", "0", "%", "="};
JPanel contenPanel jp1;
JButton bt []=new JButton [s.l ength];
JTextField JTF;
Char before='0';
Int number=0;
Boolean operate=false, equal=false;

Public MyFrame () {
//TODO Auto - generated constructor stub
SetSize (300, 200);
SetDefaultCloseOperation (EXIT_ON_CLOSE);
SetTitle (" take more than a calculator ");
SetResizable (false);
SetLocationRelativeTo (null);
JPanel contentPanel=(JPanel) getContentPane ();
JTF=new JTextField (" 0 ");
JTF. SetEditable (false);
GridLayout layout=new GridLayout (3, 0, 5, 5);
Jp1=new JPanel ();
Jp1. SetLayout (layout);
For (int I=0; I & lt; S.l ength; I++) {
Bt [I]=new JButton (s [I]);
Jp1. Add (bt [I]);
Bt [I] addActionListener (this);
}
ContentPanel. Add (jp1);
ContentPanel. Add (JTF, BorderLayout. NORTH);
setVisible(true);
}

@ Override
Public void actionPerformed (an ActionEvent arg0) {
//TODO Auto - generated method stub
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related