西科人BBS_西安科技大学学生论坛

 找回密码
 立即注册
楼主: 幽忧

我不喜欢灌水

[复制链接]
发表于 2006-4-9 16:13:34 | 显示全部楼层
你灌的最厉害
 楼主| 发表于 2006-4-9 16:13:42 | 显示全部楼层
引用第4楼呵呵★蓝夜2006-04-09 16:11发表的“”:
前 言


   前 言

    掌握如何安装、配置和调试计算机网络是市场需求量很高和令人兴奋的技能。本书覆盖的知识面很广,从网络评估到局域网、广域网、协议、拓扑结构、传输介质和安全的讨论都有所涉及。本书不仅介绍了大量的概念,而且还给出诸如TCP/IP协议组等连网中最重要方面的深入全面的练习。除解释概念之外,每章还包含数个与专业人员所关心的连网有关的现实中的例子,这使本书成为网络实践学习工具。

    本书各章节会讨论如下主题:

    第1章、第2章和第3章简单介绍网络基础知识,包括网络标准组织、OSI模型和网络协议。

    第4章在前几章的基础上继续讲解在局域网中所使用的各种逻辑和物理结构。

    第5章和第6章讨论网络中的物理部分,包括线路、网络接口卡、集线器、路由器、网桥和交换机。在第6章,你会看到几幅典型网络设备的照片。

    第7章扩展局域网有关知识,讨论广域网拓扑结构和传输方法。

    第8章、第9章,以及第10章介绍最流行的网络操作系统:Windows NT、NetWare和UNIX。

    第11章详细讨论TCP/IP协议组中的组件和使用方法,以及当前的网络中所使用的最流行协议。

    第12章和第13章从逻辑和实践的角度提出解决网络中疑难问题和维护网络的各项任务。一旦你了解网络的工作原理,以及建立网络的方法,则有必要知道如何修补和维护网络。

    第14章和第15章讨论在面对诸如电源失效、硬件或软件故障以及安全攻击等突发事件时如何保持网络的安全。在第15章你还会学习如何实现企业级的安全策略。

    第16章通过介绍网络项目的实现过程,以综合运用所学的网络知识。本章还包含规划中有关技术问题的有益提示。

    本书最后的三个附录可作为网络专业人员参考之用。附录A是大量的与组网有关的软件和硬件资源。附录B通过提供一组典型网络专业人员所用的工具,以扩展所学到的网络硬件知识。附录C给出规划、安装和解决网络疑难问题时会使用的表格范例。

    读者对象

    本书可以满足那些想掌握广泛的且与供应商无关的网络概念的专业人士需要。本书的内容和其教学性特点提供给你一个真正交互的学习过程,为面对千变万化的网络工业的挑战打下良好的基础。除本书提供的基本内容之外,每章还包含实践项目,带领你一步步地完成各种任务。每章还包含一个学习案例,在案例中你将作为问题解决者,要求运用在本章中所学的知识,完满地解决问题。

    本书特点

    为帮助你完全领会网络概念,本书还具有许多有助于提高学习经验的特点。

    ?章节目标。每章首先详细列出本章中应该掌握的概念要领。通读要领列表,你能快速浏览本章中所要介绍的内容,也会是一种很有用处的学习帮助。

    ?插图和表格。本书给出了有关服务器界面和组件的大量插图,相信会有助于形象化理解安装步骤、理论和概念。而且,本书中所含的许多表格提供实践和理论知识的详细讲解,并给出有关比较。

    ?实践项目。尽管理解网络技术背后的原理很重要,但无助于提高实践动手能力。为提高读者的动手能力,本书在理论讲解的同时,每章还提供大量的实践项目,以期增加实际工作经历。

    ?章节小结。每章后面都总结本章中所介绍的概念。概念小结有助于读者重新温习本章中所学的内容。

    ?复习题。章节后面提供一组复习题,可以帮助读者进一步加深理解本章中所学的内容。回答这些问题将确保你完全掌握所学的重要概念。

    ?实例项目。每章最后一部分是几个实例项目。借助这些练习,通过实际设计和实现过程,可以运用从本章中所获得的知识和技能。




