小编Jav*_*ewb的帖子

For和While Loop

我有一个同时运行的程序,我有这个问题,我想停止线程,但一旦我点击输入,for循环/ while循环不会被取消

如果我将for循环从循环中取出while,程序实际上会响应输入并关闭.

class MyNumber extends Thread {

    private volatile boolean processing = true;

    public void run() {
        while (processing) {
            // Once I take this for loop out(put // beside it like right now), the enter key to stop the program then does work.
            //for(int i = 1; i<27; i++){
             System.out.println("Letter " + "i");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // }
        }
    }

    public void permSleep() {
        processing = false; …
Run Code Online (Sandbox Code Playgroud)

java multithreading loops

5
推荐指数
1
解决办法
152
查看次数

setLocation of Label

我让所有标签都正常工作,但userLabel [3]无法正确定位无论我做什么,标签"颜色:"始终显示在x坐标为0且y坐标为0的框架上在框架的一半.

    JLabel[] userLabel = new JLabel[4];
    for(int p = 0; p < userLabel.length; p++){
        userLabel[p] = new JLabel();
        userLabel[p].setSize(100,50);
        frameSetUp.add(userLabel[p]);
    }
    userLabel[0].setText("Width of Frame:");
    userLabel[1].setText("Height of Frame:");
    userLabel[2].setText("# OF Balls:");
    userLabel[3].setText("Color:");

    userLabel[0].setLocation(10,35);
    userLabel[1].setLocation(10,85);
    userLabel[2].setLocation(10,135);
    userLabel[3].setLocation(0,0); //no matter what coordinates I change this too, it wont reposition
Run Code Online (Sandbox Code Playgroud)

图片:[IMG] http://i41.tinypic.com/23jfo9l.png [/ IMG] http://i41.tinypic.com/23jfo9l.png

java swing jlabel null-layout-manager

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