📄 right5_1_3.htm
字号:
<html><head><title>JAVA编程语言</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../../css/text.css" type="text/css"><script language="JavaScript"><!--function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features);}//--></script></head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td valign="top"> <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF"> <tr> <td valign="top"> <p> <span class="pt9-black"> </span><span class="zhongdian">1.Frame<a name="01"></a></span><span class="pt9-black"><br> <br> <img src="../../../images/tu/ch05/5_1_3_1.gif" width="357" height="148"><br> <br> 以下是容器的例子:<br> <br> <img src="../../../images/html/liti.gif" width="38" height="38" align="absbottom" title="例题"> <font color="000099">例5.1<a name="03"></a></font><br> import java.awt.*;<br> public class MyFrame extends Frame{<br> public static void main(String args[ ]){<br> MyFrame fr = new MyFrame("Hello Out There!"); <font color="330099"> <font color="339900"><br> //构造方法</font></font><br> fr.setSize(200,200); <font color="339900"><br> //设置Frame的大小,缺省为(0,0)</font><br> fr.setBackground(Color.red); <font color="339900"><br> //设置Frame的背景,缺省为红色</font><br> fr.setVisible(true); <font color="339900"><br> //设置Frame为可见,缺省为不可见</font><br> }<br> public MyFrame (String str){<br> super(str); <font color="339900">//调用父类的构造方法</font><br> }<br> }<br> <br> <a href="#03" onClick="MM_openBrWindow('tanchu1.htm','','width=153,height=153')"><font color="#FF0000">查看运行结果</font></a><br> <br> <font color="000099">一般我们要生成一个窗口,通常是用Window的子类Frame来进行实例化,而不是直接用到Window类。Frame的外观就像我们平常在windows系统下见到的窗口,有标题、边框、菜单、大小等等。每个Frame的对象实例化以后,都是没有大小和不可见的,因此必须调用setSize( )来设置大小,调用setVisible(true)来设置该窗口为可见的。<br> <br> 另外,AWT在实际的运行过程中是调用所在平台的图形系统,因此同样一段AWT程序在不同的操作系统平台下运行所看到的图形系统是不一样的。例如在windows下运行,则显示的窗口是windows风格的窗口;而在UNIX下运行时,则显示的是UNIX风格的窗口。</font><br> <br> </span><span class="zhongdian">2. Panel<a name="02"></a></span><span class="pt9-black"><br> <br> <img src="../../../images/tu/ch05/5_1_3_2.gif" width="247" height="116"><br> <br> <img src="../../../images/html/liti.gif" width="38" height="38" align="absbottom" title="例题"> <font color="000099">例5.2<a name="04"></a></font><br> import java.awt.*;<br> public class FrameWithPanel extends Frame{<br> public FrameWithPanel(String str){<br> super(str);<br> }<br> <br> public static void main(String args[]){<br> FrameWithPanel fr = new FrameWithPanel("Frame with Panel");<br> Panel pan=new Panel();<br> fr.setSize(200,200);<br> fr.setBackground(Color.red); <font color="339900"><br> //框架fr的背景颜色设置为红色</font><br> fr.setLayout(null); <font color="339900"><br> //取消布局管理器</font><br> pan.setSize(100,100);<br> pan.setBackground(Color.yellow); <font color="339900"><br> //设置面板pan的背景颜色为黄色</font><br> fr.add(pan); <font color="339900">//用add方法把面板pan添加到框架fr中</font><br> fr.setVisible(true);<br> }<br> }<br> <br> <a href="#04" onClick="MM_openBrWindow('tanchu2.htm','','width=241,height=241')"><font color="#FF0000">查看运行结果</font></a><br> <br> <font color="000099">一般我们要生成一个窗口,通常是用Window的子类Frame来进行实例化,而不是直接用到Window类。Frame的外观就像我们平常在windows系统下见到的窗口,有标题、边框、菜单、大小等等。每个Frame的对象实例化以后,都是没有大小和不可见的,因此必须调用setSize( )来设置大小,调用setVisible(true)来设置该窗口为可见的。<br> <br> 另外,AWT在实际的运行过程中是调用所在平台的图形系统,因此同样一段AWT程序在不同的操作系统平台下运行所看到的图形系统是不一样的。例如在windows下运行,则显示的窗口是windows风格的窗口;而在UNIX下运行时,则显示的是UNIX风格的窗口。</font><br> <br> <br> <br> </span></p> </td> </tr> </table> </td> </tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -