Custom Multiple Choice Menu

Hey all,

I am attempting to create a custom sort of multiple choice menu, and was directed to this forum from a friendly member of codingforums.com. Here's the rundown:

I'm working on a project that requires me to implement a sort of sequential multiple choice question system that uses very little space, and is very smooth, so when a user understands the input (hit a,b,c,d,...) they can rapidly answer a sequence of questions. Anyway, I've got a mockup of what I'm looking to do, but still have trouble figuring out how best to go about this in Swing.

Any insight or suggestion would be a big help, I'm coming back to Swing after a bit of a hiatus and right now I'm just sort of API-crawling to figure this out.

Here's the functionality mock-up, basically this will go inside of a JPanel, where what's actually important is just the orange stuff. (Ideally this is scalable from 1-4 windows or so, but if I can figure out how to do at least 2 the rest I think will be mostly math.)

http://www.davehora.com/learnlab/panel_mockup.gif

And my own thoughts: Perhaps I can achieve this either using no layout manager for absolute positioning based on the size of the area and the number of choices, or create a layout manager that uses JLabels and does the positioning for me when given x number of multiple choice questions.

[1373 byte] By [Skizzlera] at [2007-10-2 16:29:41]
# 1
Anyone, a thought on this, please? :o
Skizzlera at 2007-7-13 17:31:38 > top of Java-index,Desktop,Core GUI APIs...
# 2

this might be one way?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Testing extends JFrame

{

CardLayout cl = new CardLayout();

JPanel panel = new JPanel(cl);

JLabel label = new JLabel(" ");

public Testing()

{

setLocation(200,100);

setSize(400,300);

setDefaultCloseOperation(EXIT_ON_CLOSE);

panel.add("0",new QuestionPanel(new String[]{"Add 3 ","Subtract 3 ","Multiply 3 ","Divide 3 "},0));

panel.add("1",new QuestionPanel(new String[]{"by ","from ","to ","with "},1));

panel.add("2",new QuestionPanel(new String[]{"right side","left side","both sides"},2));

getContentPane().add(label,BorderLayout.NORTH);

getContentPane().add(panel,BorderLayout.CENTER);

pack();

}

class QuestionPanel extends JPanel

{

public QuestionPanel(String[] questions, final int questionNumber)

{

setLayout(new GridLayout(0,1));

ButtonGroup group = new ButtonGroup();

for(int x = 0; x < questions.length; x++)

{

final JRadioButton rb = new JRadioButton(questions[x]);

group.add(rb);

add(rb);

rb.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

label.setText(label.getText()+rb.getText());

if(questionNumber < 2) cl.next(panel);}});

}

}

}

public static void main(String[] args){new Testing().setVisible(true);}

}

Michael_Dunna at 2007-7-13 17:31:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
Wow, yeah, that might actually be better than what I was going for. It saves space even better, and it looks like based on the length of the overall string I can ramp up the number of sequential multiple choices.
Skizzlera at 2007-7-13 17:31:38 > top of Java-index,Desktop,Core GUI APIs...