我有一个处理某些文件的程序。有时,我需要在处理过程中停止它,但是我很难完成它。我已经看到了几种可能性,但我不确定应该追求什么。它是多线程的,就像在游戏中一样吗?我找到了一些有关取消的信息,但它似乎只适用于输入数据时?我在下面包含了我的gui的代码,因为我可能只是做错了什么?
要明确,目标是无论处理的位置如何都要停止程序......
private JRadioButton blockButton, unblockButton;
private JButton btnCancel;
private ButtonGroup group;
private JLabel text;
private JButton enter;
public Gui(){
super("Download CORS files");
setLayout(null);
text = new JLabel("Would you like to download data in a block of days or intermittently over time?");
add(text);
blockButton = new JRadioButton("Block of Days", true);
unblockButton = new JRadioButton("Intermittent Days", false);
btnCancel = new JButton("Cancel run");
add(blockButton);
add(unblockButton);
add(btnCancel);
group = new ButtonGroup();
group.add(blockButton);
group.add(unblockButton);
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = this.getSize().width;
int h = this.getSize().height;
int x = ((dim.width-w)/2)-200;
int y = ((dim.height-h)/2)-200;
// Move the window
this.setLocation(x, y);
enter = new JButton("Enter");
enter.addActionListener(this);
add(enter);
text.setBounds(5,5,700,25);
blockButton.setBounds(5, 25, 300, 25);
unblockButton.setBounds(5,50, 300, 25);
enter.setBounds(75,100,100,20);
btnCancel.setBounds(300,100,100,20);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}});
答案 0 :(得分:0)
根据情况停止处理的两种方法