• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

java同一包下的两个文件,一个文件中的函数调用另一个文件中的函数失败?

分成两个文件写问题:第二个listenns文件中函数没有被调用,原因是生成的界面上start按钮和右上角的关闭按钮点击无反应,请问原因是什么test文件package SecondJava;import java.awt.*;import java.awt.event.*;public class test extends Frame implements ActionListener{        private Button start=new Button("Start");        private Button show=new Button("Show");        private Button close=new Button("close");        private TextField display=new TextField(25);        private listens count=new listens(show,25);        private class WindowCloser extends WindowAdapter{                public void WindowClosing(WindowEvent we){                        System.exit(0);                }        }        public test(){                super("CountDown Tester");                setLayout(new FlowLayout());                addWindowListener(new WindowCloser());                add(start);                add(show);                add(display);                add(close);                close.addActionListener(this);                show.addActionListener(this);                start.addActionListener(this);                count.addActionListener(this);                                pack();                setVisible(true);        }        public void actionPerformed(ActionEvent e){                if(e.getSource()==start){                        count.startCounting();                }                else if(e.getSource()==show)display.setText("Event came from:"+e.getActionCommand());                else if(e.getSource()==close)System.exit(0);        }        public static void main(String args[]){                test c=new test();        }}listens文件package SecondJava;import java.awt.*;import java.awt.event.*;public class listens {        ActionListener listener=null;        Object source=null;        int maxCount=10;        public listens(Object _source,int _maxCount){                maxCount=_maxCount;                source=_source;        }        public void addActionListener(ActionListener newListener){                listener=AWTEventMulticaster.add(listener, newListener);        }        public void removeActionListener(ActionListener oldListener){                listener=AWTEventMulticaster.remove(listener, oldListener);        }        public void startCounting(){                if(listener==null){                        for(int i=maxCount;i>=0;i--){                                System.out.println("i:"+i);                                System.out.println("Done.Generating event now...");                                listener.actionPerformed(new ActionEvent(source,ActionEvent.ACTION_PERFORMED,"CountDown"));                        }                }        }}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

private只能在本包内调用啊,你改成public就行了。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!