desktop.zip

  • 管理员
    了解作者
  • Java
    开发工具
  • 3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 775
    下载次数
  • 2001-01-18 16:26
    上传日期
象win95开始菜单一样的地址菜单
desktop.zip
  • www.pudn.com.txt
    218B
  • Desktop.htm
    300B
  • desktop.java
    7.9KB
内容介绍
import java.net.*; import java.lang.*; import java.util.*; import java.awt.*; import java.applet.*; public class desktop extends Applet { Frame f; Image wallpaper; //for Icons (size=32x32) int iconWH=32; int iconCount=0; Vector iconText =new Vector(); Vector icons =new Vector(); Vector iconX =new Vector(); Vector iconY =new Vector(); Vector iconLink =new Vector(); //for StartBtn String startbtn="Start"; int startbtnEX=0; Image startlogo,buffer=null; //for PopMenu Vector items=new Vector(); Vector hrefs=new Vector(); Dimension d=size(); boolean pop=false; int maxLength=0; int fwidth=100; int itemCount=0; int mouseX=0,mouseY=0; int menuY=0,menuEY=0; int fheight=0; //code for Icons public void addIcon(String txt,Image img,String href,String x,String y) { iconText.addElement(txt); icons.addElement(img); iconLink.addElement(href); iconX.addElement(x); iconY.addElement(y); iconCount++; } //code for PopMenu public void addItem(String caption,String href) { items.addElement(caption); hrefs.addElement(href); if(caption.length()>maxLength)maxLength=caption.length(); itemCount++; } public boolean mouseUp(Event e,int x,int y) { int tempY=0,i=0,ix=0,iy=0,iex=0; mouseX=x; mouseY=y; if(pop&&(0<=mouseX)&&(menuY<mouseY)&&(fwidth>=mouseX)&&(menuEY>mouseY)) { for(tempY=menuY;tempY<menuEY;tempY+=fheight,i++) if((tempY+8<mouseY)&&(tempY+fheight+8>mouseY)) { repaint(0,tempY+8,fwidth,tempY+fheight+8); showStatus("Select "+i+" is "+items.elementAt(i)+" Link To "+hrefs.elementAt(i)); break; } do_menu(i); } else if((0<=mouseX)&&(d.height-fheight<mouseY)&&(startbtnEX>=mouseX)&&(d.height>mouseY)) {pop=!pop;repaint();} else { repaint(); pop=false; } if(iconCount>0) for(i=iconCount-1;i>=0;i--) { if(icons.elementAt(i)!=null) { ix= Integer.parseInt((String) iconX.elementAt(i))-iconWH/2; iex=iconWH; iy= Integer.parseInt((String) iconY.elementAt(i))+iconWH; if((ix<=mouseX)&&(iy-iconWH<=mouseY) &&(ix+iex>=mouseX)&&(iy+fheight-8>=mouseY)) {do_icon(i);break;} }else break; } return true; } public boolean mouseMove(Event e,int x,int y) { int tempY=0; mouseX=x; mouseY=y; repaint(); return true; } public void update(Graphics g){paint(g);} public boolean imageUpdate(Image img,int flags,int x,int y, int w,int h) { if((flags&SOMEBITS)!=0){repaint(x,y,w,h); } else if((flags&ABORT)!=0) {repaint();} return(flags&(ALLBITS|ABORT))==0; } public void paint(Graphics g) { Graphics screengc=null; screengc=g; g=buffer.getGraphics(); int i=0; String str; int y=0; int ix=0,iy=0,iex=0; d=size(); fheight= g.getFontMetrics().getHeight() + 8; if(wallpaper!=null) g.drawImage(wallpaper,0,0,d.width,d.height-8,this); g.setColor(Color.lightGray); g.fillRect(0,d.height-fheight,d.width,fheight+8); startbtnEX=g.getFontMetrics().stringWidth(startbtn)+20; g.fill3DRect(0,d.height-fheight,startbtnEX,fheight+8,!pop); if(startlogo!=null) g.drawImage(startlogo,0,d.height-fheight+2,16,fheight+8,this); if(!pop)g.setColor(Color.black);else g.setColor(Color.white); g.drawString(startbtn,17,d.height-3); if(iconCount>0) for(i=iconCount-1;i>=0;i--) { if(icons.elementAt(i)!=null) { g.setColor(Color.lightGray); iex= g.getFontMetrics().stringWidth((String) iconText.elementAt(i)); ix= Integer.parseInt((String) iconX.elementAt(i))- iex/2; iy= Integer.parseInt((String) iconY.elementAt(i))+iconWH; if((ix<=mouseX)&&(iy-iconWH<=mouseY) &&(ix+iex>=mouseX)&&(iy+fheight-8>=mouseY)) g.draw3DRect(ix-4,iy-iconWH-4,iex+8,iy+fheight,true); g.setColor(Color.black); g.fillRect( ix, iy+2, g.getFontMetrics().stringWidth((String) iconText.elementAt(i)), fheight-8 ); g.setColor(Color.white); g.drawString( (String) iconText.elementAt(i), ix, iy+fheight-8 ); g.drawImage( (Image)icons.elementAt(i), ix+iconWH/2, iy-iconWH, iconWH,iconWH,this ); } } if(pop&&(itemCount>0)) { y=d.height-fheight-8; menuEY=y; for(i=itemCount-1;i>=0;i--) { str=(String) items.elementAt(i); g.setColor(Color.lightGray); if((0<=mouseX)&&(y-fheight+8<=mouseY)&&(fwidth>=mouseX)&&(y+8>=mouseY)) g.fill3DRect(0,y-fheight+8,fwidth,fheight,false); else g.fill3DRect(0,y-fheight+8,fwidth,fheight,true); g.setColor(Color.black); g.drawString(str,5,y); y-=fheight; } menuY=y; } screengc.drawImage(buffer,0,0,null); } //menu handler public void do_menu(int i) { switch(i) { case 0: f=new msgbox("About RDesktop", "Created by: Raymond Anthony Samalo\n"+ "E-mail : eng60728@leonis.nus.edu.sg\n"+ "Made with : jdk 1.0,1998\n"+ "What is it: a Desktop like interface for\n"+ " website navigational purpose\n"+ "Parameters:\n"+ " msg is the message of the day\n"+ " img is the background image\n"+ " cmd is the menu button text\n"+ " logo is the menu button image\n\n"+ " menu1 .. menuN are the menu items\n"+ " link1 .. linkN are the URLs \n\n"+ " icon1 .. iconN are the icon image files\n"+ " ilink1 .. ilinkN are the URLs \n"+ " ix1 .. ixN are the x-center of icons\n"+ " iy1 .. iyN are the top-y of icons\n"+ " itext1 .. itextN are the icons' text\n\n"+ "Note :\n link can be started with pop: for making messagebox\n"+ " I will be trying to allow dragging icon or a cool Mac Desktop\n"+ "Super Note:\n this is a freeware but if you want to support me...\n"+ "BTW :\n THANK YOU FOR TRYING RDesktop \n" ); f.show(); break; default: do_link((String)hrefs.elementAt(i)); } } // icon handler public void do_icon(int i) { showStatus("Select icon"+i+" is "+iconText.elementAt(i)); do_link((String)iconLink.elementAt(i)); } // link executor public void do_link(String link) { if(link.startsWith("pop:")) { f=new msgbox("RDesktop message",link.substring(4)); f.show(); }else { try{getAppletContext().showDocument(new URL(link));} catch(MalformedURLException er) { f=new msgbox("RDesktop ERROR","PAGE NOT FOUND:\n"+link); f.show(); } } } // INIT() public void init() {int i=0; setBackground(Color.cyan); d=size(); buffer=createImage(d.width,d.height); if(getParameter("msg")!=null) {f=new msgbox("Message of the day..!",getParameter("msg"));f.show();} if(getParameter("img")!=null) wallpaper=getImage(getDocumentBase(),getParameter("img")); if(getParameter("logo")!=null) startlogo=getImage(getDocumentBase(),getParameter("logo")); if(getParameter("cmd")!=null) startbtn=getParameter("cmd"); addItem("(C)RDesktop","about"); for(i=1;getParameter("menu"+i)!=null;i++) addItem( getParameter("menu"+i), (getParameter("link"+i)!=null)?getParameter("link"+i):"none" ); for(i=1;getParameter("icon"+i)!=null;i++) addIcon( (getParameter("itext"+i)!=null)?getParameter("itext"+i):"", getImage(getDocumentBase(),getParameter("icon"+i)), (getParameter("ilink"+i)!=null)?getParameter("ilink"+i):"none", getParameter("ix"+i), getParameter("iy"+i) ); } } class msgbox extends Frame { msgbox(String title,String message) { super(title); setLayout(new BorderLayout()); add("Center",new TextArea(message)); add("So
评论
    相关推荐