[关闭此窗口]
发表于 2006-4-9 16:13:42 | 显示全部楼层
引用第4楼呵呵★蓝夜2006-04-09 16:11发表的“”:
[s:22]  [s:22]  [s:22]  [s:22]  [s:22]
引用+表情!
发表于 2006-4-9 16:14:20 | 显示全部楼层
引用第10楼ぁ简单爱ぁ2006-04-09 16:13发表的“”:
你灌的最厉害
同意!
 楼主| 发表于 2006-4-9 16:15:01 | 显示全部楼层
引用第12楼咖啡巧克力2006-04-09 16:13发表的“”:

[s:22]  [s:22]  [s:22]  [s:22]  [s:22]
引用+表情!
<HTML>
<HEAD>
<title>俄罗斯方块</title>
<style>
<!--
BODY
{
}
.MB
{
   BACKGROUND-COLOR: firebrick;
   CURSOR: default;
   HEIGHT: 22px;
   WIDTH: 22px
}
.SB
{
   BACKGROUND-COLOR: slategray;
   CURSOR: default;
   HEIGHT: 22px;
   WIDTH: 22px
}
.BK
{
   BACKGROUND-COLOR: white;
   CURSOR: default;
   HEIGHT: 22px;
   WIDTH: 22px
}
.GT
{
   BORDER-BOTTOM: deepskyblue thin solid;
   BORDER-LEFT: deepskyblue thin solid;
   BORDER-RIGHT: deepskyblue thin solid;
   BORDER-TOP: deepskyblue thin solid;
   CURSOR: default
}
-->
</style>
<script>
<!--
var BX=new Array(4);
var BY=new Array(4);
var PX=new Array(4);
var PY=new Array(4);
var mTimer
var firstView

function beginGame()
{
   gameState=0;
   speed=1;
   outTime=1100-speed*100;
   score=0;
   if(gameState!=0)return;
   firstView=true;
   for(j=0;j<16;j++)
      for(i=0;i<10;i++)
        setClass(i,j,"BK");
   randBar();
   gameState=1;
   Play.disabled=true;
   window.clearInterval(mTimer);
   mTimer=window.setInterval("moveBar()",outTime);
}

function keyControl()
{
   if(gameState!=1)return;
   switch(event.keyCode){
      case 37:{   //left
        for(i=0;i<4;i++)if(BX==0)return;
        for(i=0;i<4;i++)if(getClass(BX-1,BY)=="SB")return;
        for(i=0;i<4;i++)setClass(BX,BY,"BK");
        for(i=0;i<4;i++)BX=BX-1;
        for(i=0;i<4;i++)setClass(BX,BY,"MB");
        break;}
      case 38:{   //up
        var preMBarX=new Array(4);
        var preMBarY=new Array(4);
        var cx=Math.round((BX[0]+BX[1]+BX[2]+BX[3])/4);
        var cy=Math.round((BY[0]+BY[1]+BY[2]+BY[3])/4);
        for(i=0;i<4;i++){
           preMBarX=Math.round(cx-cy+BY);
           preMBarY=Math.round(cx+cy-BX);
           if(preMBarX<0 || preMBarX>9 || preMBarY<0 || preMBarY>15)return;
           if(getClass(preMBarX,preMBarY)=="SB")return;
        }
        for(i=0;i<4;i++)setClass(BX,BY,"BK");
        for(i=0;i<4;i++){
           BX=preMBarX;
           BY=preMBarY;
        }
        for(i=0;i<4;i++)setClass(BX,BY,"MB");
        break;}
      case 39:{   //right
        for(i=0;i<4;i++)if(BX==9)return;
        for(i=0;i<4;i++)if(getClass(BX+1,BY)=="SB")return;
        for(i=0;i<4;i++)setClass(BX,BY,"BK");
        for(i=0;i<4;i++)BX=BX+1;
        for(i=0;i<4;i++)setClass(BX,BY,"MB");
        break;}
      case 40:{   //down
        moveBar();
        break;}
   }
}

function delLine()
{
   for(i=0;i<4;i++)setClass(BX,BY,"SB");
   for(j=0;j<16;j++){
      dLine=true;
      for(i=0;i<9;i++){
        if(getClass(i,j)!="SB"){
           dLine=false;
           break;
        }
      }
      if(dLine){
        score=score+100;
        for(k=j;k>0;k--)
           for(l=0;l<10;l++)
              setClass(l,k,getClass(l,k-1));
        for(l=0;l<10;l++)setClass(l,0,"BK");
      }
   }
   randBar();
   speed=Math.floor(score/3000)+1;
   outTime=1100-speed*100;
   scoreBar.innerHTML="Score : " + score;
   speedBar.innerHTML="Speed : " + speed;
   window.clearInterval(mTimer);
   mTimer=window.setInterval("moveBar()",outTime);
}

