|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
专门做了这个例子;而java的这个例子好像就是为了教学而写的,很多教学目的的例子是不考虑优化、性能的。
外部类是新的事务模子,而且现实上旧的事务模子连同新库的特性都被它好的撑持,依附老式的编程办法无疑增添了一个新的凌乱的要素。如今有更多分歧的办法为我们编写厌恶的代码。恰巧的是,这类代码展现在本书中和程序样本中,而且乃至在文件和程序样本中同SUN公司区分开来。在这一节中,我们将看到一些关于我们会和不会运转新AWT的争吵,并由向我们展现除能够包涵的情形,我们能够随时利用吸收器类往办理我们的事务处置必要来停止。由于这类办法一样是最复杂和最明晰的办法,它将会对我们进修它组成无效的匡助。
在看就任何事之前,我们晓得只管Java1.1向后兼容Java1.0(也就是说,我们能够在1.1中编译和运转1.0的程序),但我们其实不能在统一个程序里夹杂事务模子。换言之,当我们试图集成老的代码到一个新的程序中时,我们不克不及利用老式的action()办法在统一个程序中,因而我们必需决意是不是对新程序利用老的,难以保护的办法大概晋级老的代码。这不会有太多的合作由于新的办法对老的办法而言是云云的优异。
1.原则:运转它的好办法
为了给我们一些事物来举行对照,这儿有一个程序例子演示向我们保举的办法。到如今它会变得相称的熟习和温馨。- //:GoodIdea.java
- //Thebestwaytodesignclassesusingthenew
- //Java1.1eventmodel:useaninnerclassfor
- //eachdifferentevent.Thismaximizes
- //flexibilityandmodularity.
- importjava.awt.*;
- importjava.awt.event.*;
- importjava.util.*;
- publicclassGoodIdeaextendsFrame{
- Button
- b1=newButton("Button1"),
- b2=newButton("Button2");
- publicGoodIdea(){
- setLayout(newFlowLayout());
- b1.addActionListener(newB1L());
- b2.addActionListener(newB2L());
- add(b1);
- add(b2);
- }
- publicclassB1LimplementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- System.out.println("Button1pressed");
- }
- }
- publicclassB2LimplementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- System.out.println("Button2pressed");
- }
- }
- publicstaticvoidmain(String[]args){
- Framef=newGoodIdea();
- f.addWindowListener(
- newWindowAdapter(){
- publicvoidwindowClosing(WindowEvente){
- System.out.println("WindowClosing");
- System.exit(0);
- }
- });
- f.setSize(300,200);
- f.setVisible(true);
- }
- }///:~
复制代码
这是很有点微乎其微的:每一个按钮有它本人的印出一些事物到把持台的吸收器。但请注重在全部程序中这不是一个前提语句,大概是一些暗示“我想要晓得如何使事务产生”的语句。每块代码都与运转有关,而不是范例查验。也就是说,这是最好的编写我们的代码的办法;不单单是它更容易使我们了解观点,最少是使我们更容易浏览和保护。剪切和粘贴到新的程序是一样云云的简单。
2.将主类作为吸收器完成
第一个坏主张是一个一般的和保举的办法。这使得主类(有代表性的是程序片或帧,但它能酿成一些类)实行各类分歧的吸收器。上面是一个例子:- //:BadIdea1.java
- //Someliteraturerecommendsthisapproach,
- //butitsmissingthepointofthenewevent
- //modelinJava1.1
- importjava.awt.*;
- importjava.awt.event.*;
- importjava.util.*;
- publicclassBadIdea1extendsFrame
- implementsActionListener,WindowListener{
- Button
- b1=newButton("Button1"),
- b2=newButton("Button2");
- publicBadIdea1(){
- setLayout(newFlowLayout());
- addWindowListener(this);
- b1.addActionListener(this);
- b2.addActionListener(this);
- add(b1);
- add(b2);
- }
- publicvoidactionPerformed(ActionEvente){
- Objectsource=e.getSource();
- if(source==b1)
- System.out.println("Button1pressed");
- elseif(source==b2)
- System.out.println("Button2pressed");
- else
- System.out.println("Somethingelse");
- }
- publicvoidwindowClosing(WindowEvente){
- System.out.println("WindowClosing");
- System.exit(0);
- }
- publicvoidwindowClosed(WindowEvente){}
- publicvoidwindowDeiconified(WindowEvente){}
- publicvoidwindowIconified(WindowEvente){}
- publicvoidwindowActivated(WindowEvente){}
- publicvoidwindowDeactivated(WindowEvente){}
- publicvoidwindowOpened(WindowEvente){}
- publicstaticvoidmain(String[]args){
- Framef=newBadIdea1();
- f.setSize(300,200);
- f.setVisible(true);
- }
- }///:~
复制代码
如许做的用处显现鄙人述三行里:
addWindowListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
由于Badidea1实行举措吸收器和窗中吸收器,这些程序行固然能够承受,而且假如我们一向保持想法使大批的类往削减服务器检索时代的程序片载进的作法,它看起来酿成一个不错的主张。可是:
(1)Java1.1版撑持JAR文件,因而一切我们的文件能够被安排到一个单一的紧缩的JAR文件中,只必要一次服务器检索。我们不再必要为Internet效力而削减类的数目。
(2)下面的代码的组件加倍的少,因而它难以捉住和粘贴。注重我们必需不但要实行林林总总的接口为我们的主类,但在actionPerformed()办法中,我们使用一串前提语句测试哪一个举措被完成了。不单单是这个形态发展,阔别吸收器模子,除此以外,我们不克不及复杂地反复利用actionPerformed()办法由于它是指定为这个特别的使用程序利用的。将这个程序例子与GoodIdea.java举行对照,我们能够恰好捕获一个吸收器类并粘贴它和最小的焦心就任何中央。别的我们能够为一个独自的事务注册多个吸收器类,同意乃至更多的模块在每一个吸收器类在每一个吸收器中运转。
3.办法的夹杂
第二个badidea夹杂了两种办法:利用内嵌吸收器类,但一样实行一个或更多的吸收器接口以作为主类的一部分。这类办法无需在书中和文件中举行注释,并且我能够揣测到Java开辟者以为他们必需为分歧的目标而接纳分歧的办法。但我们却不用——在我们编程时,我们也许大概会偏向于利用内嵌吸收器类。- //:BadIdea2.java
- //AnimprovementoverBadIdea1.java,sinceit
- //usestheWindowAdapterasaninnerclass
- //insteadofimplementingallthemethodsof
- //WindowListener,butstillmissesthe
- //valuablemodularityofinnerclasses
- importjava.awt.*;
- importjava.awt.event.*;
- importjava.util.*;
- publicclassBadIdea2extendsFrame
- implementsActionListener{
- Button
- b1=newButton("Button1"),
- b2=newButton("Button2");
- publicBadIdea2(){
- setLayout(newFlowLayout());
- addWindowListener(newWL());
- b1.addActionListener(this);
- b2.addActionListener(this);
- add(b1);
- add(b2);
- }
- publicvoidactionPerformed(ActionEvente){
- Objectsource=e.getSource();
- if(source==b1)
- System.out.println("Button1pressed");
- elseif(source==b2)
- System.out.println("Button2pressed");
- else
- System.out.println("Somethingelse");
- }
- classWLextendsWindowAdapter{
- publicvoidwindowClosing(WindowEvente){
- System.out.println("WindowClosing");
- System.exit(0);
- }
- }
- publicstaticvoidmain(String[]args){
- Framef=newBadIdea2();
- f.setSize(300,200);
- f.setVisible(true);
- }
- }///:~
复制代码
由于actionPerformed()举措完成办法同主类严密地分离,以是难以复用代码。它的代码读起来一样是混乱和使人腻烦的,远远凌驾了外部类办法。分歧理的是,我们不能不在Java1.1版中为事务利用那些老的思绪。
4.承继一个组件
创立一个新范例的组件时,在运转事务的老办法中,我们会常常看到分歧的中央产生了变更。这里有一个程序例子来演示这类新的事情办法:- //:GoodTechnique.java
- //Yourfirstchoicewhenoverridingcomponents
- //shouldbetoinstalllisteners.Thecodeis
- //muchsafer,moremodularandmaintainable.
- importjava.awt.*;
- importjava.awt.event.*;
- classDisplay{
- publicstaticfinalint
- EVENT=0,COMPONENT=1,
- MOUSE=2,MOUSE_MOVE=3,
- FOCUS=4,KEY=5,ACTION=6,
- LAST=7;
- publicString[]evnt;
- Display(){
- evnt=newString[LAST];
- for(inti=0;i<LAST;i++)
- evnt[i]=newString();
- }
- publicvoidshow(Graphicsg){
- for(inti=0;i<LAST;i++)
- g.drawString(evnt[i],0,10*i+10);
- }
- }
- classEnabledPanelextendsPanel{
- Colorc;
- intid;
- Displaydisplay=newDisplay();
- publicEnabledPanel(inti,Colormc){
- id=i;
- c=mc;
- setLayout(newBorderLayout());
- add(newMyButton(),BorderLayout.SOUTH);
- addComponentListener(newCL());
- addFocusListener(newFL());
- addKeyListener(newKL());
- addMouseListener(newML());
- addMouseMotionListener(newMML());
- }
- //Toeliminateflicker:
- publicvoidupdate(Graphicsg){
- paint(g);
- }
- publicvoidpaint(Graphicsg){
- g.setColor(c);
- Dimensions=getSize();
- g.fillRect(0,0,s.width,s.height);
- g.setColor(Color.black);
- display.show(g);
- }
- //Dontneedtoenableanythingforthis:
- publicvoidprocessEvent(AWTEvente){
- display.evnt[Display.EVENT]=e.toString();
- repaint();
- super.processEvent(e);
- }
- classCLimplementsComponentListener{
- publicvoidcomponentMoved(ComponentEvente){
- display.evnt[Display.COMPONENT]=
- "Componentmoved";
- repaint();
- }
- publicvoid
- componentResized(ComponentEvente){
- display.evnt[Display.COMPONENT]=
- "Componentresized";
- repaint();
- }
- publicvoid
- componentHidden(ComponentEvente){
- display.evnt[Display.COMPONENT]=
- "Componenthidden";
- repaint();
- }
- publicvoidcomponentShown(ComponentEvente){
- display.evnt[Display.COMPONENT]=
- "Componentshown";
- repaint();
- }
- }
- classFLimplementsFocusListener{
- publicvoidfocusGained(FocusEvente){
- display.evnt[Display.FOCUS]=
- "FOCUSgained";
- repaint();
- }
- publicvoidfocusLost(FocusEvente){
- display.evnt[Display.FOCUS]=
- "FOCUSlost";
- repaint();
- }
- }
- classKLimplementsKeyListener{
- publicvoidkeyPressed(KeyEvente){
- display.evnt[Display.KEY]=
- "KEYpressed:";
- showCode(e);
- }
- publicvoidkeyReleased(KeyEvente){
- display.evnt[Display.KEY]=
- "KEYreleased:";
- showCode(e);
- }
- publicvoidkeyTyped(KeyEvente){
- display.evnt[Display.KEY]=
- "KEYtyped:";
- showCode(e);
- }
- voidshowCode(KeyEvente){
- intcode=e.getKeyCode();
- display.evnt[Display.KEY]+=
- KeyEvent.getKeyText(code);
- repaint();
- }
- }
- classMLimplementsMouseListener{
- publicvoidmouseClicked(MouseEvente){
- requestFocus();//GetFOCUSonclick
- display.evnt[Display.MOUSE]=
- "MOUSEclicked";
- showMouse(e);
- }
- publicvoidmousePressed(MouseEvente){
- display.evnt[Display.MOUSE]=
- "MOUSEpressed";
- showMouse(e);
- }
- publicvoidmouseReleased(MouseEvente){
- display.evnt[Display.MOUSE]=
- "MOUSEreleased";
- showMouse(e);
- }
- publicvoidmouseEntered(MouseEvente){
- display.evnt[Display.MOUSE]=
- "MOUSEentered";
- showMouse(e);
- }
- publicvoidmouseExited(MouseEvente){
- display.evnt[Display.MOUSE]=
- "MOUSEexited";
- showMouse(e);
- }
- voidshowMouse(MouseEvente){
- display.evnt[Display.MOUSE]+=
- ",x="+e.getX()+
- ",y="+e.getY();
- repaint();
- }
- }
- classMMLimplementsMouseMotionListener{
- publicvoidmouseDragged(MouseEvente){
- display.evnt[Display.MOUSE_MOVE]=
- "MOUSEdragged";
- showMouse(e);
- }
- publicvoidmouseMoved(MouseEvente){
- display.evnt[Display.MOUSE_MOVE]=
- "MOUSEmoved";
- showMouse(e);
- }
- voidshowMouse(MouseEvente){
- display.evnt[Display.MOUSE_MOVE]+=
- ",x="+e.getX()+
- ",y="+e.getY();
- repaint();
- }
- }
- }
- classMyButtonextendsButton{
- intclickCounter;
- Stringlabel="";
- publicMyButton(){
- addActionListener(newAL());
- }
- publicvoidpaint(Graphicsg){
- g.setColor(Color.green);
- Dimensions=getSize();
- g.fillRect(0,0,s.width,s.height);
- g.setColor(Color.black);
- g.drawRect(0,0,s.width-1,s.height-1);
- drawLabel(g);
- }
- privatevoiddrawLabel(Graphicsg){
- FontMetricsfm=g.getFontMetrics();
- intwidth=fm.stringWidth(label);
- intheight=fm.getHeight();
- intascent=fm.getAscent();
- intleading=fm.getLeading();
- inthorizMargin=
- (getSize().width-width)/2;
- intverMargin=
- (getSize().height-height)/2;
- g.setColor(Color.red);
- g.drawString(label,horizMargin,
- verMargin+ascent+leading);
- }
- classALimplementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- clickCounter++;
- label="click#"+clickCounter+
- ""+e.toString();
- repaint();
- }
- }
- }
- publicclassGoodTechniqueextendsFrame{
- GoodTechnique(){
- setLayout(newGridLayout(2,2));
- add(newEnabledPanel(1,Color.cyan));
- add(newEnabledPanel(2,Color.lightGray));
- add(newEnabledPanel(3,Color.yellow));
- }
- publicstaticvoidmain(String[]args){
- Framef=newGoodTechnique();
- f.setTitle("GoodTechnique");
- f.addWindowListener(
- newWindowAdapter(){
- publicvoidwindowClosing(WindowEvente){
- System.out.println(e);
- System.out.println("WindowClosing");
- System.exit(0);
- }
- });
- f.setSize(700,700);
- f.setVisible(true);
- }
- }///:~
复制代码
这个程序例子一样证实了林林总总的发明和显现关于它们的信息的事务。这类显现是一种会合显现信息的办法。一组字符串往猎取关于每品种型的事务的信息,而且show()办法对任何图象对象都设置了一个句柄,我们接纳并间接地写在表面代码上。这类计划是成心的被某种事务反复利用。
激活面板代表了这类新型的组件。它是一个底部有一个按钮的黑色的面板,而且它由使用吸收器类为每个独自的事务来激发捕获一切产生在它之上的事务,除那些在激活面板过载的老式的processEvent()办法(注重它应当一样挪用super.processEvent())。使用这类办法的独一来由是它捕获产生的每个事务,因而我们能够察看延续产生的每事务。processEvent()办法没有更多的展现代表每一个事务的字符串,不然它会不能不利用一串前提语句往寻觅事务。在别的方面,内嵌吸收类早已明晰地晓得被发明的事务。(假定我们注册它们到组件,我们不必要任何的控件的逻辑,这将成为我们的目标。)因而,它们不会往反省任何事务;这些事务恰好做它们的原质料。
每一个吸收器修正显现字符串和它的指定事务,而且挪用重画办法repaint()因而将显现这个字符串。我们一样能注重到一个一般能打消闪灼的法门:
publicvoidupdate(Graphicsg){
paint(g);
}
我们不会一直必要过载update(),但假如我们写下一些闪灼的程序,并运转它。默许的最新版本的扫除背景然后挪用paint()办法从头画出一些丹青。这个扫除举措一般会发生闪灼,可是不用要的,由于paint()重画了全部的表面。
我们能够看到很多的吸收器——可是,对吸收器输出反省指令,但我们却不克不及吸收任何组件不撑持的事务。(不像BadTechnuque.java那样我们能每时每刻看到)。
实验这个程序是非常的有教导意义的,由于我们进修了很多的关于在Java中事务产生的办法。一则它展现了年夜多半开窗口的体系中计划上的瑕疵:它相称的难以往单击和开释鼠标,除非挪动它,而且当我们实践上正试图用鼠标单击在某物体上时开窗口的会经常以为我们是在拖动。一个办理这个成绩的计划是利用mousePressed()鼠标按下办法和mouseReleased()鼠标开释办法往取代mouseClicked()鼠标单击办法,然后判别是不是往挪用我们本人的以工夫和4个像素的鼠标滞后感化的“mouseReallyClicked()实在的鼠标单击”办法。
5.糟糕的组件承继
另外一种做法是挪用enableEvent()办法,并将与但愿把持的事务对应的模子传送给它(很多参考书中都曾说起这类做法)。如许做会形成那些事务被发送至老式办法(只管它们对Java1.1来讲是新的),并接纳象processFocusEvent()如许的名字。也必需要记着挪用基本类版本。上面是它看起来的模样。- //:BadTechnique.java
- //Itspossibletooverridecomponentsthisway,
- //butthelistenerapproachismuchbetter,so
- //whywouldyou?
- importjava.awt.*;
- importjava.awt.event.*;
- classDisplay{
- publicstaticfinalint
- EVENT=0,COMPONENT=1,
- MOUSE=2,MOUSE_MOVE=3,
- FOCUS=4,KEY=5,ACTION=6,
- LAST=7;
- publicString[]evnt;
- Display(){
- evnt=newString[LAST];
- for(inti=0;i<LAST;i++)
- evnt[i]=newString();
- }
- publicvoidshow(Graphicsg){
- for(inti=0;i<LAST;i++)
- g.drawString(evnt[i],0,10*i+10);
- }
- }
- classEnabledPanelextendsPanel{
- Colorc;
- intid;
- Displaydisplay=newDisplay();
- publicEnabledPanel(inti,Colormc){
- id=i;
- c=mc;
- setLayout(newBorderLayout());
- add(newMyButton(),BorderLayout.SOUTH);
- //Typecheckingislost.Youcanenableand
- //processeventsthatthecomponentdoesnt
- //capture:
- enableEvents(
- //Paneldoesnthandlethese:
- AWTEvent.ACTION_EVENT_MASK|
- AWTEvent.ADJUSTMENT_EVENT_MASK|
- AWTEvent.ITEM_EVENT_MASK|
- AWTEvent.TEXT_EVENT_MASK|
- AWTEvent.WINDOW_EVENT_MASK|
- //Panelcanhandlethese:
- AWTEvent.COMPONENT_EVENT_MASK|
- AWTEvent.FOCUS_EVENT_MASK|
- AWTEvent.KEY_EVENT_MASK|
- AWTEvent.MOUSE_EVENT_MASK|
- AWTEvent.MOUSE_MOTION_EVENT_MASK|
- AWTEvent.CONTAINER_EVENT_MASK);
- //Youcanenableaneventwithout
- //overridingitsprocessmethod.
- }
- //Toeliminateflicker:
- publicvoidupdate(Graphicsg){
- paint(g);
- }
- publicvoidpaint(Graphicsg){
- g.setColor(c);
- Dimensions=getSize();
- g.fillRect(0,0,s.width,s.height);
- g.setColor(Color.black);
- display.show(g);
- }
- publicvoidprocessEvent(AWTEvente){
- display.evnt[Display.EVENT]=e.toString();
- repaint();
- super.processEvent(e);
- }
- publicvoid
- processComponentEvent(ComponentEvente){
- switch(e.getID()){
- caseComponentEvent.COMPONENT_MOVED:
- display.evnt[Display.COMPONENT]=
- "Componentmoved";
- break;
- caseComponentEvent.COMPONENT_RESIZED:
- display.evnt[Display.COMPONENT]=
- "Componentresized";
- break;
- caseComponentEvent.COMPONENT_HIDDEN:
- display.evnt[Display.COMPONENT]=
- "Componenthidden";
- break;
- caseComponentEvent.COMPONENT_SHOWN:
- display.evnt[Display.COMPONENT]=
- "Componentshown";
- break;
- default:
- }
- repaint();
- //Mustalwaysremembertocallthe"super"
- //versionofwhateveryouoverride:
- super.processComponentEvent(e);
- }
- publicvoidprocessFocusEvent(FocusEvente){
- switch(e.getID()){
- caseFocusEvent.FOCUS_GAINED:
- display.evnt[Display.FOCUS]=
- "FOCUSgained";
- break;
- caseFocusEvent.FOCUS_LOST:
- display.evnt[Display.FOCUS]=
- "FOCUSlost";
- break;
- default:
- }
- repaint();
- super.processFocusEvent(e);
- }
- publicvoidprocessKeyEvent(KeyEvente){
- switch(e.getID()){
- caseKeyEvent.KEY_PRESSED:
- display.evnt[Display.KEY]=
- "KEYpressed:";
- break;
- caseKeyEvent.KEY_RELEASED:
- display.evnt[Display.KEY]=
- "KEYreleased:";
- break;
- caseKeyEvent.KEY_TYPED:
- display.evnt[Display.KEY]=
- "KEYtyped:";
- break;
- default:
- }
- intcode=e.getKeyCode();
- display.evnt[Display.KEY]+=
- KeyEvent.getKeyText(code);
- repaint();
- super.processKeyEvent(e);
- }
- publicvoidprocessMouseEvent(MouseEvente){
- switch(e.getID()){
- caseMouseEvent.MOUSE_CLICKED:
- requestFocus();//GetFOCUSonclick
- display.evnt[Display.MOUSE]=
- "MOUSEclicked";
- break;
- caseMouseEvent.MOUSE_PRESSED:
- display.evnt[Display.MOUSE]=
- "MOUSEpressed";
- break;
- caseMouseEvent.MOUSE_RELEASED:
- display.evnt[Display.MOUSE]=
- "MOUSEreleased";
- break;
- caseMouseEvent.MOUSE_ENTERED:
- display.evnt[Display.MOUSE]=
- "MOUSEentered";
- break;
- caseMouseEvent.MOUSE_EXITED:
- display.evnt[Display.MOUSE]=
- "MOUSEexited";
- break;
- default:
- }
- display.evnt[Display.MOUSE]+=
- ",x="+e.getX()+
- ",y="+e.getY();
- repaint();
- super.processMouseEvent(e);
- }
- publicvoid
- processMouseMotionEvent(MouseEvente){
- switch(e.getID()){
- caseMouseEvent.MOUSE_DRAGGED:
- display.evnt[Display.MOUSE_MOVE]=
- "MOUSEdragged";
- break;
- caseMouseEvent.MOUSE_MOVED:
- display.evnt[Display.MOUSE_MOVE]=
- "MOUSEmoved";
- break;
- default:
- }
- display.evnt[Display.MOUSE_MOVE]+=
- ",x="+e.getX()+
- ",y="+e.getY();
- repaint();
- super.processMouseMotionEvent(e);
- }
- }
- classMyButtonextendsButton{
- intclickCounter;
- Stringlabel="";
- publicMyButton(){
- enableEvents(AWTEvent.ACTION_EVENT_MASK);
- }
- publicvoidpaint(Graphicsg){
- g.setColor(Color.green);
- Dimensions=getSize();
- g.fillRect(0,0,s.width,s.height);
- g.setColor(Color.black);
- g.drawRect(0,0,s.width-1,s.height-1);
- drawLabel(g);
- }
- privatevoiddrawLabel(Graphicsg){
- FontMetricsfm=g.getFontMetrics();
- intwidth=fm.stringWidth(label);
- intheight=fm.getHeight();
- intascent=fm.getAscent();
- intleading=fm.getLeading();
- inthorizMargin=
- (getSize().width-width)/2;
- intverMargin=
- (getSize().height-height)/2;
- g.setColor(Color.red);
- g.drawString(label,horizMargin,
- verMargin+ascent+leading);
- }
- publicvoidprocessActionEvent(ActionEvente){
- clickCounter++;
- label="click#"+clickCounter+
- ""+e.toString();
- repaint();
- super.processActionEvent(e);
- }
- }
- publicclassBadTechniqueextendsFrame{
- BadTechnique(){
- setLayout(newGridLayout(2,2));
- add(newEnabledPanel(1,Color.cyan));
- add(newEnabledPanel(2,Color.lightGray));
- add(newEnabledPanel(3,Color.yellow));
- //YoucanalsodoitforWindows:
- enableEvents(AWTEvent.WINDOW_EVENT_MASK);
- }
- publicvoidprocessWindowEvent(WindowEvente){
- System.out.println(e);
- if(e.getID()==WindowEvent.WINDOW_CLOSING){
- System.out.println("WindowClosing");
- System.exit(0);
- }
- }
- publicstaticvoidmain(String[]args){
- Framef=newBadTechnique();
- f.setTitle("BadTechnique");
- f.setSize(700,700);
- f.setVisible(true);
- }
- }///:~
复制代码
切实其实,它可以事情。但却其实太糟糕,并且很难编写、浏览、调试、保护和再生。既然云云,为何还不利用外部吸收器类呢?
学习JAVA的目的更多的是培养自身的工作能力,我觉得工作能力的一个核心就是:独立思考能力,因为只有独立思考后,才会有自己的见解 |
|