java的if语句进不去 10分
来源:百度知道 编辑:UC知道 时间:2024/05/17 01:04:03
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NoLayoutManagement extends Frame implements ActionListener{
JFrame frame;
JPanel panel;
JButton button;
JTextField textfield;
public NoLayoutManagement ()
{
frame=new JFrame();
panel=new JPanel();
textfield=new JTextField();
button=new JButton("确定");
panel.setLayout(null);
frame.add(panel);
panel.add(textfield);
panel.add(button);
textfield.setText("请输入123");
textfield.setBounds(80,30,42,18);
textfield.setSize(100,18);
button.setBounds(20,94,60,20);
button.addActionListener(this);
frame.setTitle("java图形化界面");
frame.setSize(300,500);
panel.setVisible(true);
frame.setVisible(true);
}
public static void main(String[] args) {
NoLayoutManagement
import java.awt.event.*;
import javax.swing.*;
public class NoLayoutManagement extends Frame implements ActionListener{
JFrame frame;
JPanel panel;
JButton button;
JTextField textfield;
public NoLayoutManagement ()
{
frame=new JFrame();
panel=new JPanel();
textfield=new JTextField();
button=new JButton("确定");
panel.setLayout(null);
frame.add(panel);
panel.add(textfield);
panel.add(button);
textfield.setText("请输入123");
textfield.setBounds(80,30,42,18);
textfield.setSize(100,18);
button.setBounds(20,94,60,20);
button.addActionListener(this);
frame.setTitle("java图形化界面");
frame.setSize(300,500);
panel.setVisible(true);
frame.setVisible(true);
}
public static void main(String[] args) {
NoLayoutManagement
if(textfield.getText().trim()=="123")试下
trim()是String的方法 作用是清除前和后的回车符和空格
保证最前和最后一个都是有效字符
if(textfield.getText()=="123")
试试用textfield.equal("123")或是textfield.equals("123")
忘了
if(textfield.getText().equals("123"))
这么改就行了。"=="和equals是有区别的。
java中
== 是判断2个引用是否指向同一对象,如:
String a=new String("aaa");
String b=a;
判断a和b是否指向同一对象,就要f(a==b){...}
在如:String a="aa";String b="bb" 判断要用
if(a.equals(b)){....}
按ctrl+1让eclipse自动改错
按ctrl+1让eclipse自动改错