Need some logic help - someone with a fresh brain!

Ok i have a problem where i need to get an x/y coordinate from the user...

it is used when the user pastes an image into my program (they choose the point where they want the image to start from).

when the user presses ctrl v this method is called:

publicstatic Point getCords()

{

String title ="Set Co-ordinates of pasted image";

final JInternalFrame frame =new JInternalFrame(title, false, true, false,true);

JPanel container =new JPanel();

container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));

//create Jpanels which will contain components

JPanel panel =new JPanel();

panel.setLayout(new BorderLayout());

JPanel panel2 =new JPanel();

panel2.setLayout(new BorderLayout());

//create labels

JLabel width =new JLabel("X - Coordinate: ");

JLabel height =new JLabel ("Y - Coordinate: ");

//create text fields

final JTextField enterX =new JTextField(10);

final JTextField enterY =new JTextField(10);

enterX.setBorder(new LineBorder(Color.black, 1,true));

enterY.setBorder(new LineBorder(Color.black, 1,true));

//position components in jpanels

panel.add(width, BorderLayout.WEST);

panel.add(enterX, BorderLayout.EAST);

panel2.add(height, BorderLayout.WEST);

panel2.add(enterY, BorderLayout.EAST);

//create button to add

JButton okButton =new JButton("Ok");

okButton.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e)

{

int x, y;

try

{

x = Integer.parseInt(enterX.getText());

y = Integer.parseInt(enterY.getText());

}

catch(Exception egger)

{

JOptionPane.showMessageDialog(null,"Coordinates must be integers");

return;

}

setP(x, y);

}

});

container.add(panel);

container.add(panel2);

frame.getContentPane().add(container);

frame.setVisible(true);

frame.setSize(100, 100);

desktop.add(frame, JDesktopPane.POPUP_LAYER);

return p;

}

most of that is GUI, just setting up a JInternalFrame which displays two labels, two textFields and an ok button. when the user clicks the ok button, a point is made from the two coordinates entered.

at the moment though the point ("p") is being returned straight away without it letting me fill in the form, i know why but i dont know how i can get it to wait for me to fill in the form first.

please help me, thanks

[4111 byte] By [boblettoj99a] at [2007-11-27 5:08:59]
# 1
anyone?my brain is fried :(
boblettoj99a at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Are you trying to make a JInternalFrame act like a modal dialog?If so, I'd give up and just code a JDialog to do it.
Hippolytea at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 3
really? is there no way to do it then?ok thanks for the pointer :)
boblettoj99a at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 4
> really? is there no way to do it then?I'm not sure. You could post this in the Swing Forum, so that the experts could see it.
Hippolytea at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 5
is there some kind of JDialog already premade like JOptionPane except with 2 textFields?i dont really understand how to construct them at all
boblettoj99a at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 6

> is there some kind of JDialog already premade like

> JOptionPane except with 2 textFields?

>

> i dont really understand how to construct them at all

I was working on trying to make one of those last night, I'll post what I got if I remember when I get home.

hunter9000a at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...
# 7

Here's what I came up with. If anyone has a simpler way to do this, I'd love to see it :). You can only click the buttons, there aren't any key listeners on them. Hope it helps.

JTextField jTextFieldAddr = new JTextField(10);

JTextField jTextFieldPort = new JTextField(10);

Object ret = JOptionPane.showOptionDialog(this,

new Object[] {"Address", jTextFieldAddr, "Port", jTextFieldPort},

"title",

JOptionPane.OK_CANCEL_OPTION,

JOptionPane.PLAIN_MESSAGE,

null,

new Object[] {"OK", "Cancel"},

"option1");

if (ret.equals(Integer.valueOf(JOptionPane.OK_OPTION))) {

System.out.println("ret is ok");

String addr = jTextFieldAddr.getText();

String port = jTextFieldPort.getText();

}

else if (ret.equals(Integer.valueOf(JOptionPane.NO_OPTION))) {

System.out.println("ret is cancel");

}

hunter9000a at 2007-7-12 10:28:33 > top of Java-index,Java Essentials,Java Programming...