Accname
2D-Graphics enthusiast
- Reaction score
- 1,462
Hi guys.
Hopefully an easy question.
I am working with java here, using lwjgl to make an openGL window.
In the case of any kind of error (exception being thrown or illegal input or anything) i want to open a popup window displaying an error message.
I think this will be easier and more consumer friendly then having the game just crash to the desktop and making a cryptic error log. (i make the error log anyways)
So for the popup i dont want to use openGL as well, wanna make it a little bit easier on me and just use a jframe.
I made the following sub class of jframe:
And this is all nice and dandy.
But i want my main application to be halted until the popup has been closed.
At first i tried it with the following code:
But that doesnt work. I think this is because of the caching, if i add any random System.out.print message within the while-loop body it works.
So i tried:
And this kinda works. But i dont like this solution, its quick and dirty.
So, is there any easy way i could have my main thread blocked until the jframe has been disposed?
Thanks in advance.
Hopefully an easy question.
I am working with java here, using lwjgl to make an openGL window.
In the case of any kind of error (exception being thrown or illegal input or anything) i want to open a popup window displaying an error message.
I think this will be easier and more consumer friendly then having the game just crash to the desktop and making a cryptic error log. (i make the error log anyways)
So for the popup i dont want to use openGL as well, wanna make it a little bit easier on me and just use a jframe.
I made the following sub class of jframe:
Code:
private static class Error_Popup extends JFrame {
private static final long serialVersionUID = 4013003667450751116L;
private JPanel contentPane;
public Error_Popup(String title, String message, int x, int y) {
setType(Type.POPUP);
setTitle(title);
setAlwaysOnTop(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setMinimumSize(new Dimension(512, 256));
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setText(message);
contentPane.add(textArea, BorderLayout.CENTER);
JButton button = new JButton("Close this");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
contentPane.add(button, BorderLayout.SOUTH);
pack();
setSize(getWidth(), getHeight() + textArea.getPreferredSize().height);
setLocation(x - getWidth() / 2, y - getHeight() / 2);
setVisible(true);
}
}
But i want my main application to be halted until the popup has been closed.
At first i tried it with the following code:
Code:
Error_Popup win = new Error_Popup(title, message, x, y);
while(win.isShowing()){}
So i tried:
Code:
Error_Popup win = new Error_Popup(title, message, x, y);
while(win.isShowing()){
win.requestFocus();
}
So, is there any easy way i could have my main thread blocked until the jframe has been disposed?
Thanks in advance.