使用JLabel绘制外观[null布局]Java Swing*错误

使用JLabel绘制外观[null布局]Java Swing*错误,java,swing,interface,helper,Java,Swing,Interface,Helper,我正在尝试用JLabels构建一个学生图 我的应用程序执行sql查询,并为每个月的条目数返回一个int值,如果没有找到任何条目,则返回0 //scale variable is an int //ene is a return value from another method that runs before //in case there are no students in january I dont have to graph anything //so this 'if' doe

我正在尝试用JLabels构建一个学生图

我的应用程序执行sql查询,并为每个月的条目数返回一个int值,如果没有找到任何条目,则返回0

//scale variable is an int

//ene is a return value from another method that runs before

//in case there are no students in january I dont have to graph anything
//so this 'if' doesnt run

Scale = 50;  

if (Ene != 0) { 

            System.out.println(Ene + " ene stdds");

// this prints out 11 ene stdds

            double EneBH = 449 * (Ene / Scale);
            int EneBHeight = (int) Math.round(EneBH);
            int EneBYLocal = 612 - EneBHeight;

            EneP.setBounds(76, EneBYLocal, 7, EneBHeight);
            EneP.setVisible(true);

        } else {

//if the last if didnt run I want to know if it hidd the label

            System.out.println("HIDDEN ENE");
            EneP.setVisible(false);
        }

*Ene p是第一个用于作图的jlabel,它看起来是基达灰色的,位于enero区

*EneP打印出11名学生,但从未显示,没有打印隐藏的ene,只是没有显示


*如果我解决或您解决,EneP将拥有与其他JLabel相同的代码,请

我已找到解决我自己问题的方法

解决方案很简单,结果表明,如果将Ene(保存为整数值的查询的返回变量)除以同样是整数的Scale变量,java将返回0

因此,我自己发现了这一点,在每行后面放置一个system.out.print(),并打印每个变量的值

我注意到11/50不应该返回0,所以我将scale变量改为double,仍然返回0;但我两个都改了,现在都正常了

Scale = 50;  

if (Ene != 0) { 

        System.out.println(Ene + " ene stdds");

// this prints out 11 ene stdds

        double EneBH = 449 * (Ene / Scale);
        int EneBHeight = (int) Math.round(EneBH);
        int EneBYLocal = 612 - EneBHeight;

        EneP.setBounds(76, EneBYLocal, 7, EneBHeight);
        EneP.setVisible(true);

    } else {

  //if the last if didnt run I want to know if it hidd the label

        System.out.println("HIDDEN ENE");
        EneP.setVisible(false);
    }

很抱歉,我在您的问题中看不到任何问题。若要更快获得更好的帮助,请发布或。(然后问一个问题。)