How do I create a simple cancel button using a while loop in Java?
4 replies, posted
Thread title, just a simple question
[code]
while(true)
{
JButton button = new JButton("Cancel");
break;
}
[/code]
appears to fit the bill
Or for the one-liner fans out there:
[code]while ((JButton button = new JButton("Cancel")) == null);[/code]
[code]
while(true){
//Do your crap
//Pseudocode:
if(button.Pressed){
break;
}
}
[/code]
I don't know Java button shit so I don't know how correct that is.
If you want to handle the events form a button you need to use an ActionListener.
[code]
JButton b = new JButton("Cancel");
b.addActionListener( new ActionListener(){
void actionPerformed(ActionEvent e){
yourJFrame.dispose();
}
});
yourJFrame.add(b);
[/code]
Sorry, you need to Log In to post a reply to this thread.