Time |
S |
Nick |
Message |
06:59 |
|
aditsu |
hi |
07:58 |
|
|
mr_lou joined ##friendlyjava |
08:57 |
|
|
kirua_ joined ##friendlyjava |
18:34 |
|
|
javabegina joined ##friendlyjava |
18:35 |
|
javabegina |
good evening |
18:35 |
|
aditsu |
hi |
18:36 |
|
javabegina |
i have a problem with a GUI application is it possible to get some tips here? |
18:36 |
|
aditsu |
it is possible :) |
18:37 |
|
javabegina |
:-) |
18:38 |
|
javabegina |
actually i am new to java and wrote a small program for plotting graphs. the problem i have is i dont know how i can Update my GUI. in the case the Center of a BorderPane. I got a button when i press it the Graph will be plotted but it never erases the previous one so that i get 2 Lines. how i can archieve that? https://pastebin.com/1L4TKA0W |
18:39 |
|
javabegina |
this is not the fill code since the full code persist of more classes. but i think it should be enough to have an overview. |
18:39 |
|
javabegina |
full* |
18:40 |
|
aditsu |
ah, javafx |
18:40 |
|
javabegina |
i asked already in the java channel but none helped me out. |
18:40 |
|
javabegina |
yes javafx |
18:41 |
|
javabegina |
i m actually very stuck. i was looking some tutorials most of them talk about oberserver patterns or timers but they dont explain how i refresh a whole GUI / part of a GUI. |
18:42 |
|
aditsu |
it looks like you draw the graph by adding some Path elements to the centerContent |
18:43 |
|
javabegina |
center content is the middle Pane where i draw everything |
18:43 |
|
aditsu |
you also make some Ellipse dots, but you don't seem to use them for anything |
18:43 |
|
javabegina |
i use them |
18:43 |
|
javabegina |
the Ellipse dots are deactivated |
18:44 |
|
javabegina |
atm. they actually just show where the coords will be placed on the graph |
18:44 |
|
aditsu |
anyway, to clear the graph, you should probably remove all the children of centerContent |
18:44 |
|
javabegina |
hm something like: root.getChildren().clear(); ? |
18:45 |
|
aditsu |
probably, you can try that |
18:46 |
|
javabegina |
i tried it in the update method earlier. it completely messesup the layout after i put root.getChildren().add(centerContent); |
18:46 |
|
aditsu |
do it at the beginning of plotGraph |
18:46 |
|
javabegina |
i did that |
18:46 |
|
javabegina |
it actually will but itself over the topMenu smh |
18:47 |
|
javabegina |
uhh wait. i need to set it again to the center no? |
18:47 |
|
javabegina |
root.setCenter(centerContent); |
18:47 |
|
aditsu |
that shouldn't be necessary |
18:48 |
|
javabegina |
hm if i simply add it the centerContent overlaps the whole BorderPane like it has no fixed position |
18:48 |
|
javabegina |
and my textfield nor the button is accessible |
18:49 |
|
aditsu |
can you try to make a self-contained example? it's hard to know what you mean without being able to run the code |
18:50 |
|
javabegina |
uff wait |
18:50 |
|
javabegina |
i think it works now |
18:51 |
|
javabegina |
enterContent.getChildren().clear(); does the magic in the update() function |
18:51 |
|
javabegina |
centerContent.getChildren().clear() |
18:51 |
|
javabegina |
i do not even need to add it again |
18:52 |
|
aditsu |
oh, I just realized you wrote *root*.getChildren().clear() before |
18:52 |
|
javabegina |
yes |
18:52 |
|
javabegina |
my mistake |
18:52 |
|
javabegina |
root remove the whole Panes top center and bottom |
18:52 |
|
javabegina |
which ruined the whole view |
18:53 |
|
aditsu |
right |
18:54 |
|
javabegina |
https://gyazo.com/195ad3bed27dd2d15e91f32a0b056e37 |
18:54 |
|
javabegina |
works now perfectly |
18:54 |
|
aditsu |
alright 👍 |
18:54 |
|
javabegina |
many thanks for your help |
18:55 |
|
aditsu |
you're welcome |
18:55 |
|
javabegina |
why are here not so many people? the real java channel is full but none is talking or people cant help :D |
18:56 |
|
aditsu |
probably not many people know about this channel |
18:56 |
|
javabegina |
i found it by the list since i was looking for an alternative channel |
18:57 |
|
aditsu |
btw there is another way to draw things in javafx, using the Canvas class |
18:57 |
|
aditsu |
that lets you draw into an actual image; the way you did it adds separate UI elements |
18:58 |
|
aditsu |
both have pros and cons |
18:58 |
|
javabegina |
i tried it with the canvas class but i had problems to put eventHandlers to the items |
18:58 |
|
aditsu |
oh yes, if you want it to be interactive, your way may be easier |
18:58 |
|
pdurbin |
We're here because we like aditsu. And Java. :) |
18:58 |
|
javabegina |
i wanted to put an eventHandler to the Ellipse before |
18:59 |
|
javabegina |
but i struggled getting it to work |
18:59 |
|
javabegina |
when i did put an event to the eclipse it simply...did nothing |
18:59 |
|
aditsu |
pdurbin: aww :) |
19:00 |
|
javabegina |
is it even possible to add an event to a drawn circle? |
19:00 |
|
aditsu |
javabegina: well, you can try it again, make sure to add the ellipse to your content |
19:00 |
|
javabegina |
i suppose on Canvas i dont use Ellipse ep = new Ellipse(); or? |
19:01 |
|
javabegina |
the ellipse is part of the graphic context its not an object how i could put it into the content? |
19:01 |
|
javabegina |
i m confused now :D |
19:02 |
|
javabegina |
which way is the best to draw |
19:02 |
|
javabegina |
since i want to make more interactive programs |
19:02 |
|
aditsu |
don't bother with Canvas then |
19:03 |
|
aditsu |
continue what you were doing |
19:03 |
|
javabegina |
i just want to learn it correctly thats why i m asking |
19:04 |
|
aditsu |
I don't have a lot of experience with this, but I think what you're doing is correct (without Canvas) |
19:04 |
|
javabegina |
ok |
19:04 |
|
javabegina |
in that case i m happy :-) |
19:05 |
|
javabegina |
btw the way i coded is that correct and clear or should i work with even more classes and use MVC patterns for it? |
19:08 |
|
aditsu |
don't really care about MVC; I think your code could be simplified, but it doesn't look too bad |
19:08 |
|
javabegina |
in which way simplified? got a hint? so that i can take a look |
19:09 |
|
javabegina |
i know i could probably make a DrawingHandler |
19:09 |
|
javabegina |
which draws the stuff |
19:10 |
|
javabegina |
and for the basic declarations of the diffrent Panes well.. i had no other solution to make it shorter |
19:11 |
|
javabegina |
btw. i just found a tutorial how i could realize my program with the canvas aswel |
19:11 |
|
javabegina |
its kinda...hm yes like drawing with photoshop or such program need layers and move those layers around. everything moveable to a diffrent layer |
19:13 |
|
aditsu |
well, for example, you could make a method to create a Path for a line (or even multiple lines), instead of duplicating the code for it |
19:15 |
|
javabegina |
ur right |
19:16 |
|
javabegina |
but the first one is a moveTo not a LineTo so the commands are only used 1 time |
19:17 |
|
aditsu |
you have basically the same code repeated 5 times: a MoveTo followed by a LineTo |
19:17 |
|
aditsu |
also I think your whole graph could be a single path with many LineTo's, instead of many single-line paths |
19:18 |
|
javabegina |
the paths are drawn based on a Generated Value Table |
19:18 |
|
aditsu |
that's irrelevant |
19:18 |
|
javabegina |
this one atm. is only plotting ax+b but i gonna put some more complex ones |
19:18 |
|
javabegina |
hm |
19:19 |
|
javabegina |
1 single Path based on the Value Table? |
19:19 |
|
javabegina |
hm how this could be dont |
19:20 |
|
javabegina |
done* |
19:22 |
|
aditsu |
basically, MoveTo with wh[0], then for(int i = 1; i < wh.length; i++) add LineTo with wh[i] |
19:24 |
|
javabegina |
you are talking about the plotGraph correct? |
19:24 |
|
aditsu |
yeah |
19:25 |
|
javabegina |
if i understand you correct it means i created a global Path Object and just add all Lines and moveTo to this Object and when its done i just simply attach it to my Pane? |
19:25 |
|
aditsu |
also, in the current version, you can change to i < wh.length - 1, then you don't need the try/catch |
19:26 |
|
aditsu |
yes, but it doesn't need to be global, it can be a local variable in plotGraph |
19:27 |
|
javabegina |
i didnt know i could do it that way |
19:27 |
|
javabegina |
will be the path then be smoother bezier like? |
19:27 |
|
javabegina |
for example for x^2 plots |
19:28 |
|
aditsu |
it should look the same as before |
19:28 |
|
aditsu |
if you want a bezier path, you need to program that |
19:28 |
|
javabegina |
sounds fun |
19:29 |
|
aditsu |
there's CubicCurve for example |
19:30 |
|
javabegina |
mhm |
19:31 |
|
javabegina |
still need the calculation for the control points |
19:31 |
|
aditsu |
or you can just use straight segments, but more of them and shorter |
19:31 |
|
javabegina |
that was actually my idea at the beginning |
19:31 |
|
javabegina |
but 100 segments is never enouh :D |
19:47 |
|
javabegina |
my plotting mehtod looks now like this: https://pastebin.com/7UQrrsjc |
19:59 |
|
aditsu |
that's.. not what I said :p |
20:02 |
|
javabegina |
thats how i interpreted it :D |
20:02 |
|
javabegina |
it had 1 Path object |
20:02 |
|
javabegina |
and puts all the values into it |
20:02 |
|
javabegina |
and at the end adds it |
20:02 |
|
aditsu |
well.. yes, but you only need the first MoveTo |
20:02 |
|
javabegina |
why? |
20:03 |
|
aditsu |
when you draw a line to a point, you don't need to move to the same point again, you already got there |
20:05 |
|
javabegina |
i though everytime you draw a new point you need to go to its location |
20:05 |
|
javabegina |
i gonna test this |
20:06 |
|
javabegina |
dang |
20:06 |
|
javabegina |
that works :-) |
20:07 |
|
javabegina |
so i only need to move 1 time to a position and from there it simply connects? |
20:07 |
|
javabegina |
no matter which formula a gonna use later on? |
20:08 |
|
javabegina |
i have my thoughs actually about 1/x hyperbel |
20:08 |
|
aditsu |
yeah, it's like drawing lines on paper |
20:09 |
|
javabegina |
https://pastebin.com/QdKWyYvW |
20:09 |
|
javabegina |
now its like u told me |
20:09 |
|
aditsu |
well, not exactly, but close |
20:10 |
|
javabegina |
what did i miss? |
20:10 |
|
aditsu |
you went from 0 to length-1 and used i+1, I said from 1 to length, using i |
20:11 |
|
aditsu |
it's the same thing in the end, but clearer |
20:12 |
|
javabegina |
oh ok yes true starting at 1 instead of 0 hm yes |
20:14 |
|
aditsu |
you can get rid of a lot of parentheses and the -1's |
20:18 |
|
javabegina |
https://pastebin.com/iR6ZDun2 |
20:19 |
|
aditsu |
you only changed one of the 3 things I mentioned first |
20:19 |
|
aditsu |
that's wrong |
20:19 |
|
javabegina |
lemme check |
20:20 |
|
javabegina |
i took the parentheses away, replaced the i+1 and did set the moveTo outside starting at index 0 |
20:21 |
|
aditsu |
oh, you replaced the i+1 in 1 or 2 places, but not in the LineTo |
20:22 |
|
aditsu |
and you're still going to length-1 |
20:23 |
|
aditsu |
then I said you can get rid of the -1's |
20:23 |
|
javabegina |
yep |
20:23 |
|
javabegina |
overseen that |
20:24 |
|
javabegina |
https://pastebin.com/XwiS6Vd3 |
20:24 |
|
javabegina |
iff |
20:24 |
|
javabegina |
dang :D |
20:25 |
|
javabegina |
how i coulnd even get an error at + -1 |
20:25 |
|
aditsu |
it's valid, but very clumsy |
20:25 |
|
javabegina |
prbably java took it as - |
20:25 |
|
aditsu |
-1 is a number |
20:26 |
|
javabegina |
ofc |
20:26 |
|
javabegina |
https://pastebin.com/7TNMNgE9 |
20:27 |
|
javabegina |
i actually didnt know that java validates + - 1 as -1 i mean 2 signs directly after eachother |
20:27 |
|
aditsu |
well.. ok, but you're making the tiniest steps of improvement.. what's the point in multiplying with 1? |
20:28 |
|
aditsu |
a + -1 * b -> what's wrong with a - b? |
20:28 |
|
javabegina |
well i had actually the problem that the Y axis was upside down |
20:29 |
|
javabegina |
so i multiplied by -1 to get it correct in the coordinate system |
20:29 |
|
aditsu |
you could have just replaced + with - |
20:31 |
|
javabegina |
thats actually right. |
20:32 |
|
javabegina |
https://pastebin.com/GATnhjAb |
20:32 |
|
javabegina |
now it should be fine |
20:33 |
|
javabegina |
at least i learn alot from this very happy about that |
20:34 |
|
javabegina |
practice makes perfect |
20:34 |
|
aditsu |
that looks better, can probably be simplified more |
20:35 |
|
javabegina |
i could put the coord into a Point structure aswel coordX and coordY |
20:39 |
|
javabegina |
looks actually extremly compact now |
20:39 |
|
aditsu |
still looks like a lot of duplication to me :) |
20:40 |
|
javabegina |
mhm |
20:40 |
|
javabegina |
the ellipses i suppose |
20:40 |
|
aditsu |
when you have duplicated code, it's easy to make mistakes, like not changing all of them when you want to make a change |
20:41 |
|
javabegina |
facts |
20:41 |
|
javabegina |
i know the Ellipse are duplications too |
20:41 |
|
aditsu |
I'm mainly talking about the "center + something * offset" calculations everywhere |
20:41 |
|
javabegina |
oh yes |
20:43 |
|
javabegina |
well no idea how i could make this simplier now except putting it into a variable before i calculate |
20:46 |
|
aditsu |
well, looking through the API, the best way might be to set translate and scale values on the path |
20:48 |
|
aditsu |
basically changing the whole coordinate system of the node |
20:48 |
|
javabegina |
mhm |
20:48 |
|
javabegina |
thats now new |
20:52 |
|
javabegina |
translate sounds nice |
20:53 |
|
javabegina |
could just simply define the center point at the beginning |
20:53 |
|
javabegina |
and then just move the offset |
20:54 |
|
aditsu |
set scale for your offset |
20:57 |
|
javabegina |
lets see if it works |
20:57 |
|
aditsu |
you may need to experiment a bit |
20:58 |
|
javabegina |
https://pastebin.com/LWXsy7ih |
20:58 |
|
javabegina |
lol |
20:58 |
|
javabegina |
https://gyazo.com/a976c96a8e772fc923daa11d904af713 |
20:58 |
|
javabegina |
thats a bit.... yes |
20:58 |
|
javabegina |
lol |
20:59 |
|
javabegina |
looks strange |
20:59 |
|
aditsu |
ok, I guess it also scaled the thickness |
21:00 |
|
javabegina |
:-) yes |
21:03 |
|
javabegina |
i actually cant find a solution how i can change the thickness |
21:05 |
|
aditsu |
you can set the stroke width to compensate.. or you can revert to modifying the points, but in a single place |
21:15 |
|
javabegina |
works good now |
21:15 |
|
javabegina |
i gonna refactor the other stuff aswell i m sure there is alot to change |
21:15 |
|
javabegina |
aswel |
21:15 |
|
javabegina |
many thanks for your help and your time |
21:22 |
|
aditsu |
alright :) |