关于addActionListener( this)能不能把this去掉?
关于addActionListener( this)能不能把this去掉?关于addActionListener( this)能不能把this去掉?是这样的,下面是我的一道习题,做完了我觉得mian方法只有一句,有点多余。。 就想把所有的都搬进main方法,但就是这个addActionListener( this)进不来。。我把this换了很多变量名都不对。 请高手指点。怎么样才能不用这个this? 下面是题目。。 //编程练习801 //创建一个框架并将其布局管理设为FlowLayout //创建两个面板并加入 //每个面板包含三个按键,并使用FlowLayout //点击按键时,在控制台显示信息。 import t.*; import javax.swing.*; import t.event.*; public class Test801 extends JFrame implements ActionListener { private JButton j01=new JButton("bu01"); private JButton j02=new JButton("bu02"); private JButton j03=new JButton("bu03"); private JButton j10=new JButton("bu10"); private JButton j20=new JButton("bu20"); private JButton j30=new JButton("bu30"); public static void main(String[] args) { Test801 frame=new Test801(); } public Test801() { JFrame myFrame=new JFrame("Test801"); tDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tSize(400,300); tVisible(true); tLayout(new FlowLayout()); JPanel p1=new JPanel(); JPanel p2=new JPanel(); tLayout(new FlowLayout()); tLayout(new FlowLayout()); dActionListener( this); dActionListener(this); dActionListener( this); dActionListener( this); dActionListener(this); dActionListener( this); d(j01); d(j02); d(j03); d(j10); d(j20); d(j30); d(p1); d(p2); } public void actionPerformed(ActionEvent e) { if( tSource()==j01) { intln("The bu01 button is clicked"); } else if ( tSource()==j02) { intln("The bu02 button is clicked"); } else if ( tSource()==j03) { intln("The bu03 button is clicked"); } else if ( tSource()==j10) { intln("The bu10 button is clicked"); } else if ( tSource()==j20) { intln("The bu20 button is clicked"); } else if ( tSource()==j30) { intln("The bu30 button is clicked"); } } }
这样写才好,才体现出java的面向对象的思想,在这里this指的是main函数里的new Test801()这个对象,若一定要加在main函数里 dActionListener(frame); 就可以了
答:这个网站listen to this 英语初,中,高级文本都有,我试过了,可以下载详情>>
答:google "java 缓冲池"详情>>
答:百度里搜张孝祥 非常好的视频教程详情>>