允许在调用方法和JOptionPane之后代码继续执行所需的计时器或其他想法 [英] Timer or other idea required to allow code to continue execution after calling method and JOptionPane

查看:93
本文介绍了允许在调用方法和JOptionPane之后代码继续执行所需的计时器或其他想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调用此方法后,我需要一种允许程序继续运行代码的方法.

当前,它等待半小时,获取信息,将其存储到对象WeatherCard中,然后显示并重复.但是它挂在JOptionPane上.我需要一种方法来使程序保持在JOptionPane下方,或者在大约10秒后关闭窗格.我不确定当前如何在我的代码中使用

I need a way to allow my program to keep running code after this method is called.

Currently, it waits for half an hour, gets the info, stores it to the object WeatherCard, and displays it, and repeats. But it hangs on the JOptionPane. I need a way to make it so that the program either keeps going underneath the JOptionPane or to close the pane after about 10 seconds. I am not sure how to work either into my code, currently

public void printWeatherCard(WeatherCard w, JFrame controlFrame) throws MalformedURLException, IOException{
    /* Displays a dialog box containing the temperature and location */
    BufferedImage img = ImageIO.read(new URL(w.imgSrc));
    ImageIcon icon = new ImageIcon(img);

    JOptionPane.showMessageDialog(controlFrame, "It is currently " + w.currentTemp + " \u00B0 F in " + w.location.city + ", " + w.location.state + ".\nCurrent humidity: " + w.currentHumidity + 
            "%.\nChance of precipitation: " + w.chancePrecip + "%.", "Weather Update: " + w.location.zipCode, JOptionPane.INFORMATION_MESSAGE, icon);
}

推荐答案

但是它挂在JOptionPane上.我需要一种方法来做到这一点 程序要么继续在JOptionPane下运行,要么关闭 大约10秒钟后显示窗格.我也不知道该如何工作 代码,当前

But it hangs on the JOptionPane. I need a way to make it so that the program either keeps going underneath the JOptionPane or to close the pane after about 10 seconds. I am not sure how to work either into my code, currently

有两种方法

  • (更好,更轻松)创建JDialog(JFrame parent, boolean true),默认关闭操作HIDE_ON_CLOSE,只有一个JDialog作为local variabl e,由setVisible(false/true)

  • (better easier, comfortable) create JDialog(JFrame parent, boolean true), with default close operation HIDE_ON_CLOSE, only one JDialog as local variable, reuse this Object by setVisible(false/true)

在所有JOptionPanes的数组内部循环(全部存在,直到当前的JVM存活为止),由@kleopatra

这篇关于允许在调用方法和JOptionPane之后代码继续执行所需的计时器或其他想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