仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1029|回复: 18
打印 上一主题 下一主题

[学习教程] JAVA编程:java图象扫瞄器

[复制链接]
爱飞 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:44:30 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

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也很舒服啊。我就不明白“稍微差一些”那一些是从哪里差来的。
爱飞 该用户已被删除
沙发
 楼主| 发表于 2015-3-17 21:10:59 | 显示全部楼层
在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-11 03:31

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表