【问题标题】:How to display a pop up with the contents of a如何显示包含内容的弹出窗口
【发布时间】:2017-02-24 03:10:47
【问题描述】:

我正在尝试制作一个以秒为单位的程序,然后在午夜后弹出时间。为此,我编写了以下代码,尽管我无法让它打印回时间。我可以让它显示在控制台中,但我宁愿它弹出。谁能指出我正确的方向?谢谢

import javax.swing.JOptionPane;

公开课练习4 {

private static final int MinsInHour = 60;
private static final int SecsInMinute = 60;

public static void main(String[] args) {

    String inputseconds = JOptionPane.showInputDialog("How many seconds? <> ");
    int seconds = Integer.parseInt(inputseconds);

}

private static String timeConversion(int seconds) {

    final int MinsInHour = 60;
    final int SecsInMinute = 60;

        int minutes = seconds / SecsInMinute;
        seconds -= minutes * SecsInMinute;

        int hours = minutes / MinsInHour;
        minutes -= hours * MinsInHour;

    return hours + " hours " + minutes + " minutes " + seconds + " seconds";
    JOptionPane.showMessageDialog(hours + " hours " + minutes + " minutes " + seconds + " seconds");
}

}

【问题讨论】:

    标签: java time printing calculator clock


    【解决方案1】:

    return 之后不能有其他命令。我已经为你颠倒了最​​后两行。

    private static String timeConversion(int seconds) {
    
        final int MinsInHour = 60;
        final int SecsInMinute = 60;
    
            int minutes = seconds / SecsInMinute;
            seconds -= minutes * SecsInMinute;
    
            int hours = minutes / MinsInHour;
            minutes -= hours * MinsInHour;
    
        JOptionPane.showMessageDialog(hours + " hours " + minutes + " minutes " + seconds + " seconds");
        return hours + " hours " + minutes + " minutes " + seconds + " seconds";
    }
    

    【讨论】:

    • Exercise4.java:26: 错误:没有找到适合 showMessageDialog(String) 的方法 JOptionPane.showMessageDialog(hours + " hours " + minutes + " minutes " + seconds + " seconds");我把这个拿回来了,有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 2022-07-31
    • 2012-10-28
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多