hi hello! im planning to do a payroll system for our defense project,im a beginner and i want our program to be more complicated in a way that we can still be able to explain it. I want our program to be able to have multiple input boxes, because the only thing that i know is to create a single JOptionPane.showMessageDialog.

IN one box, i wan it to have a lot of input boxes..
thank you :)

Recommended Answers

All 9 Replies

JFrame has nothing to do with JOptionPane. a JFrame can be used to create your own user screens, so yes, also a 'dialogbox' with as many input fields you need, in the layout you want it to be shown in.

This would be a good place to start learning how to create such screens.

indeed if you are trying to get multiple inputs at once from a user, the JOptionPane can't help you.

you will want to create a class and extend JFrame from it, then Initialize your components and set your layout. You will be using many components to build your form, more than likely you will need many JLabel , JTextField , possibly some JPasswordField and at least one or more JButton , you will also need to add ActionListenners to those JButtons.

For an easy layout to work with for starters, i would suggest using the GridLayout, it will split the screen in a Grid of the size you specify and add the components you give it from left to right and top to bottom.

this.setLayout(new GridLayout(4,2)); //will create grid that is 2 cells wide and 4 cells high

Now, im looking foward to see your first attempts at this gui building, but there is one more thing i would like you to take into consideration while building this; programing standards dictate that a child should not call methods from its parent.

This means that lets say your main program creates and initialize a object of your JFrame extension class, when you click that "save" button or whatever, the form cannot call methods from your main program. It is possible to do it, but semanticaly , it is wrong.

To anyone else reading this , please correct me if that last part is wrong, but im pretty sure i remember something like that! :D

it's possible, but it restricts the kind of parent objects that can use the child, and that way, it limits the re-usability.
doesn't mean that two JFrames shouldn't be able to communicate with one another. just thinking of inner classes, for instance.

im actually not sure what the best way to respect that standard is, what i did in school last time i had to do soemthing like this was create and initialize the JButton in the main program and pass it as an argument to the form's constructor, the form still placed the button in its layout, but this way i could implement the actionlistenner in the main program's code :D

its a strange workarround but i did not want to have a method, lets say "setLoggedInUser(String user)" in the main program that would be called by a child form that i created. and java doesn't have anything like "ref" arguments so.

come to think of it, i guess one possibility would be to extend JOptionPane and add some showMultipleInputDialog(...) method.

use a JTextField...if your input is of multiple lines use a Textarea

use a JTextField...if your input is of multiple lines use a Textarea

she was talking about multiple input fields, not multiple lines.
btw, a String in a JTextField is not necessarily limited to about 50 chars, the only real difference would be in the formatting.

she was talking about multiple input fields, not multiple lines.
btw, a String in a JTextField is not necessarily limited to about 50 chars, the only real difference would be in the formatting.

multiple input fields???
TextPane

multiple input fields???
TextPane

thanks guys, i am trying to start working on it...thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.