⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mb.java

📁 一个简单的visio程序。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    int keycode = e.getKeyCode();
	    boolean saveValue = this.pressSpaceKey;
	    this.pressSpaceKey = false; // xiang rong 98 - 02 -20

	    if(keycode == KeyEvent.VK_ESCAPE && escflag)
		{
			if (okflag)
			   R.id = 1;
			else
			   R.id = 2;
			P.id = 1;
    	    this.dispose(); 
		}
    	else if (obj == ok && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 1;
			P.id = 1;
    	    this.dispose(); 
    	}
    	else if (obj == yes && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 6;
			P.id = 1;
    	    this.dispose(); 
    	}
    	else if (obj == no && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 7;
			P.id = 1;
    	    this.dispose(); 
    	}
    	else if (obj == cancel && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 2;
			P.id = 1;
    	    this.dispose(); 
    	}
    	else if (obj == abort && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 3;
			P.id = 1;
    	    this.dispose(); 
    	}
    	else if (obj == retry && keycode == KeyEvent.VK_SPACE && saveValue)
    	{
			R.id = 4;
			P.id = 1;
    	    this.dispose(); 
    	}
		else if (obj == ignore && keycode == KeyEvent.VK_SPACE && saveValue)
		{
    		R.id = 5;
			P.id = 1;
    	    this.dispose(); 
    	}
	}

   private void filldailog(String msg,int type)//change 4/18/97
	{
      setLayout(null);
		if ( type >= 80 && type < 256)
    	   type = 0;
    	else if(type >= 256 && type < 512)
    	{
    	   type = type % 256;
    	   second = true;
    	}
    	else if(type >= 512 )     //??? 4096
    	{
    	   type = type % 512;
    	   third = true;
    	}

    	if ( (type < 16 && type > 5) || type < 0)
    	    type = 0;
    	else if (type > 21 && type < 32)
    	    type = 0;
    	else if (type > 37 && type < 48)
    	    type = 0;
    	else if (type > 53 && type < 64)
    	    type = 0;
    	else if (type > 69 && type < 80)
    	    type = 0;

      int newtype = 0;
      /*try
      {
         webide.MainConsole applet = webide.MainConsole.getMainConsole();
		   if(applet!=null)
         {
            java.net.URL url = applet.getCodeBase();
            String imgRes = applet.getParameter("imagesource") + java.io.File.separator;
            if(type>=0 && type <6)
               newtype = type;
            else if(type >= 16 && type < 32){// add stop icon
               newtype = type % 16;
               url = new URL(url, imgRes + "stop.gif");
            }else if (type >= 32 && type < 48){// add ? icon "questionMark.gif"
               newtype = type % 32;
               url = new URL(url, imgRes + "question.gif");
            }else if (type >= 48 && type < 64){// add ! icon
               newtype = type % 48;
               url = new URL(url, imgRes + "exclaim.gif");
            }else if (type >= 64 && type < 80){// add i icon
               newtype = type % 64;
               url = new URL(url, imgRes + "hand.gif");
            }
            if (url != null)
               stop = applet.getImage(url);
         }
      }catch(Exception io){stop = null;}
		if (stop != null)
		{
			Imagelabel img = new Imagelabel(stop);
			add(img);
			img.setBounds(getInsets().left+9,getInsets().top+28,39,36);
		}	
		*/
      mtype = newtype;
      String tmp=msg;
      int chn=(int)'\n';
      int chr=(int)'\r';
      int i=0,j=0,k=1;
		Vector strVector = new Vector();
      while (tmp.indexOf(chn)!=-1 || tmp.indexOf(chr)!=-1)
      {
    	   i=tmp.indexOf(chn);
    	   j=tmp.indexOf(chr);
		   if (i!=-1 && j==-1){
			  strVector.addElement(tmp.substring(0,i));
			  tmp = tmp.substring(i+1);
    	   }else if (i==-1 && j!=-1){
			  strVector.addElement(tmp.substring(0,j));
    	      tmp = tmp.substring(j+1);
    	   }else if (i==j+1){
			  strVector.addElement(tmp.substring(0,j));
    	      tmp = tmp.substring(i+1);
    	   }else if (j==i+1){
			  strVector.addElement(tmp.substring(0,i));
    	      tmp = tmp.substring(j+1);
    	   }else if (j>i){
			  strVector.addElement(tmp.substring(0,i));
    	      tmp = tmp.substring(i+1);
    	   }else if (j<i){
			  strVector.addElement(tmp.substring(0,j));
    	      tmp = tmp.substring(j+1);
    	   }
      }
		if (tmp != null && !tmp.equals(""))
			strVector.addElement(tmp);
		Vector mv = new Vector();
		FontMetrics fm = getToolkit().getFontMetrics(new Font("Dialog", Font.PLAIN, 11));
		for(int z=0;z<strVector.size();z++)
		{
			String str = (String)strVector.elementAt(z);
			int strWidth = fm.stringWidth(str);
			if (strWidth > maxWidth) maxWidth = strWidth;
			if (strWidth > 330)
			{
				if (maxWidth > 330)	maxWidth = 330;
				StringTokenizer size = new StringTokenizer(str," ");
				StringBuffer s = new StringBuffer();
				while (size.hasMoreTokens()) {
					s.append(size.nextToken()+" ");
					strWidth = fm.stringWidth(s.toString());
					if (strWidth > 330)
					{
						if (strWidth > 380)
						{
							maxWidth = 380;
							String st=s.toString();
							StringBuffer b = new StringBuffer();
							for (int x=0;x<st.length();x++)
							{
								b.append(st.charAt(x));
								if (fm.stringWidth(b.toString()) >= 380)
								{
									mv.addElement(b.toString());
									int width = fm.stringWidth(b.toString());
									if (width > maxWidth)
										maxWidth = width;
									b = new StringBuffer();
								}
							}
							mv.addElement(b.toString());
						}else{
							mv.addElement(s.toString());
							int width = fm.stringWidth(s.toString());
							if (width > maxWidth)
								maxWidth = width;
						}
						s = new StringBuffer();
					}
				}
				mv.addElement(s.toString());
			}else 
				mv.addElement(str);
		}

		int titlewidth = fm.stringWidth(title);
		if (titlewidth > 330)
		{
			titlewidth = 330;
		} 
		if (maxWidth < titlewidth + 50)
			maxWidth = titlewidth + 50;

		if (maxWidth < 90) maxWidth = 90;
		if ((newtype == 3 || newtype == 2) && maxWidth < 150) maxWidth = 150;
	    setFont(new Font("Dialog", Font.PLAIN, 11));
        Label bord[] = new Label[mv.size()];

		for(k=0;k<mv.size();k++){
    	  bord[k] = new Label((String)mv.elementAt(k),0);
		  if (stop != null)
    		 bord[k].setBounds(getInsets().left+39+10,getInsets().top+43+k*16,maxWidth,15);
		  else bord[k].setBounds(getInsets().left+10,getInsets().top+43+k*16,maxWidth,15);
		  add(bord[k]);
		}
        add_button(newtype,k,second,third);
        setBackground(Color.lightGray);
        switch(newtype)
    	{
    	    case 0:
    	      ok.requestFocus();
    	      break;
    	    case 1:
    	      if (second)
    			cancel.requestFocus();
    	      else
    			ok.requestFocus();
    	      break;
    	    case 2:
    	      if (second)
    		 retry.requestFocus();
    	      else if (third)
    		 ignore.requestFocus();
    	      else
    		 abort.requestFocus();
    	      break;
    	    case 3:
    	      if (second)
    		 no.requestFocus();
    	      else if(third)
    		 cancel.requestFocus();
    	      else
    		 yes.requestFocus();
    	      break;
    	    case 4:
    	      if (second)
    		 no.requestFocus();
    	      else
    		 yes.requestFocus();
    	      break;
    	    case 5:
    	      if (second)
    		 cancel.requestFocus();
    	      else
    		 retry.requestFocus();
    	      break;
    	}
       setResizable(false);
	    Dimension size = getToolkit().getScreenSize();
	    Dimension dim = getSize();
	    setLocation(Math.max(0, (size.width - dim.width) / 2), Math.max(0, (size.height - dim.height) / 2));
   }

	private void add_button(int type,int k,boolean second,boolean third)
	{
    	switch(type)
    	{
    	    case 0:
    	      okflag = true;
    	      escflag = true;
    	      ok.addActionListener(this);
    	      ok.addKeyListener(this);
    	      add(ok);
			  if (stop == null){
				  ok.setBounds(getInsets().left+(maxWidth+20)/2-46/2,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  ok.setBounds(getInsets().left+(39+maxWidth+20)/2-46/2,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
			  break;
    	    case 1:
    	      ok.addActionListener(this);
    	      ok.addKeyListener(this);
    	      cancel.addActionListener(this);
    	      cancel.addKeyListener(this);
    	      escflag = true;
			  if (second){
    			add(cancel);
    			add(ok);
			  }else {
				add(ok);
				add(cancel);
			  }
			  if (stop == null){
				  ok.setBounds(getInsets().left+(maxWidth+28)/2-50,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(maxWidth+28)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+28,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  ok.setBounds(getInsets().left+(39+maxWidth+20)/2-50,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(39+maxWidth+20)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
    	      break;
    	    case 2:
    	      if (second){
				  add(retry);
				  add(abort);
				  add(ignore);
    	      }else if (third){
				  add(ignore);
				  add(abort);
				  add(retry);
    	      }else{
    			  add(abort);
    			  add(retry);
    			  add(ignore);
			  }
    	      abort.addActionListener(this);
    	      abort.addKeyListener(this);
    	      retry.addActionListener(this);
    	      retry.addKeyListener(this);
    	      ignore.addActionListener(this);
    	      ignore.addKeyListener(this);
			  if (stop == null){
				  abort.setBounds(getInsets().left+(maxWidth+20)/2-77,getInsets().top+43+k*16+12,46,25);
				  retry.setBounds(getInsets().left+(maxWidth+20)/2-23,getInsets().top+43+k*16+12,46,25);
				  ignore.setBounds(getInsets().left+(maxWidth+20)/2+31,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  abort.setBounds(getInsets().left+(39+maxWidth+20)/2-77,getInsets().top+43+k*16+12,46,25);
				  retry.setBounds(getInsets().left+(39+maxWidth+20)/2-23,getInsets().top+43+k*16+12,46,25);
				  ignore.setBounds(getInsets().left+(39+maxWidth+20)/2+31,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
    	      break;
    	    case 3:
    	      if (second){
    			  add(no);
    			  add(cancel);
				  add(yes);
    	      }else if(third){			  
				  add(cancel);
				  add(yes);
				  add(no);
    	      } else{
				  add(yes);
    			  add(no);
    			  add(cancel);
    	      }
    	      escflag = true;
    	      cancel.addActionListener(this);
    	      cancel.addKeyListener(this);
    	      yes.addActionListener(this);
    	      yes.addKeyListener(this);
    	      no.addActionListener(this);
    	      no.addKeyListener(this);
			  if (stop == null){
				  yes.setBounds(getInsets().left+(maxWidth+20)/2-77,getInsets().top+43+k*16+12,46,25);
				  no.setBounds(getInsets().left+(maxWidth+20)/2-23,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(maxWidth+20)/2+31,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  yes.setBounds(getInsets().left+(39+maxWidth+20)/2-77,getInsets().top+43+k*16+12,46,25);
				  no.setBounds(getInsets().left+(39+maxWidth+20)/2-23,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(39+maxWidth+20)/2+31,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
    	      break;
    	    case 4:
    	      if (second){
    			  add(no);
    			  add(yes);
			  }
    	      else{
    			  add(yes);
    			  add(no);
    	      }
			  yes.addActionListener(this);
    	      yes.addKeyListener(this);
    	      no.addActionListener(this);
    	      no.addKeyListener(this);
			  if (stop == null){
				  yes.setBounds(getInsets().left+(maxWidth+28)/2-50,getInsets().top+43+k*16+12,46,25);
				  no.setBounds(getInsets().left+(maxWidth+28)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+28,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  yes.setBounds(getInsets().left+(39+maxWidth+20)/2-50,getInsets().top+43+k*16+12,46,25);
				  no.setBounds(getInsets().left+(39+maxWidth+20)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
    	      break;
    	    case 5:
    	      if (second){
    			  add(cancel);
    			  add(retry);
			  }
    	      else {
    			  add(retry);
    			  add(cancel);
			  }
    	      escflag = true;
    	      cancel.addActionListener(this);
    	      cancel.addKeyListener(this);
    	      retry.addActionListener(this);
    	      retry.addKeyListener(this);
			  if (stop == null){
				  retry.setBounds(getInsets().left+(maxWidth+28)/2-50,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(maxWidth+28)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+maxWidth+28,getInsets().top+getInsets().bottom+90+k*16);
			  }else {
				  retry.setBounds(getInsets().left+(39+maxWidth+20)/2-50,getInsets().top+43+k*16+12,46,25);
				  cancel.setBounds(getInsets().left+(39+maxWidth+20)/2+4,getInsets().top+43+k*16+12,46,25);
				  setSize(getInsets().left+getInsets().right+39+maxWidth+20,getInsets().top+getInsets().bottom+90+k*16);
			  }
    	      break;
    	}
   }
}//end class msgbox

class Imagelabel extends Canvas{
	Image image;
	int w,h;
    public Imagelabel(Image image){
		this.image = image;
	}
	public void paint(Graphics g) {
        w = image.getWidth(this);
        h = image.getHeight(this);
        g.drawImage(image, 0, 0,w,h,this);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -