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

📄 小生杂谈--java中mdi的实现.htm

📁 行业分类数据库管理系统
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      <TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" cellSpacing=1 
      cellPadding=3 width="98%" bgColor=#cccccc border=0>
        <TBODY>
        <TR bgColor=#f8f8f8>
          <TD>
            <P><FONT size=4><STRONG><IMG src="小生杂谈--Java中MDI的实现.files/1.gif"><A 
            href="http://blogger.org.cn/blog/blog.asp?name=wonderow&amp;subjectid=150">[编程技术]<A 
            href="http://blogger.org.cn/blog/more.asp?name=wonderow&amp;id=972">Java中MDI的实现</A></STRONG></FONT><BR><A 
            class=categorylink 
            href="http://blogger.org.cn/blog/list.asp?classid=36" 
            target=_blank>原创空间</A>,&nbsp;&nbsp;<A class=categorylink 
            href="http://blogger.org.cn/blog/list.asp?classid=14" 
            target=_blank>软件技术</A></P>
            <P><A href="http://blogger.org.cn/blog/blog.asp?name=wonderow" 
            target=_blank>Wonderow</A> 发表于 2004-12-14 22:46:46 </P></TD></TR>
        <TR bgColor=#ffffff>
          <TD height=0>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD>MDI,Multiple Document Interface(多文档界面)与SDI相对,应用也很广泛。像Word 
                  XP以前的版本都是用MDI(之后的版本应该也算MDI,但形式有些不同,看起来像SDI),VS/VS.Net等很多软件也都是MDI,其方便显而易见,即可以在一个窗体中的有限空间里提供多个文档同时编辑使用的功能。<BR><BR>  一般的编程语言都会提供显著的MDI功能,但Java似乎不那么明显,问了一些经常使用Java的同学居然一时也没说上来如何实现。于是借助网络的强大力量,我们知道了在Swing中提供了JDesktopPane和JInternalFrame,结合使用即可实现MDI的效果。<BR><BR>  代码是简单的,先在主窗体(可是以一个JFrame)中加入一个JDesktopPane,为MDI“提供活动的空间”:<BR>
                  <DIV 
                  style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
                  <DIV><A href="小生杂谈--Java中MDI的实现.files/None.gif" 
                  target=_blank><IMG onmousewheel="return bbimg(this)" 
                  title=点击在新窗口查看原始图片 src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A><SPAN 
                  style="COLOR: #000000">JDesktopPane&nbsp;desktop&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">new</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;JDesktopPane&nbsp;();<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A></SPAN><SPAN 
                  style="COLOR: #000000">??</SPAN><SPAN 
                  style="COLOR: #000000">.add(desktop);</SPAN></DIV></DIV>  这里的??可以是任意的Container,这一点Java就显得很自由,很灵活,可以在很多地方创建这样的一个DesktopPane。<BR>  当然,如果想这个Pane在需要时可以滚动,可以使用常用的技巧,把它加入一个JScrollPane,这里比较特殊,需要重载它的preferredSizeOfAllFrames函数才能获得正确的尺寸,才有正确的滚动效果: 

                  <DIV 
                  style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
                  <DIV><A href="小生杂谈--Java中MDI的实现.files/None.gif" 
                  target=_blank><IMG onmousewheel="return bbimg(this)" 
                  title=点击在新窗口查看原始图片 src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A><SPAN 
                  style="COLOR: #000000">public&nbsp;class&nbsp;JDesktop&nbsp;extends&nbsp;JDesktopPane<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>{<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">void</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;paint(Graphics&nbsp;g)<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;{<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.paint(g);<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dimension&nbsp;d&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;preferredSizeOfAllFrames();<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">this</SPAN><SPAN 
                  style="COLOR: #000000">.setPreferredSize(d);<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">this</SPAN><SPAN 
                  style="COLOR: #000000">.revalidate();<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A><BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A><BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #008000">/*</SPAN><SPAN 
                  style="COLOR: #008000">*<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;返回最佳desktop尺寸..<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #008000">*/</SPAN><SPAN 
                  style="COLOR: #000000"><BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Dimension&nbsp;preferredSizeOfAllFrames()<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;{<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JInternalFrame&nbsp;[]&nbsp;array&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;getAllFrames();<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top border=0></A><BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">int</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;maxX&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">0</SPAN><SPAN 
                  style="COLOR: #000000">;<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">int</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;maxY&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">0</SPAN><SPAN 
                  style="COLOR: #000000">;<BR><A 
                  href="小生杂谈--Java中MDI的实现.files/None.gif" target=_blank><IMG 
                  onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 
                  src="小生杂谈--Java中MDI的实现.files/None.gif" 
                  onload="java_script_:if(this.width>500)this.width=500" 
                  align=top 
                  border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
                  style="COLOR: #0000ff">for</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
                  style="COLOR: #0000ff">int</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN 
                  style="COLOR: #000000">=</SPAN><SPAN 
                  style="COLOR: #000000">&nbsp;</SPAN><SPAN 

⌨️ 快捷键说明

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