|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
还得说上一点,就java本质而言,是面相对象的,但是你有没有发现,java也不全是,比如说基本类型,int,那他就是整型而不是对象,转换类型是还得借助包装类。扫瞄器//显现对象为jpg,gifcanvas中绘图利用doublebuffering,利用scrollbar显现,显现地区流动了,能够扩大成依照canvas的巨细来显现的形式,由于canvas放在center地位。importjava.awt.*;importjava.awt.event.*;importjava.awt.image.*;importjavax.swing.*;classFrameextextendsFrame{}publicclassImagesextendsFrameimplementsActionListener,WindowListener,WindowStateListener{//Frameextfr=newFrameext();LabelLabel1=newLabel("",Label.LEFT);//willshowthefilenameButtonButton1=newButton("openfile");intxpos,ypos;intimageHeight;intw,h;Imageoffimg,bg;Graphicsoffg;booleanfirst=true;//extendsCanvas.Thiscodewilluseitspaintmethod.publicMyCanvasCanvas1=newMyCanvas();staticScrollbarhorizontal,vertical;//scrollbarusedFileDialogfd=newFileDialog(this,"Open",FileDialog.LOAD);ImageImage1;publicvoidinitialize(){//System.out.println("dddddd"+this.MAXIMIZED_BOTH);//this.setLocation(0,0);//this.setSize(this.getToolkit().getScreenSize());this.setSize(600,600);this.setLocation(30,30);this.setBackground(Color.lightGray);Canvas1.setBackground(Color.white);Canvas1.setSize(580,580);//ColorChooserDialogcolorDialog=newColorChooserDialog(this,"@fff",this);this.add("North",horizontal=newScrollbar(Scrollbar.HORIZONTAL));this.add("East",vertical=newScrollbar(Scrollbar.VERTICAL));Panelpa=newPanel();pa.setBackground(Color.white);Label1.setBackground(Color.lightGray);Label1.setAlignment(Label.LEFT);pa.add(Label1);pa.add(Button1);//addlabelandbuttononpanelthis.add("South",pa);//addpanelatsouththis.add("Center",Canvas1);this.addWindowListener(this);this.addWindowStateListener(this);Button1.addActionListener(this);try{System.out.println("getsize"+Canvas1.getSize()+"getwidth"+Canvas1.getWidth()+"getheight"+Canvas1.getHeight());}catch(Exceptione){System.out.println(e.toString());}this.pack();this.show();}voidimageload(){fd.setFile("*.jpg;*.gif");//filespeicificfd.show();if(fd.getFile()==null){Label1.setText("Youhavenotchosenanyimagefilesyet");}else{Stringd=(fd.getDirectory()+fd.getFile());Image1=Toolkit.getDefaultToolkit().getImage(d);if(Image1==null){System.out.println("imageisnullofthisfile:"+d);return;}Label1.setText(d);System.out.println("imageloaded"+d);//ItisimportanttouseCanvas1astheImageObserver.MediaTrackermt=newMediaTracker(Canvas1);//hereshouldbenoticedliketheauthorsaymt.addImage(Image1,0);try{mt.waitForAll();}catch(InterruptedExceptione){System.out.println(e.toString());}w=Image1.getWidth(this);h=Image1.getHeight(this);//setwandhtheimagesheightandwidthSystem.out.println("imagewidthandheightis"+w+""+h);if(offimg!=null&&(offimg.getHeight(this)<h||offimg.getWidth(this)<w)){//shallwerecreatetheoffimgfordoublebufferingiftheimageislargerSystem.out.println("offimagewandh"+offimg.getHeight(this)+""+offimg.getWidth(this)+"w"+w+"h"+h);offimg=createImage(w,h);offg=offimg.getGraphics();}vertical.setMaximum(h-390);//hereimportantsetscrollbarsmaximum//imagesizeminus(showsizeminusinsectssizefirst),//youcandetermtheinsectsbyprogramorsimplesetthemaximumto//acertainnumber,andthenyouscrollitdownandtracewhenitreach//theboundary,thevaluedoesnotagreewiththemaximumnumberyouset//andthedifferencemaybetheinsectssizeyoushallminusfirst//vertical.setVisibleAmount((h-290)/10);//ifwetrytosetthevisibleamounttoavariable,thescrollbywillbeuncertainand//hardtocontralhorizontal.setMaximum(w-440);//horizontal.setVisibleAmount((w-390)/10);Canvas1.repaint();//imageloadedsorepaintthecanvas//Canvas1.paint();}}publicbooleanhandleEvent(Evente){//System.out.println("catched"+e);//wecanseeclearlywhateventhappenifwedontcommentthissentenceif(e.id==Event.WINDOW_DESTROY){System.exit(0);}elseif(e.targetinstanceofScrollbar){System.out.println("scollofhandleevent");if(e.target==horizontal){xpos=((Integer)e.arg).intValue();//tracethescrollvalueforimageshowlater}elseif(e.target==vertical){ypos=((Integer)e.arg).intValue();}System.out.println(""+xpos+""+ypos);//System.out.println("checkinghereeeeeeeeeeeeeee");Canvas1.repaint();}returnsuper.handleEvent(e);}publicvoidwindowStateChanged(WindowEvente){System.out.println("windowstatechanged");Canvas1.repaint();}publicvoidwindowClosing(WindowEvente){//Usethis.hide();forsubsequentformsinmultiformapplicationsSystem.exit(0);}publicvoidwindowActivated(WindowEvente){System.out.println("windowactivated");Canvas1.repaint();}publicvoidwindowClosed(WindowEvente){}publicvoidwindowDeactivated(WindowEvente){}publicvoidwindowDeiconified(WindowEvente){}publicvoidwindowIconified(WindowEvente){}publicvoidwindowOpened(WindowEvente){}publicvoidactionPerformed(ActionEventevent){System.out.println("catched2"+event);Buttonb=(Button)event.getSource();if(b==Button1){imageload();}}publicstaticvoidmain(Stringargs[]){Imagesa=newImages();a.initialize();}/*publicvoidupdate(Graphicsg){Canvas1.update(g);}publicvoidpaint(Graphicsg){Canvas1.paint(g);}*///Asimpleinnerclasstoshowthebasics.classMyCanvasextendsCanvas{publicvoidupdate(Graphicsg){System.out.println("update");if(offg!=null&&Image1!=null){offg.clearRect(50,50,500,450);offg.drawImage(Image1,50,50,500,450,xpos,ypos,450+xpos,400+ypos,this);g.drawImage(offimg,50,50,this);System.out.println("wandhis"+w+""+h+"andcountupdateis"+"offg"+offg);}}publicvoidpaint(Graphicsg){if(first){offimg=createImage(getWidth(),getHeight());offg=offimg.getGraphics();System.out.println("wandhis"+w+""+h+"andcountupdateis"+"offg"+offg);first=false;}if(offg!=null&&Image1!=null)//ifdeletethiswhenthewindowstatechange,theimagewillnotshow{//youmustscrollthebarbyhandthenitwillshowweshowtakecarewhatthefunctionofpaintwhenrepaintoffg.clearRect(50,50,500,450);offg.drawImage(Image1,50,50,500,450,xpos,ypos,450+xpos,400+ypos,this);g.drawImage(offimg,50,50,this);System.out.println("wandhis"+w+""+h+"andcountupdateis"+"offg"+offg);}System.out.println("thisispaint");}}//Endofinnerclass.}
IDE是好。java中的IDE更是百花齐放,你用jbuilder能说jbuilder赶不上vs吗?用eclipse,netbeans也很舒服啊。我就不明白“稍微差一些”那一些是从哪里差来的。 |
|