Topic: 各位大哥帮帮我! (== and equals)

  Print this page

1.各位大哥帮帮我! (== and equals) Copy to clipboard
Posted by: sss6586576
Posted on: 2004-10-21 15:52

{ 请尽量用准确的文字描述作为标题 }


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class bbb extends JApplet implements WindowListener,ActionListener,ItemListener
{
JOptionPane p1=new JOptionPane();
JLabel l1=new JLabel("name");
JLabel l2=new JLabel("nosmoking seat distinct");
JLabel l3=new JLabel("smoking seat distinct");
JCheckBox c1=new JCheckBox();
JCheckBox c2=new JCheckBox();
JTextField t=new JTextField(10);
JButton b=new JButton("确定");


public bbb()
{
Container container = getContentPane();
container.setLayout(new FlowLayout());

container.add(l1);
container.add(t );
container.add(l2);
container.add(c1);
c1.addItemListener(this);
container.add(l3);
container.add(c2);
c2.addItemListener(this);
container.add(b);
b.addActionListener(this);
}
public void windowClosing(WindowEvent e){System.exit(0);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}

public void itemStateChanged(ItemEvent e)
{

if(e.getSource()==c1&&e.getSource()==c2)
{

p1.showMessageDialog(null,"error");

}

}

public void actionPerformed(ActionEvent e)
{

if(e.getSource()==b)
{
if(t.getText()=="")
{

p1.showMessageDialog(null,"name is null.");

}
}
}
}

它的功能是录入信息.当name 为空时,出现提示框"error",当两个checkbox同时被选时,也出现提示框"error".但界面做出来了,可是事件怎么也弄不出来.
请各位大哥指点,另外,小弟学事件方面的处理.但这是图书馆这方面的书太少了.不知哪位热心大哥可以推荐小弟一本书看.

2.Re:各位大哥帮帮我! [Re: sss6586576] Copy to clipboard
Posted by: qingbo777
Posted on: 2004-10-21 16:32

把t.getText()=="" 改成 t.getText().equals("")
另外e.getSource()==c1&&e.getSource()==c2明显是不对的.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923