function getClass(x,y){return GameBar.children[y].children[x].className;}
function setClass(x,y,cName){GameBar.children[y].children[x].className=cName;}

function moveBar()
{
   if(gameState!=1)return;
   dropLine=true;
   for(i=0;i<4;i++)if(BY==15)dropLine=false;
   if(dropLine)for(i=0;i<4;i++)if(getClass(BX,BY+1)=="SB")dropLine=false;
   if(!dropLine){
      window.clearInterval(mTimer);
      delLine();
      return;
   }
   for(i=0;i<4;i++)setClass(BX,BY,"BK");
   for(i=0;i<4;i++)BY=BY+1;
   for(i=0;i<4;i++)setClass(BX,BY,"MB");
}

function pauseGame()
{
   if(gameState==0)return;
   if(event.srcElement.value=="Pause"){
      gameState=2;
      event.srcElement.value="Continue";
      window.clearInterval(mTimer);
   }
   else{
      gameState=1;
      event.srcElement.value="Pause";
      mTimer=window.setInterval("moveBar()",outTime);
   }
}

function fMnu(){return false;}
document.oncontextmenu=fMnu;

function preview()
{
   if(previewBar.style.display!="none")
      previewBar.style.display="none";
   else
      previewBar.style.display="block";
}

function replayGame()
{
   if(gameState!=1)return;
   if(!confirm("真的要重新开始?"))return;
   gameState=0;
   window.clearInterval(mTimer);
   beginGame();
}
function randBar()
{
   randNum=Math.floor(Math.random()*20)+1;
   if(!firstView)
      for(i=0;i<4;i++){
        BX=PX;
        BY=PY;
      }
   switch(randNum){
      case 1:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=4;
        PY[1]=1;
        PX[2]=5;
        PY[2]=1;
        PX[3]=6;
        PY[3]=1;
        break;}
      case 2:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=4;
        PY[2]=1;
        PX[3]=4;
        PY[3]=2;
        break;}
      case 3:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=6;
        PY[2]=0;
        PX[3]=6;
        PY[3]=1;
        break;}
      case 4:{
        PX[0]=5;
        PY[0]=0;
        PX[1]=5;
        PY[1]=1;
        PX[2]=5;
        PY[2]=2;
        PX[3]=4;
        PY[3]=2;
        break;}
      case 5:{
        PX[0]=6;
        PY[0]=0;
        PX[1]=6;
        PY[1]=1;
        PX[2]=4;
        PY[2]=1;
        PX[3]=5;
        PY[3]=1;
        break;}
      case 6:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=4;
        PY[1]=1;
        PX[2]=4;
        PY[2]=2;
        PX[3]=5;
        PY[3]=2;
        break;}
      case 7:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=4;
        PY[1]=1;
        PX[2]=5;
        PY[2]=0;
        PX[3]=6;
        PY[3]=0;
        break;}
      case 8:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=5;
        PY[2]=1;
        PX[3]=5;
        PY[3]=2;
        break;}
      case 9:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=5;
        PY[2]=1;
        PX[3]=6;
        PY[3]=1;
        break;}
      case 10:{
        PX[0]=5;
        PY[0]=0;
        PX[1]=5;
        PY[1]=1;
        PX[2]=4;
        PY[2]=1;
        PX[3]=4;
        PY[3]=2;
        break;}
      case 11:{
        PX[0]=4;
        PY[0]=1;
        PX[1]=5;
        PY[1]=1;
        PX[2]=5;
        PY[2]=0;
        PX[3]=6;
        PY[3]=0;
        break;}
      case 12:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=4;
        PY[1]=1;
        PX[2]=5;
        PY[2]=1;
        PX[3]=5;
        PY[3]=2;
        break;}
      case 13:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=6;
        PY[2]=0;
        PX[3]=5;
        PY[3]=1;
        break;}
      case 14:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=4;
        PY[1]=1;
        PX[2]=4;
        PY[2]=2;
        PX[3]=5;
        PY[3]=1;
        break;}
      case 15:{
        PX[0]=5;
        PY[0]=0;
        PX[1]=5;
        PY[1]=1;
        PX[2]=4;
        PY[2]=1;
        PX[3]=6;
        PY[3]=1;
        break;}
      case 16:{
        PX[0]=5;
        PY[0]=0;
        PX[1]=5;
        PY[1]=1;
        PX[2]=5;
        PY[2]=2;
        PX[3]=4;
        PY[3]=1;
        break;}
      case 17:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=4;
        PY[2]=1;
        PX[3]=5;
        PY[3]=1;
        break;}
      case 18:{
        PX[0]=4;
        PY[0]=0;
        PX[1]=5;
        PY[1]=0;
        PX[2]=4;
        PY[2]=1;
        PX[3]=5;
        PY[3]=1;
        break;}
      case 19:{
        PX[0]=3;
        PY[0]=0;
        PX[1]=4;
        PY[1]=0;
        PX[2]=5;
        PY[2]=0;
        PX[3]=6;
        PY[3]=0;
        break;}
      case 20:{
        PX[0]=5;
        PY[0]=0;
        PX[1]=5;
        PY[1]=1;
        PX[2]=5;
        PY[2]=2;
        PX[3]=5;
        PY[3]=3;
        break;}
   }
   if(firstView){
      firstView=false;
      randBar();
      return;
   }
   for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        previewBar.children[j].children.className="BK";
      }
   }
   for(i=0;i<4;i++)previewBar.children[PY].children[PX-3].className="MB";
   for(i=0;i<4;i++){
      if(getClass(BX,BY)!="BK"){
        alert("Game Over!");
        window.clearInterval(mTimer);
        Play.disabled=false;
        gameState=0;
        return;
      }
   }
   for(i=0;i<4;i++)setClass(BX,BY,"MB");
}
// -->
</script>
</HEAD>
<BODY bgcolor=Black onkeydown="return keyControl();">
<center>
<P><b><font color=red>俄罗斯方块</font></b></P>
<table cellspacing=0 cellpadding=0 class=gt border=1 bordercolor="LightYellow " style="position:absolute;left:220px;top:53px;">
<Tbody id=GameBar>
<tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK>
</td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr>
</tbody>
</table>
</center>
<table style="position:absolute;top=100px;left:50px">
   <tr><td id=scoreBar style="color:white">Score : 0</td></tr>
   <tr><td id=speedBar style="color:white">Speed : 1</td></tr>
