欢迎来到天天文库
浏览记录
ID:48262273
大小:88.50 KB
页数:17页
时间:2020-01-20
《java web编程技术(沈泽刚,清华大学出版社)第十六章课后习题部分解答》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、*********AdapterDemo.java*********importjava.awt.event.*;importjavax.swing.JFrame;publicclassAdapterDemoextendsJFrame{publicstaticvoidmain(String[]args){AdapterDemoframe=newAdapterDemo();frame.setSize(220,80);frame.setLocationRelativeTo(null);frame.setDefaultCloseOpera
2、tion(JFrame.EXIT_ON_CLOSE);frame.setTitle("适配器演示");frame.setVisible(true);}publicAdapterDemo(){addWindowListener(newWindowAdapter(){publicvoidwindowActivated(WindowEventevent){System.out.println("窗口激活");}});}}***********AnimationDemo.java*****importjava.awt.*;importjav
3、a.awt.event.*;importjavax.swing.*;publicclassAnimationDemoextendsJFrame{publicAnimationDemo(){add(newMovingMessagePanel("消息移动"));}publicstaticvoidmain(String[]args){AnimationDemoframe=newAnimationDemo();frame.setSize(280,100);frame.setLocationRelativeTo(null);frame.set
4、DefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setTitle("消息移动演示");frame.setVisible(true);}staticclassMovingMessagePanelextendsJPanel{privateStringmessage="Java欢迎您";privateintxCoordinate=0;privateintyCoordinate=20;publicMovingMessagePanel(Stringmessage){this.message=
5、message;Timertimer=newTimer(1000,newTimerListener());timer.start();}protectedvoidpaintComponent(Graphicsg){super.paintComponent(g);if(xCoordinate>getWidth()){xCoordinate=-20;}xCoordinate+=5;g.drawString(message,xCoordinate,yCoordinate);}classTimerListenerimplementsActi
6、onListener{publicvoidactionPerformed(ActionEvente){repaint();}}//classTimerListenerimplementsActionListener}//staticclassMovingMessagePanelextendsJPanel}//publicclassAnimationDemoextendsJFrame*********AnonymousListenerDemo.java********importjavax.swing.*;importjava.awt
7、.event.*;publicclassAnonymousListenerDemoextendsJFrame{publicAnonymousListenerDemo(){JButtonjbtNew=newJButton("新建");JButtonjbtOpen=newJButton("打开");JButtonjbtSave=newJButton("保存");JButtonjbtPrint=newJButton("打印");JPanelpanel=newJPanel();panel.add(jbtNew);panel.add(jbtO
8、pen);panel.add(jbtSave);panel.add(jbtPrint);add(panel);jbtNew.addActionListener(newActionListener(){publicvoidactionP
此文档下载收益归作者所有