#help with button in mainframe (calculator)
1 messages · Page 1 of 1 (latest)
only glanced your code, after the calc.sett.. do u update the screen value ?
no that's not what im asking
u do some math in the add method
then u set calc.sett ...
do u upate the gui after ?
that's what im asking. Are u asking it to update after that code :p
no no need for screenshots, just try to answer the question
u set the value in the calculator
after that, are u telling the GUI to update or not ?
where is the update ?
( your code is messely ported over to the gist )
ok il try to rephrase
your gui had an action
so u send stuff to the backend
after that has been send, are u asking your GUI to update ( redraw ) ?
ou ?
( where )
unless the bot really messed up the gist creation, the only text change i'm seeing is set to 0
yea the textfield
yes , so that the GUI reads from the backend
u got an inital set to 0 in your code
alot of getters from the textfield towards your backend
but no result send to it
A gui does not automaticly update when the backend value is changed so that code section is quite needed
before u go off to think in weird solutions, do u understand what im asking ?
now where does it read from the calculator ?
u gui does not do things on its own, it needs to be instructed to do things
can u please answere where it does that ?
i cant see it in the code that u uploaded, and that's most likely where the problem is
your answer is this -> the calculator reads from the textfield
im asking the inverse
where does the textfield gets it value out of the calculator
right, can u post the code where it does that ?
ty, that was not added to the initial gist
mm it was added
@winter heart this is the name of the textfield correct ?
currentValueTextField
the only value your setting to is it the initial 0
do u have an update method where it reads from the calculator class ?
( even the initial 0 should come from the calc. )
that return currentvalue
that does not instruct the textfield to change its contents
ok lets try something else
what normally happens is this
enter data in gui, event happends, backend reads from gui and does its work. Then gui gets instructed to redraw / update the sections that are changed
do u grasp that concept ?
u got all the code that goes to the backend
u got no code that tells the gui to update
the only output your sending towards your textfield is the initial string 0
no your correct
after the backend does it work, u need to tell the frontend to do an update
so (because u got multiple operations possible )
u make a method called ( example) updateResult where u set the textfields contents to the result of the calculator
and u call that method at the end of every possible operation
yeah u can do that aswell, if u place the instrructions in each operation
Not really a smart thing to do, cause if u need to change it, u need to change it all over the place
why are u not reading from your calculator ?
your mainframe class has a private Calculator calc. Also where your sending your frontend data to. So it would be logical to read data from calc. aswell ?
right
and did u fix your overwrite in the add method ?
double currentValue = calc.getCurrentValue();
calc.add(Double.valueOf(currentValueTextField.getText()));
calc.setCurrentValue(currentValue);
basicly your saying, read in currentvalue, do some math, overwrite with old result
no, but try it out
the concept should be good, there 's a small detail u need to add after, but try to get it working first
then worry on the user's possibly wrong input
nice
that depends on how u made it. IF its possible to enter wrong values, then u need to counter them
on your screenshot i'm not seeing any 0-9 and no negative toggle so i'm assuming that's typed
no your overthinking it
are u typing in the numbers or are they buttons ?
if its typing -> assume wrong input WILL happen
so u need to counter that 😉
do u know what a mistake would be ?
judging from the time on the respons , not really
what would happen if u type in a word ?
try it
what does it show ?
that's not nothing lol
that's your program chrashing
no
that's what i said, u got 0 input checking at the moment
u need to add that
else your program will fatal
rather sure that u already have seen it
do u know how grasp letters and such out of words ?
all u have to do is check that the thing typed only contains valid characters
pas grave, mais je dois aller cherge ma famme a la gare. Il faut justement verifie si le mot qui est dans le textfield est valable avec tous les possibilites dun calculatrice
( just need to check that the text contents matched a calculator max use ) 0123456789./*-+ and whatever u need
Closed the thread.