</table>

<table cellspacing=0 cellpadding=0 class=gt border=1 bordercolor="LightYellow " style="position:absolute;left:570px;top:53px;">
<Tbody id=previewBar>
<tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr><tr><td class=BK> </td><td class=BK> </td><td class=BK> </td><td class=BK> </td></tr>
</tbody>
</table>
<table style="position:absolute;left:570px;top:180px;">
   <tr><td><input type=button id="Play" style="width:100px" value="Play" onclick="return beginGame();"></td></tr>
   <tr><td><input type=button id="Pause" style="width:100px" value="Pause" onclick="return pauseGame();"></td></tr>
   <tr><td><input type=button id="Preview" style="width:100px" value="Preview" onclick="preview();"></td></tr>
   <tr><td><input type=button id="Replay" style="width:100px" value="Replay" onclick="replayGame();"></td></tr>
   <tr><td><input type=button id="Quit" style="width:100px" value="Quit" onclick="window.close();"></td></tr>
</table>
< div style="position:absolute;left:590px;top:390px;color:white;font-size:9pt"> 如有问题联系我<a href="mailto:sor@263.net"><font color=white>联系< /font></a></div>
</BODY>
</HTML>
<script>
function unSel()
{
   document.execCommand("Unselect");
   window.setTimeout("unSel()",10);
}
unSel();

window.onunload=rel;
function rel()
{
   location.reload();
   return false;
}

</script>
 楼主| 发表于 2006-4-9 16:15:27 | 显示全部楼层
