-1

If I am taking a large amount of input from a user lets say the favorite colour of a student in a classroom of 30 students.

I want the teacher to input each favorite colour. I dont want to ask the teacher for each name of the student in showDialogBox then search a file to show that the student exists then ask to input the colour.

Is there a way of displaying a Box which looks something like this

 John-(blank space to enter txt eg.colour) James-(blank space to enter colour) 

Or something like that, or would there be a better more convienient way for the user to input the data.

Then what comes to mind is changing a colour for a student.

Any help in pointing in the right direction would be much appreciated.

0

2 Answers 2

2

I would use a JFrame/JPanel

Frame: http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html

Panel: http://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html

Sign up to request clarification or add additional context in comments.

Comments

2

Yes, there are many ways. Some of your many options are:

  • Create a custom JPanel based component that has a label to display the name and a text input box. Read the student names and dynamically add one of these components per student to your form.

  • Use a JTable that has a column for the name and an editable column for the color (see http://docs.oracle.com/javase/tutorial/uiswing/components/table.html for a tutorial on creating tables with editable input).

  • Iterate through student names and display a dialog box for each. Rather than having the teacher enter the names, display the names from the file and just have the teacher enter the color.

The first two options require you to build your own input window, which would likely be a JFrame based component. The last option lets you use JOptionPane without having to do any of your own interface coding.

You should try one of these ways, or maybe some other way that you think of, then if you are having a specific problem, come back here and ask.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.