ActionListener in JDialog created by JOptionPane
I have a problem I absolutely cannot get around. I've been toying with this code all day and nedd some help badly. The code is posted below. Let me give you some background. I have an application that uses "popups" to ask the user a series of questions. I have two bg images I want to display for the background,
as well as a custom button (that's no sweat). I originally wrote a class extending JDialog to show the popups. But JDialog does not "block" and wait for user input. I started toying around with JOptionPane. I have created a JDialog from JOptionPane.createDialog(parent, title). All the components display correctly and
the dialog blocks, BUT the actionListener I added to my button does not go into action. Am I barking up the wrong tree, or is there a way to get a JDialog to block
the running thread?
class myDialog{
JDialog main;
JTextField inputfield;
public myDialog(JFrame parent, String display){
main = this.createDialog(parent,"hello");
Dimension screenSize =new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
main.setBounds(screenSize.width/2 - 195,
screenSize.height/2 - 50,395,110);
JLabel textInsert =new JLabel(display);
textInsert.setFont(new Font("Serif", Font.BOLD|Font.ITALIC, 14));
textInsert.setForeground(Color.gray);
JButton next =new JButton(new ImageIcon("images/gui/next.png"));
inputfield =new JTextField(20);
Container c = main.getContentPane();
c.setLayout(new BorderLayout());
c.removeAll();// call this to remove the components added by JOptionPane.
BackgroundComponent panel =new BackgroundComponent(new ImageIcon("images/gui/upperdialog.png").getImage());
BackgroundComponent panel2 =new BackgroundComponent(new ImageIcon("images/gui/lowerdialog.png").getImage());
panel.add(new JLabel(new ImageIcon("images/gui/spacer.png")));
panel.add(textInsert);
panel2.add(inputfield);
panel2.add(next);
c.add(panel, BorderLayout.NORTH);
c.add(panel2, BorderLayout.CENTER);
main.setResizable(true);
main.setVisible(true);
next.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
main.setVisible(false);
}
});///////////////////////////////////////
}
}
Thanx in advance -- CSB

