java吧 关注:1,247,185贴子:12,725,272
  • 3回复贴,共1

可以在一个类不继承Frame情况下给button1与button2添加事件监听器吗

只看楼主收藏回复


import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
class Deng{
public JFrame jf = new JFrame("酒店管理系统");
public Container con = jf.getContentPane() ;
public Toolkit toolkit = Toolkit.getDefaultToolkit() ;
public Dimension sc = toolkit.getScreenSize() ;
public JLabel name1 = new JLabel("用户名") ;
public JLabel pass1 = new JLabel("密码") ;
public JTextField textName = new JTextField() ;
public JPasswordField textPs = new JPasswordField() ;
public JButton button1 = new JButton("登陆") ;
public JButton button2 = new JButton("重置") ;
public Deng() {
con.setLayout(null) ;
jf.setSize(sc.width/3,sc.height*10/25) ;
jf.setLocation(sc.width/3,sc.height/4) ;
con.setLayout(null) ;
jf.setSize(sc.width/3,sc.height*10/25) ;
jf.setLocation(sc.width/3,sc.height/4) ;
jf.setResizable(false) ;
name1.setLocation(80,30) ;
name1.setSize(100, 100) ;
name1.setForeground(Color.white) ;
pass1.setLocation(80,90) ;
pass1.setSize(100,100) ;
pass1.setForeground(Color.white) ;
textName.setSize(140, 20) ;
textName.setLocation(170, 70) ;
textPs.setSize(140, 20) ;
textPs.setLocation(170, 130) ;
textPs.setEchoChar('*') ;
button1.setSize(90,25) ;
button1.setLocation(80,180 ) ;
button2.setSize(90,25) ;
button2.setLocation(220, 180) ;
con.add(name1) ;
con.add(pass1) ;
con.add(textName) ;
con.add(textPs) ;
con.add(button1) ;
con.add(button2) ;
con.setBackground(Color.black) ;
jf.setResizable(false) ;
jf.setVisible(true) ;
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class Denglu {
public static void main(String args[]) {
new Deng() ;
}
}


IP属地:湖南1楼2011-11-03 15:12回复
    button1中怎样添加事件监听器?


    IP属地:湖南2楼2011-11-03 15:14
    回复
      菜鸟向高手们求助啊!!


      IP属地:湖南3楼2011-11-03 15:16
      回复
        有人吗???


        IP属地:湖南4楼2011-11-03 15:20
        回复