小编Pra*_*hra的帖子

关于整数比较的澄清?

class Demo{
public static void main(String[] args) {  
     Integer i = Integer.valueOf(127);  
     Integer j = Integer.valueOf(127);        

     System.out.println(i==j);  

     Integer k = Integer.valueOf(128);  
     Integer l = Integer.valueOf(128);        

     System.out.println(k==l);  
  }  
}
Run Code Online (Sandbox Code Playgroud)

第一个print语句打印为true,而第二个打印语句打印为false.为什么?请详细解释.

java autoboxing integer value-of

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

Java GUI编程

代码给出了nullpointer异常的错误..... wat做什么?

import java.awt.event.*;
import javax.swing.*;

public class Gui implements ActionListener{
JButton button;

public Gui(){
    JFrame frame=new JFrame();
    JButton button =new JButton("click me!");
    button.addActionListener(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(button);
    frame.setSize(270,300);
    frame.setVisible(true);
}
public static void main(String[] args){
    new Gui();
}

public void actionPerformed(ActionEvent e){
    button.setText("I've been clicked");
}

}
Run Code Online (Sandbox Code Playgroud)

java swing scope nullpointerexception

-5
推荐指数
2
解决办法
159
查看次数