Hello,
I'm creating a game in which multiple pieces can be on a square, and when that square is clicked, I want a window to pop up and allow the user to select from a list of the pieces.
The list of pieces selected would be returned to the main program when the window is closed. While the window is open, I would like to suspend the execution of the program.
So, this code basically illustrates the basics of my dilemna.
public class JBegin {
public static void main(String[] args){
customFrame newFrame= new customFrame(0);
}
}
(code}
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class customFrame extends JFrame implements MouseListener{
int x=0, y=2,z;
public customFrame(int layer){
z=layer+1;
addMouseListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setSize(new Dimension(1000, 1000));
}
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
customFrame subset = new customFrame(z);
//freeze previous window
//wait for customFrame to close
//get values from subset.
x=y*2+z;
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
In the customFrame class, after the mouse button has been clicked, I want the code to wait for the new customFrame window to be closed before evaluating the equation.
I've done some reading, and I've heard that JDialog will accomplish most things a JFrame will (Though I haven't been able to find any tutorials on how to paint in JDialog). I also may be hesitant because I have some classes which are configured wonderfully for a JFrame.
In any case, would threads or a JDialog box be a more appropriate way to solve this problem? And if it is the JDialog option, do you know of a good JDialog painting tutorial (as, obviously, I've been having trouble finding one)?
Thanks for all your time and advice