#/help

85 messages · Page 1 of 1 (latest)

muted birch
#

I have a Vbox object, and I want to insert inside 4 "radio buttons" and beside each one of them a "TextField".
It suppose to look like the first picture:

The thing is, I want to do this with code and not through SceneBuilder.
I'm just struggling with how to insert objects inside Vbox..
I've created 4 TextField in size of(Vbox.Wideth - 50, Vbox.Height) ) (I'll leave 50 of width for the radio button)
But I don't know how to insert the textField inside the Vbox

Need help, thank you!

tall basinBOT
#

This post has been reserved for your question.

Hey @muted birch! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

muted birch
#

This is my original sceneBuild build:
in the middle it's the Vbox named "vboxForAnswers"

tough plaza
#

inside the vbox u put HBoxes, inside the hbox u put the button and the textfield

u can write a method that has a string as a parameter (to fill the textfield with)
and returns the hbox

what way ur code is simple

  vBox.add(labelledRadioButton("Something something"));
  vBox.add(labelledRadioButton("Something else"));
#

but ur missing a problem ...... by doing this the radio button and the textfield are not linked logically or programatically so if u need to see the text, or hilight the line ur bust

its better to use a listView if u need more functionality than just to know if which radio button was selected

#

iirc there is an element called a Label, so that u dont have to go through the hassle of .isModifyable(false) and all the other jaz to just it from user input into program output

muted birch
#

I can make a functionality between the radio and the text by saving the index of the radio button and then look what the text is inside this index right?

And then i'll try to match it with the question, if it's the same text then it's the correct answer

muted birch
tough plaza
#

As for the sizing
Vbox and HBox are dynamically sized components
They take their size from calculating the size of the inner members
And unless u specify the sizing preferences of the inner members to minimum some of them try to fill the available space

If u want rigid size control u should be using a gridlayout for example

#

HBox and Vbox are designed to automatically grow based on contents

U can't then go and complain that they r doing exactly what they r supposed to

tough plaza
muted birch
#

i mean, setOnAction so I can press on it

tough plaza
#

why do u need an event handler on the label?
the radio button is the dymanic component is it not?

muted birch
#

I gave up on the radio button

#

I'll do only label which you press and get it's text

tough plaza
#

what event do u expect the user to perform with the label?

#

ah, so ur using a listview?

#

i'm pretty sure every listview example shows how to pull the index selected out of a listview

muted birch
#

I didn't use listview since I don't know it
I'm on youtube now to learn about it

I was thinking only about putting 4 labels and then when you press on a label it will compare with the right answer.
But I'll just move to listview

tough plaza
#

so if u didnt use a list view, and didnt use radio buttons, what did u use to give the user something to interact with?

#

do u want to do this properly?

#

@muted birch

muted birch
#

I don't know anymore how to do this with radio-buttons, I'm totally stuck with it
I'll learn about listview, hopefully I'll manage to do this

#

The aim is to do this properly, but I also have a dead-line with the university, i have to find a solution

tough plaza
#

i'm not even talking about that atm
i'm talking about the fact that ur question/quiz stuff is mixed up and confused inside ur javafx display stuff

#

i'm talking about methods with side effects

#

methods doing multiple things, all of which are bad code

muted birch
#

Do you mean methods which do different operations on the same time?

tough plaza
#

yes, single responsibility principle, u can look it up

muted birch
#

Okie my bad sorry

tough plaza
#

why ur bad, have u been tought before not to do many things in one method?

muted birch
#

yeah, to be honest I'm trying to break everything to many different methods with unique roles.
What I sent you is the initialize method where I mixed things up just to make sure it works.

But I've failed it

#

Something like this

#

One method was for initializing the question on the top of the window
Other method for the answers
And other for the poping message when the game is over

#

Is it bad?

#

But my initialize method is totally messed up right now since i'm lost 🫠
But i'm totally open for criticizing since I know I'm not good at this

tough plaza
#