# import java.awt.*;
# import java.awt.event.*;
# import java.text.*;
# import javax.swing.*;
# import javax.swing.event.*;
# import javax.swing.text.*;
#
# public class Calculator implements ActionListener,KeyListener
# {
#    private double number;
#    private String operator = "";
#    private boolean pointenable = true,inputcomplete = false,resultdisplayed = false;
#    private DecimalFormat gs = new DecimalFormat("0.#############");
#    private JPanel backpanel,textpanel,buttonpanel;
#    String[] string = {"sqrt","+/-","CE","C","7","8","9","÷","4","5","6","x","1","2","3","-","0",".","=","+"};
#    JFrame frm = new JFrame("Calculate");
#    private NumericTextField textfield;
#   
#    public class NumericDocument extends PlainDocument//define a class to cortrol 16 numbers could be cin in
#    {
#      protected int maxDigits = -1;
#      protected Toolkit toolkit = Toolkit.getDefaultToolkit();
#      public NumericDocument(int digits)
#      {
#         super();
#         maxDigits = digits;
#      }
#      public NumericDocument()
#      {
#         this(-1);
#      }
#
#      public void insertString(int offset,String text,AttributeSet attributes) throws BadLocationException
#      {
#         int count = text.length();
#         if(count > 15)
#         {
#            toolkit.beep();
#            JOptionPane.showMessageDialog(frm,"Over the length of textfield!","Error",JOptionPane.ERROR_MESSAGE);   
#            return;
#         }
#         super.insertString(offset,text,attributes);
#         
#      }
#    }
#   
#    public class NumericTextField extends JTextField
#    {
#      public NumericTextField(String text,int columns)
#      {
#         super(text,columns);
#      }
#      protected Document createDefaultModel()
#      {
#         return new NumericDocument(getColumns());
#      }
#    }//end
#   
#
#    public Calculator()
#    {  
#   
#      frm.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
#      textpanel = new JPanel();
#      textfield = new NumericTextField("0",28);
#      textfield.setHorizontalAlignment(textfield.RIGHT);
#      textfield.setFont(new Font("隶书",1,16));
#      textfield.addKeyListener(this);
#      textfield.setBackground(new Color(255,255,255));
#      textfield.setEditable(false);
#      textpanel.add(textfield);
#      buttonpanel=new JPanel();
#      buttonpanel.setLayout(new GridLayout(5,4,2,2));
#   
#      for(int i=0;i<20;i++)//add button to the buttonpanel
#      {
#         JButton   button=new JButton(string);
#         button.addActionListener(this);
#         buttonpanel.add(button);
#      }//end
#   
#      backpanel=new JPanel();
#      backpanel.setLayout(new BorderLayout());
#      backpanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
#      backpanel.add(textfield,BorderLayout.NORTH);
#      backpanel.add(buttonpanel,BorderLayout.CENTER);
#      frm.getContentPane().add(backpanel);
#      frm.pack();
#      frm.setResizable(false);
#      frm.setVisible(true);
#      frm.setLocation(400,300);
#    }
#   
#    public void ifresultdisplayed()// if result is not dispalyed ,display the result
#    {
#      if(!resultdisplayed)
#         {
#            displayResult();
#            resultdisplayed = true;
#         }
#    }// end
#   
#    public void keyPressed(KeyEvent e)
#    {      
#    }
#   
#    public void keyReleased(KeyEvent e)
#    {
#    switch(e.getKeyChar())
#    {
#       case &#39;+&#39;://press +
#       {
#          ifresultdisplayed();//if the result is not displayed display the result
#         doOperation("+");//set the operator +
#         break;
#       }
#       case &#39;-&#39;://press -
#       {
#          ifresultdisplayed();//if the result is not displayed display the result
#          doOperation("-");//set the operator -
#          break;
#       }
#       case &#39;*&#39;://press *
#       {
#          ifresultdisplayed();//if the result is not displayed display the result
#          doOperation("*");//set the operator *
#          break;
#       }
#       case &#39;/&#39;://press *
#       {
#          ifresultdisplayed();//if the result is not displayed display the result
#          doOperation("÷");//set the operator /
#       }
#    }   
#   
#    if(e.getKeyCode() == 10) displayResult();
#      else if(e.getKeyChar() >= &#39;0&#39; && e.getKeyChar() <= &#39;9&#39; || e.getKeyChar() == &#39;.&#39;)//display the number
#      {
#         numberInput(""+e.getKeyChar());//get char from keyboard
#      }
#    }
#   
#    public void keyTyped(KeyEvent e)
#    {
#    }
#   
#    public void doOperation(final String s)
#    {
#      textfield.setText(gs.format(Double.parseDouble(textfield.getText())));
#      if(!(textfield.getText().equals("")))
#      {
#         number = Double.parseDouble(textfield.getText());//convert the string to double
#         operator = s;//set operator s
#         inputcomplete = true;//textinput has complete
#      }
#    }
#   
#    public void displayResult()//display the result
#    {
#      if(operator.equals("+"))
#        textfield.setText(gs.format((number + Double.parseDouble(textfield.getText()))));//do operation +
#      else if(operator.equals("-"))   
#        textfield.setText(gs.format((number - Double.parseDouble(textfield.getText()))));//do operation -
#      else if(operator.equals("x"))
#        textfield.setText(gs.format((number * Double.parseDouble(textfield.getText()))));//do operation *
#      else if(operator.equals("÷"))
#      {
#         if(textfield.getText().equals("0"))//if the divisor id 0 showerrormessage
#           JOptionPane.showMessageDialog(frm,"Divisor can&#39;t be 0","Error",JOptionPane.ERROR_MESSAGE);
#         else
#         textfield.setText(gs.format((number / Double.parseDouble(textfield.getText()))));
#      }
#      number = 0;
#      inputcomplete = true;
#      resultdisplayed = true;// result has been diplayed
#    }// end
#   
#    public void numberInput(String s)// input the number
#    {
#      if(textfield.getText().equals("0"))//if the text is 0 ,can&#39;t input 0
#      {                       
#         if(!(s.equals("0")))
#         {
#            if(s.equals("."))// if input is a point,can&#39;t input a dot until the pointenable become true again
#            {
#              textfield.setText(textfield.getText()+".");
#              pointenable = false;
#            }
#              
#            else     
#              textfield.setText(s);// set the text s
#         }      
#      }
#      else if(s.equals("."))// if input is a dot
#      {
#         if(!inputcomplete && pointenable)// while inputcomplete is false and pointenable is true
#         {
#            textfield.setText(textfield.getText() + ".");// add a point to the text
#            pointenable = false;// set pointenable false
#         }
#      }                     
#      else if(inputcomplete)// if inputcomplete is true
#      {
#         inputcomplete = false;// set inputcomplete false
#         resultdisplayed = false;// set inputcomplete false
#         pointenable = true;// set pointenable true
#         textfield.setText(s);// set the text s
#      }
#      else
#      textfield.setText(textfield.getText() + s);// add s to the textfield
#    }
#   
#    public void actionPerformed(ActionEvent e)
#    {
#      if(e.getActionCommand().equals("+"))
#      {
#         ifresultdisplayed();
#         doOperation("+");// dooperation
#      }
#      
#      else if(e.getActionCommand().equals("-"))
#      {
#         ifresultdisplayed();
#         doOperation("-");// dooperation
#      }
#      
#      else if(e.getActionCommand().equals("x"))
#      {
#         ifresultdisplayed();
#         doOperation("x");// dooperation
#      }
#      
#      else if(e.getActionCommand().equals("÷"))
#      {
#         ifresultdisplayed();
#         doOperation("÷");// dooperation
#      }
#      
#      else if(e.getActionCommand().equals("+/-"))// convert the number to negative or positive
#      {
#         if(!(textfield.getText().equals("0")))// except 0
#         {
#            textfield.setText(gs.format(-Double.parseDouble(textfield.getText())));
#         }
#      }
#      else if(e.getActionCommand().equals("sqrt"))// do evolution
#      {
#         textfield.setText(gs.format(Double.parseDouble(textfield.getText())));
#         double s = Double.parseDouble(textfield.getText());
#         if(s >= 0)
#         textfield.setText(gs.format(Math.sqrt(Double.parseDouble(textfield.getText()))));
#         else// if the number is negative showerrormessage
#         JOptionPane.showMessageDialog(frm,"Please enter the right number!","Error",JOptionPane.ERROR_MESSAGE);
#         inputcomplete = true;
#      }
#      else if(e.getActionCommand().equals("CE"))
#      {
#         textfield.setText("0");
#      }//set text 0
#      else if(e.getActionCommand().equals("C"))
#      {
#         number = 0;operator = "";
#         inputcomplete = false;
#          pointenable = true;
#         textfield.setText("0");
#      }
#      else if(e.getActionCommand().equals("="))
#      displayResult();//displayresult
#      else
#      numberInput(e.getActionCommand());
#    }
#   
#    public static void main(String[] args)
#    {
#      Calculator obj = new Calculator();
发表于 2006-4-9 16:15:33 | 显示全部楼层
引用第11楼幽忧2006-04-09 16:13发表的“”:

前 言


   前 言
.......
[s:36]  [s:36]  [s:36]  [s:36]  [s:36]
西
 楼主| 发表于 2006-4-9 16:15:45 | 显示全部楼层
Thinking in Java 读书笔记

决定开始啃这本大部头的Java宝典,边啃边做点笔记吧.废话少说!



第四章 初始化和清除(Initialization&CleanUp)



主要章节内容:

4.1 构建器

4.2 方法过载

4.3 收尾和垃圾收集

4.4 成员初始化



关键词:Constructor,finalize(),初始化顺序



重点整理:



1.构造函数

要点:

构建器(Constructor)属于一种较特殊的方法类型,因为它没有返回值.这与void返回值存在着明显的区别。对于void返回值,尽管方法本身不会自动返回什么,但仍然可以让它返回另一些东西。构建器则不同,它不仅什么也不会自动返回,而且根本不能有任何选择.若创建一个没有构件器的类,则编译器会自动创建一个默认构件器.



2.finalize()和gc()



(1)问题:finalize()函数是干嘛的?Java不是有Garbage Collection(以下简称gc)来负责回收内存吗?

回答:

gc只能清除在堆上分配的内存(纯java语言的所有对象都在堆上使用new分配内存),而不能清除栈上分配的内存(当使用JNI技术时,可能会在栈上分配内存,例如java调用c程序,而该c程序使用malloc分配内存时).因此,如果某些对象被分配了栈上的内存区域,那gc就管不着了,对这样的对象进行内存回收就要靠finalize().

举个例子来说,当java 调用非java方法时(这种方法可能是c或是c++的),在非java代码内部也许调用了c的malloc()函数来分配内存,而且除非调用那个了free() 否则不会释放内存(因为free()是c的函数),这个时候要进行释放内存的工作,gc是不起作用的,因而需要在finalize()内部的一个固有方法调用它(free()).

finalize的工作原理应该是这样的:一旦垃圾收集器准备好释放对象占用的存储空间,它首先调用finalize(),而且只有在下一次垃圾收集过程中,才会真正回收对象的内存.所以如果使用finalize(),就可以在垃圾收集期间进行一些重要的清除或清扫工作.



(2)问题:finalize()在什么时候被调用?

回答:



有三种情况



1.所有对象被Garbage Collection时自动调用,比如运行System.gc()的时候.

2.程序退出时为每个对象调用一次finalize方法。

3.显式的调用finalize方法



除此以外,正常情况下,当某个对象被系统收集为无用信息的时候,finalize()将被自动调用,但是jvm不保证finalize()一定被调用,也就是说,finalize()的调用是不确定的,这也就是为什么sun不提倡使用finalize()的原因.





3. this

要点:

this关键字只能在方法中使用,它能为调用该方法的对象提供相应的句柄,使得同一个类产生的不同对象实例在调用同一方法的时候,系统能判断出是哪一个对象在进行调用.

比如:

MyObject a=new MyObject();

MyObject b=new MyObject();

a.f();// (3)

b.f();// (4)

编译器在编译的时候,实际上是将(3),(4)句解释为

MyObject.f(a);

MyObject.f(b);

的,这样就将调用了该方法的对象的信息传到了方法中,也就是传给了this,就可以通过this表示调用该方法的对象实例.



用this的概念还可以解释为什么在静态方法中不能调用非静态方法和元素,这是因为静态方法中没有this,也就是说我们不能获得调用该方法的对象的句柄.既然找不到这个对象实例,我们又怎么能够在其中调用对象实例的方法和元素呢?



那为什么静态方法没有this呢?用静态方法的概念可以来理解这个问题.静态方法是类方法,是所有对象实例公用的方法.它不属于某一个具体的对象实例,因此也无法用this来体现这个实例.这和非静态方法是不一样的.打个比方,在一个局域网内的几个用户每个人都有一台客户机,但都访问一台公共的服务器.对于每台客户机来说,它的this就是使用它的用户.而对于服务器来说,它没有this,因为它是大家公用的,不针对某一个具体的客户.



4.对象初始化

要点:

1.对象只有在创建的时候,需要使用它的时候才进行初始化,否则永远都不会初始化.

2.对象进行初始化是有一定顺序的,无论在定义的时候各个成员的摆放位置如何.首先是静态成员和对象,然后是非静态成员和对象,最后才运行构造器.

3.静态成员和对象有且只有一次初始化过程,这个过程发生在第一次创建对象或者第一次使用类的静态成员和对象的时候.



以一个名为Dog的类为例,它的对象实例初始化过程如下:

(1) 类型为Dog的一个对象首次创建时,或者Dog类的static方法/static字段首次访问时,Java解释器必须找到Dog.class(在事先设好的类路径里搜索)。

(2) 找到Dog.class后,它的所有static初始化模块都会运行。因此,static初始化仅发生一次——在Class对象首次载入的时候。

(3) 创建一个new Dog()时,Dog对象的构建进程首先会在内存堆(Heap)里为一个Dog对象分配足够多的存储空间。

(4) 这种存储空间会清为零,将Dog中的所有基本类型设为它们的默认值

(5) 进行字段定义时发生的所有初始化都会执行。

(6) 执行构建器。正如第6章将要讲到的那样,这实际可能要求进行相当多的操作,特别是在涉及继承的时候



5.数组的初始化

数组包括基本数据类型数组和对象数组,其中对于对象数组的初始化,经常会出现"Exception"错误.比如下面的程序



问题代码如下:

public userInfo[] getUsersInfo() {



userInfo[] usersInfo=null;



if (users.size()!=0) {

usersInfo=new userInfo[users.size()];



for(int i=0;i< usersInfo.length;i++) {

//+-------------------出问题的地方-----------------

usersInfo.name=((User)(users.elementAt(i))).name;

usersInfo.type=((User)(users.elementAt(i))).type;

usersInfo.userID=((User)(users.elementAt(i))).userID;

//+-------------------出问题的地方-----------------

}

System.out.println("here");

return usersInfo;

}else {

return null;

}

}



其中userInfo的定义为

class userInfo{

userInfo(String name,int type,int userID){

this.name=name;

this.type=type;

this.userID=userID;

}

String name;

int type;

int userID;

}



运行到程序中标出的问题区域时,系统显示NullPointerException,为什么会这样呢?



这是因为,Java在定义数组的时候

usersInfo=new userInfo[users.size()];

并没有给数组元素分配内存,它只是一个句柄数组,数组中的对象还没有初始化.因此数组中的每个对象都需要new之后才可以访问.例如:

A[] a=new A[2];

for(int i=0;i<2;i++)

a = new A();

这样才能a.someMethod()



因此上面的程序应该改为



public userInfo[] getUsersInfo() {



userInfo[] usersInfo=null;



if (users.size()!=0) {

usersInfo=new userInfo[users.size()];



for(int i=0;i< usersInfo.length;i++) {

//+-------------------修改的地方-----------------

usersInfo=new userInfo(((User)(users.elementAt(i))).name,

((User)(users.elementAt(i))).type,

((User)(users.elementAt(i))).userID);

}

//+-------------------修改的地方-----------------

return usersInfo;

}else {

return null;

}

}

就没问题了
发表于 2006-4-9 16:16:30 | 显示全部楼层
引用第15楼幽忧2006-04-09 16:15发表的“”:
# import java.awt.*;
# import java.awt.event.*;
# import java.text.*;
# import javax.swing.*;
# import javax.swing.event.*;
.......




西
 楼主| 发表于 2006-4-9 16:16:46 | 显示全部楼层
引用第16楼呵呵★蓝夜2006-04-09 16:15发表的“”:

[s:36]  [s:36]  [s:36]  [s:36]  [s:36]
西
满满看
坐在秋千上

哈密的晚上一直是那样的星光灿烂,让你感觉不到悲伤,可我为什么属于悲伤,眼前的幸福真的那么远——题记

坐在秋千上

手抓紧 头抬起 笑了 为何 因为她甜甜的睡了 我知道
我呢
呼吸着微热的空气 看见天上的银河 看见星星笑的好美
路上无人 路灯在亮 空空的仿佛世界死去了

坐在秋千上

麻木 心乱了
又是一个难眠的夜
星我相望 等天亮
月挂在我的头上 笑了 她说:她不要下来 让我等
笑了 我点头 月笑了 好甜 好美
空气有了一丝凉凉的感觉 缠绕在心痛上

坐在秋千上

晚上天也好蓝
却有了一片一片的粉色
好美
秋千在荡 摇啊摇啊
我可以睡吗..
醒了过后 我会在那 我会干吗.....

我在等....
生命的一半都在等中过....

坐在秋千上

荡到天亮 回家睡 因为我知道我醒来要干吗....不在怕忘记..
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西科人BBS ( 粤ICP备20049523号-3 )

GMT+8, 2026-4-16 17:00 , Processed in 0.056995 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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