APe*_*son 0 java loops while-loop
我有以下代码,一切似乎工作除了while循环,这里是代码:
JLabel img = new JLabel(loadingScreens.getImageIcon(0));
loadingFrame.setUndecorated(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
int wid = (int) width;
int hgt = (int) height;
wid = wid/2;
hgt = hgt/2;
wid -=350;
hgt -=350;
loadingFrame.setLocation(wid, hgt);
loadingFrame.setSize(700, 700);
loadingFrame.setBackground(new Color(0,0,0,0));
loadingFrame.add(img);
loadingFrame.setIconImage(loadingScreens.getImage(0));
loadingFrame.setVisible(true);
System.out.println("Done 1");
try{
Thread.sleep(500);
System.out.println("Done 2");
}catch(Exception e){
System.out.println("exception caught");
}
Integer lo = 0;
System.out.println("Done 3");
while(lo.equals(256)){
System.out.println("Started 4");
loadingFrame.setBackground(new Color(lo, lo, lo, lo));
loadingFrame.repaint();
try{
Thread.sleep(10);
}catch(Exception e2){
}
lo++;
}
Run Code Online (Sandbox Code Playgroud)
loadingFrame 是一个基本的JFrame.
任何帮助都很有用
while循环在指定条件时循环true.您已初始化lo为0,不等于256,因此永远不会输入循环体.
因为你lo在循环中递增,也许你的意思相反:
while(!lo.equals(256)){
Run Code Online (Sandbox Code Playgroud)
!Java中的运算符否定了布尔条件,因此它显示为:"while lo 不等于256".