ok, so start a new project
dont delete the old one so that u have something to refer to but dont try to fix the code in the existing project, u already said ur hopelessly lost

#

in the new project forget about javaFX, ur quiz ins not supposed to run because of the UI, its not supposed to care about the UI at all

muted birch
#

Done, opened a new one
And agree!

tough plaza
#

so first make a class called Question give it the question and the answers, give it which answer is correct, give it an isCorrect method

#

and then TEST the class

#

have u learn junit?

muted birch
#

and ofc generics and few other stuff

#

It's called "Java advanced"

tough plaza
#

ok, so u know how to test with the main method??

muted birch
#

Yes ofc

tough plaza
#

(honestly TDD should be one the first 3 things u get taught >.<)

#

then make a Quiz class, give it a way to load questions, give it a getRandomQuestion() method
is the quiz limitted by number of questions? is it supposed to keep track of correct answer, whatever is required for the quiz to be correct, add it in the quiz class
and add it with differant methods for each thing

#

then test the quiz

#

and only AFTER u have all of that running do u make the QuizView class where u put the javaFX

#

and u already know how to pre-initialise a controller, so u can make the QuizViewController constructor take a Quiz instance and link the quiz to the javaFX that way

#

and it wont be mixed up inside the javaFX!!

muted birch
#

It's not limited, I can put as many questions as I want

muted birch
tall basinBOT
# muted birch Ok i'll follow Thank you very much ❤️

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

muted birch
#

"is it supposed to keep track of correct answer"
Is it a question or statement?

#

Aaa got it now
Ok
Will do it

#

(1) Make a class called Question give it the question and the answers, give it which answer is correct, give it an isCorrect method
and then TEST the class

(2)then make a Quiz class, give it a way to load questions, give it a getRandomQuestion() method.
(3)keep track of correct answer or whatever is required for the quiz to be correct, add it in the quiz class
and add it with different methods for each thing
then test the quiz.
(4)only AFTER u have all of that running do u make the QuizView class where u put the javaFX
and u already know how to pre-initialise a controller, so u can make the QuizViewController constructor take a Quiz instance and link the quiz to the javaFX that way
and it wont be mixed up inside the javaFX!!

Organized it so it will be next to my eyes

muted birch
#

@tough plaza
Something like this?

Database class contains the bank of words
Question class get an index and produces an object which absorbs question, right answer, 3 wrong answers from the bank (Database).

"getAnswers()" method needs to be fixed, but it shows you the question and the 4 answers and returns the Strings which includes them

And of course main method

#

I've renamed getAnswers() to getForm()
It makes more sense

tough plaza
#

If u have a database then u need to do the same as with javafx

The database class is supposed to be about the database

Not about questions or quizes

tough plaza
#

@muted birch have u learned about interfaces? what about prepared statements?

#

dont use _ at the start of a variable name like _correctAnwer
that is not a java naming standard

#
class Question extends Database

congratulations, its now impossible to have a question without having a database
....tightly couple cade ..... bad code

what happens if somebody want to load questions from a text file?

tough plaza
#

...
ur getAnswers has the same problems as ur original code

i am assuming u have used a List?? imagine if u called .get(3) on a list and instead of getting the element it prints the element, or makes a popup on the screen with the element

ur mixing up the display of the data with the data itself

muted birch
muted birch
muted birch
tall basinBOT
tough plaza
#

U don't touch a database with strings, it allows sql injection
U use Prepared statements for it
I suggest u look that up if ur playing with a database

muted birch
tough plaza
#

Any jdbc tutorial should teach prepared statements 😦

muted birch
#

@tough plaza
They said in the assignment that the array of questions we can initialize in the code.
I think that's the only way for me since I've never touched SQL

#

and it seems like prepared statement are based on basic understanding of SQL

tough plaza
#

if u have never touched sql why r u suddenlt trying to use a datbase?

muted birch
#

Because I need to check if my code works
I've created the database
I forgot to show you

#

Database I meant like a class with Questions, answers and wrong answers so I can test my code

tall basinBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.