小编Nad*_*dim的帖子

用Java创建一个简单的计时器

我似乎无法弄清楚如何在java中创建一个简单的计时器.我需要做的只是显示时间,真的.所以只是一个开始的方法,它一直在计数,如0:00,0:01,0:02等.我已经看到了一些其他类似的论坛帖子,但所有的代码有点复杂的我的水平理解; 我是java的新手.但是,制作一个只执行这种基本功能的计时器并不难吗?如果有人可以帮助它将不胜感激:)

java timer

4
推荐指数
1
解决办法
4万
查看次数

程序似乎没有明显的原因循环

似乎我的输入框似乎出现了两次,即使它们也不应该出现.似乎无法弄清楚为什么.如果有人可以帮助,那会很棒:)

int x; //temperature input
int y; //temperature type
int z; //temperature convert
int c; //temperature celsius 
int f; //temperature fahrenheit 

public void init() 

{
    setSize(500, 500);
    Container c = getContentPane();
    c.setBackground(Color.BLUE);


}

public void paint (Graphics g)

{
    super.paint(g); 

    g.setFont(new Font("Veranda", Font.PLAIN, 20));
    g.setColor(Color.BLACK);

    String number = JOptionPane.showInputDialog("What temperature would you like to convert? (input # of degrees)");
    x = Integer.parseInt(number);   

    String number2 = JOptionPane.showInputDialog("What temperature type are you inputting? 1. Fahrenheit 2. Celsius");
    y = Integer.parseInt(number2);

    if (y==1) …
Run Code Online (Sandbox Code Playgroud)

java loops if-statement

2
推荐指数
1
解决办法
107
查看次数

如果声明不起作用,请跳过其他地方

我的"if"语句似乎不起作用,无论我输入什么似乎总是默认为我的"else"语句.例如,如果我输入整数"1"或"2",它们具有与它们相关联的"if"语句,则它仍然默认为"else".任何帮助,将不胜感激 :)

String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1.  Custom   2. Infinite"); //test choice
n = Integer.parseInt(number);
while (n < 0 || n > 2) {
    if (n == 1) {


        String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
        integer = Integer.parseInt(number2);
        while (integer < 0) {
            while (x < integer) {
                g.drawString("hi", 200, y);

                x += 1;
                y = y + 40; //test
            }//end while
        }
    }//end if 
    else …
Run Code Online (Sandbox Code Playgroud)

java if-statement

-1
推荐指数
1
解决办法
923
查看次数

标签 统计

java ×3

if-statement ×2

loops ×1

timer ×1