问题描述
importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;publicclassMvc2Ctrl{privateMvc2Viewview;privateMvc2Modelmodel;publicMvc2Ctrl(){view=newMvc2View();model=newMvc2Model();handleEvents();}//处理事件响应privatevoidhandleEvents(){addCloseLintener();addButtonListener();addButtonListener2();}//窗体关闭事件相应privatevoidaddCloseLintener(){view.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.out.println("ExitMVC2");System.exit(0);}});}privatevoidaddButtonListener(){//这个为什么在Jpanel上的为什么没有反应呀??????view.getButton().addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){System.out.println("dddddfdfdsfsf");}});}privatevoidaddButtonListener2(){view.getButton2().addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){view.getLabel2().setText(model.getText2());}});}}importjava.util.Calendar;importjava.util.GregorianCalendar;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.JPanel;//这是按钮下的jpanelpublicclassChangeMonthPanelextendsJPanel{/****/privatestaticfinallongserialVersionUID=-7265543933542495534L;privateJButtonlastYearBtn;privateJButtonlastMonthBtn;privateJLabelcurrMonthLbl;privateJButtonnextMonthBtn;privateJButtonnextYearBtn;publicChangeMonthPanel(){innit();}privatevoidinnit(){lastYearBtn=newJButton("<<");lastMonthBtn=newJButton("<");currMonthLbl=newJLabel();GregorianCalendarnow=newGregorianCalendar();intyear=now.get(Calendar.YEAR);intmonth=now.get(Calendar.MONTH);currMonthLbl.setText(String.valueOf(year)+"年"+String.valueOf(month+1)+"月");nextMonthBtn=newJButton(">");nextYearBtn=newJButton(">>");this.add(lastYearBtn);this.add(lastMonthBtn);this.add(currMonthLbl);this.add(nextMonthBtn);this.add(nextYearBtn);}publicJButtongetLastYearBtn(){returnlastYearBtn;}publicvoidsetLastYearBtn(JButtonlastYearBtn){this.lastYearBtn=lastYearBtn;}publicJButtongetLastMonthBtn(){returnlastMonthBtn;}publicvoidsetLastMonthBtn(JButtonlastMonthBtn){this.lastMonthBtn=lastMonthBtn;}publicJLabelgetCurrMonthLbl(){returncurrMonthLbl;}publicvoidsetCurrMonthLbl(JLabelcurrMonthLbl){this.currMonthLbl=currMonthLbl;}publicJButtongetNextMonthBtn(){returnnextMonthBtn;}publicvoidsetNextMonthBtn(JButtonnextMonthBtn){this.nextMonthBtn=nextMonthBtn;}publicJButtongetNextYearBtn(){returnnextYearBtn;}publicvoidsetNextYearBtn(JButtonnextYearBtn){this.nextYearBtn=nextYearBtn;}publicstaticlonggetSerialVersionUID(){returnserialVersionUID;}}帮帮忙啦~~~~源码我也上传了!
解决方案
解决方案二:
帮顶下!