Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Swing JFrame - Should I be using threads or JDialogBox (or both!)?

804170Nov 2 2010 — edited Nov 3 2010
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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
This post has been answered by camickr on Nov 2 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 1 2010
Added on Nov 2 2010
10 comments
127 views