发新话题
打印

【原创】我的Java学习笔记

【原创】我的Java学习笔记

五一放假了,在家里呆着也是呆着,没有人找我出去,呵呵,想想也没有给论坛什么有用的东东,于是试着写这个Java学习笔记,希望大家支持,有什么错误请指出来,我会将我学习Java的步骤基本写出来,呵呵.
希望我可以坚持到底,谢谢!      
夜黑漆漆, 有水的村庄 鸟叫不停, 浅沙下荸荠 那果实在地下长大象哑子叫门 鱼群悄悄潜行如同在一个做梦少女怀中 那时刻有位母亲昙花一现 鸟叫不定, 仿佛村子如一颗小鸟的嘴唇 鸟叫不定而小鸟没有嘴唇 你是夜晚的一部分 谁是黑夜的母亲 那夜晚在门前长大象哑子叫门 鸟叫不定象小鸟奉献给黑夜的嘴唇 在门外黑夜的嘴唇 写下了你的姓名

TOP

我的Java学习笔记

第一天:
我为什么要学习Java?
有时我也想我为什么会去学习Java.其实很简单,现在在我的编程中越来越多的接触到Java,无论在任何平台,或者硬件设备,你不得不承认Java确实铸得很出色.但一直让人们但心的是Java的效率问题,现在也得到了很好的改善,加以Java许多人性化的机制,我开始喜欢它,现在我来和大家一起学习Java.

了解Java:
1991年Sun公司有一个叫做Green的项目,这全项目的工程师授命设计一种小型计算机语言用于家电控制芯片等设备.由于这些设备的硬件制约,这种语言要尽量的小,而且能生成相当紧凑的代码,最重要的是可以适用于各种各样的芯片.这种语言有着强大的生命力,不受限于任何一种体系结构.为了实现这一个目标,于是产生了Java的前身.
Java要实现它的可移殖性,就要借助于一个在运行前的"中间码",这种"中间码"可以在特定的解释器上执行,而那个解释器也并不是很大,于是可以达到移殖性的目标.
Java原名叫做Oak,但后来改成了这个吸引人的"Java",如果你想知道的话可以查一下相关资料.
Java是一个完全面向对象的语言,慢慢地,Java开始向网络转移,Green项目组用Java写了一个HotJava的浏览器以便可以或好的阅读WEB页面.一直到1995年5月召开的SunWorld大会上这个试验品首次亮相,Java从此诞生.
想了解更多的内容请查阅相关资料.

Java的特点:
其最大的优势是与平台无关的"一次编写,处处运行"的可移殖性,再就是在网络上的运用.Java是面向对象的,很好的借鉴了C++的特性,所以你可以认为它是C++的发展,如果你愿意的话.Java提供了自动内存管理,取消指针和多重继承等等.
这里只是简单的介绍一下,其它内容还要你自己去学习.下面我们开始Java有一些实际内容.

什么是面向对象?
你可以了解:类,关于封装,继承以及消息传送一些基本内容.它的优点在于共享代码,提高了软件的复用性.

安装JDK(Java Develop Kit)
JDK是Sun公司提供的一个免费的软件开以工具包,包含了我们学习Java的必需工具:Java基本组件,库,Java编译器,Java解释器,小应用程序浏览器,以及一些程序.你可以从网络等途径获得它.然后参考相关资料根据你的系统配制Java的环境.去了解javac,javap,javah,javadoc及AppletViewer的内容.然后找一个JavaIDE或Java集成开发的工具.

测试Java环境,一个经典程序HelloWorld:
编写一个文件名为HelloWorld.java的程序,内容如下:
public class HelloWorld
{
        public static void main(String args[])
        {
                System.out.print("Hello World !");
        }
}
然后编译运行:
#javac HelloWorld.java
#java HelloWorld
你会看到它的输出.      

TOP

今天写得比较少,呵呵

第二天:
Java的数据类型与变量:
与其它编程语言想差不多,Java的原始数据类型(Primitive Data Type)分为布尔型(boolean),字节(Byte),字符(Char),16位整数类型(short),整数(int),长整型(long),浮点类型(float),双浮点类型(double),字符串类型(String).我主要讲一下Char和String两个类型.Java为了支持多国的语言,所以Char方面采用Unicode字符集来处理,所以必需使用16位的空间存储一个字符.String是否属于原始数据类型方面的说法有些争议,它可以很轻松的存储整个字符串,而所使用的数据空间也是随着字符串长度不同而改变,没有什么固定的空间.
什么是变量,变量如何声明,以及变量的使用希望大家自己学习,在这里我不再赘述.

Java运算符:
由于Java取消了指针,所以获得指针内存地址的运算符"*"便没有了(千万别和乘号搞乱),同时还取消了"&"取得变量内存地址运算符及"->"指针存取对象内容数据成员运算符,最后也没有获得容量大小的"sizeof"运算符(想着那时刚学编程还以为这是一个关键字).
再就是要看一看各种移位运算符:"<<",">>",">>>"等,虽然我很不喜欢用.      

TOP

【讨论】我的程序调不出来 帮一下啊 谢谢

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;


public class Wuziqi extends Applet
{
Qipan qipan;
    int ct[][];//分别存放黑(0)白(1)的四个方向的连子数目,据此判断胜负及长连
                //0横1竖2左斜3右斜
public void init()
{       ct=new int[2][4];
  qipan=new Qipan();
  setLayout(new BorderLayout());
  setLayout(qipan.getSize());
  add(qipan,"Center");
}

public int getWidth()
{
  return qipan.getWidth();
}

public int getHeight()
{
  return qipan.getHeight();
}

public static void main(String[] args)
{
  Frame f=new Frame("wuziqi");  
  f.setResizable(false);  
  f.setLayout(new BorderLayout());


  f.addWindowListener(new WindowAdapter(){
     public void windowClosing(WindowEvent e)
   {
    Frame frm=(Frame)(e.getSource());
    frm.dispose();
    System.exit(0);
   }
    }
  );


  //f.addWindowListener(new util.DefaultWindowListener(f) );  
  
  Wuziqi wuziqi=new Wuziqi();  
  wuziqi.init();
  wuziqi.start();
   
  f.setSize(wuziqi.getWidth(),20+wuziqi.getHeight());  
  f.add(wuziqi,"Center");  
  f.setVisible(true);
  //util.Util.center(f);
}
}



/*
class closeWin extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
  Frame frm=(Frame)(e.getSource());
  frm.dispose();
  System.exit(0);
}
}
*/

//import dbuffer.*;
//**********************************************************
class Qipan extends Panel
{
public static final int _rectlen=22,_rectnum=19;
//默认的方格长度及数目
//*****************************************************
protected Vector qizis;   //保存所有已下的棋子,包括在棋盘上的所有棋子和被提掉的
                                  //若某一次落子没有造成提子,则Vector qizis中保存的就是这个
//棋子
                                  //若某一次落子造成了提子,则Vector qizis中保存的就是一个
//Vector,
                                  //这个Vector中包括所有被这个棋子提掉的棋子及这个棋子本身,
                                  //这个棋子本身位于这个Vector的最后

protected int num;       //已下数目
protected int currentTurn;            //轮到谁下  Qizi._black Or Qizi._white

protected int rectnum,rectlen;       //方格长度及数目
protected int qizilen;      //棋子的直径
protected Qizi[][] map;  //在棋盘上的所有棋子
//**********************************
protected Image offscreen;   //双缓冲用的Image,Graphics
protected Graphics offg;
//**********************************
protected int size;          //棋盘的宽度及高度

protected int top,left;  //棋盘左边及上边的边距
//****************************************
protected Point mouseLoc; //鼠标的位置,即在map数组中的下标
//****************************************
protected ControlPanel controlPanel;  //控制面板
//******************************************************
public int getWidth()
{  
  return size+controlPanel.getWidth()+35;
}

public int getHeight()
{
  return size;
}
//******************************************************
public Qipan()
{
  top=left=20;
  rectnum=_rectnum;
  rectlen=_rectlen;  
  qizilen=rectlen*9/10;
  
  size=2*left+rectnum*rectlen;  
  //****************************************
  addMouseListener(new ML());
  addMouseMotionListener(new MML());   
  //****************************************
  setLayout(new BorderLayout() );
  controlPanel=new ControlPanel();

  setSize(getWidth(),size);
  add(controlPanel,"East");
  
  start();
}

public void addNotify()
{
  super.addNotify();
  offscreen=createImage(size,size);
  offg=offscreen.getGraphics();
}

public void paint(Graphics g)
{
  offg.setColor(new Color(180,150,100) );
  offg.fillRect(0,0,size,size);
  //*********************划出棋盘格子***************************
  offg.setColor(Color.black);
  for(int i=0;i<rectnum+1;i++)
  {
   int x1=left+i*rectlen;
   int x2=x1;
   
   int y1=top;
   int y2=top+rectnum*rectlen;
   offg.drawLine(x1,y1,x2,y2);
   //*************************************
   x1=left;
   x2=left+rectnum*rectlen;
   
   y1=top+i*rectlen;
   y2=y1;
   offg.drawLine(x1,y1,x2,y2);
  }
  //*****************************划出棋子********************************
  for(int i=0;i<rectnum+1;i++)
   for(int j=0;j<rectnum+1;j++)
   {
    if(map[j]==null)
     continue;
         
     
offg.setColor(map[j].color==Qizi._black?Color.black:Color.white);
     
offg.fillOval(left+i*rectlen-qizilen/2,top+j*rectlen-qizilen/2,
          qizilen,qizilen);
   }
  //*************************划出鼠标的位置,即下一步将要下的位置
//****************
  if(mouseLoc!=null)
  {
   offg.setColor(currentTurn==Qizi._black?Color.gray:
            
   new Color(200,200,250) );
   offg.fillOval(left+mouseLoc.x*rectlen-qizilen/2,
        top+mouseLoc.y*rectlen-qizilen/2,
        qizilen,qizilen);
  }
  //*******************把画面一次性画出**************************
  g.drawImage(offscreen,0,0,this);
}

public void update(Graphics g)
{
  paint(g);
}   
//*********************************************************************
class ML extends MouseAdapter
{   //放一颗棋子
  public void mousePressed(MouseEvent evt)
  {
   int xoff=left/2;
   int yoff=top/2;
   int x=(evt.getX()-xoff)/rectlen;
   int y=(evt.getY()-yoff)/rectlen;
   if(x<0 || x>rectnum || y<0 || y>rectnum)
    return;
   
   if(map[x][y]!=null)
    return;
   
   Qizi qizi=new Qizi(x,y,currentTurn);   
   
   map[x][y]=qizi;   
   //************************************
   qizis.addElement(qizi);   
   num++;
   if(currentTurn==Qizi._black)
    currentTurn=Qizi._white;
   else
    currentTurn=Qizi._black;   
   
            //更新控制面板
   controlPanel.setLabel();
  }
  
  public void mouseExited(MouseEvent evt)
  {//鼠标退出时,清除将要落子的位置
   mouseLoc=null;
   repaint();
  }
}

private class MML extends MouseMotionAdapter
    {//取得将要落子的位置
  public void mouseMoved(MouseEvent evt)
  {
   int xoff=left/2;
   int yoff=top/2;
   int x=(evt.getX()-xoff)/rectlen;
   int y=(evt.getY()-yoff)/rectlen;
   if(x<0 || x>rectnum || y<0 || y>rectnum)
    return;
   
   if(map[x][y]!=null)
    return;
   
   mouseLoc=new Point(x,y);
   repaint();  
  }
}
  

//方法mouseDownp2p结束
  
//*************************悔棋*************************
public void back()
{
  if(num==0)
  {
   controlPanel.setMsg("无子可悔");
   return;
  }
   
  Object obj=qizis.elementAt(--num);
  if(obj instanceof Qizi)
  {
   Qizi qizi=(Qizi)obj;
   map[qizi.x][qizi.y]=null;
   
   currentTurn=qizi.color;
  }else
  {   
   Vector v=(Vector)obj;
   for(int i=0;i<v.size();i++)
   {
    Qizi q=(Qizi)(v.elementAt(i) );
    if(i==v.size()-1)
    {
     map[q.x][q.y]=null;
     
     int index=qizis.indexOf(v);
     qizis.setElementAt(q,index);
     currentTurn=q.color;      
     
    }else
    {
     map[q.x][q.y]=q;
    }
   }   
  }
  controlPanel.setLabel();
  repaint();
}
//*********************前进**************************
public void forward()
{
  if(num==qizis.size())
  {
   controlPanel.setMsg("不能前进");
   return;
  }
     
  Object obj=qizis.elementAt(num++);
  
  Qizi qizi;
  if(obj instanceof Qizi)
  {
   qizi=(Qizi)(obj);
   map[qizi.x][qizi.y]=qizi;
  }else
  {
   Vector v=(Vector)obj;
   qizi=(Qizi)(v.elementAt(v.size()-1) );
   
   map[qizi.x][qizi.y]=qizi;
  }
  
  if(qizi.color==Qizi._black)
   currentTurn=Qizi._white;
  else
   currentTurn=Qizi._black;
   
            
  controlPanel.setLabel();
   
  repaint();
}
//******************重新开始游戏*************************
public void start()
{
  qizis=new Vector();
  num=0;
  map=new Qizi[rectnum+1][rectnum+1];
  
  currentTurn=Qizi._black;
  controlPanel.setLabel();
  repaint();
}
//*****************控制面板类************************************
class ControlPanel extends Panel
{
protected Label  lblTurn=new Label("",Label.CENTER);
protected Label  lblNum=new Label("",Label.CENTER);
protected Label  lblMsg=new Label("",Label.CENTER);

protected Choice choice=new Choice();
protected Button back=new Button("〈〈 悔 棋 ");
protected Button forward=new Button(" 前 进 〉〉");
protected Button start=new Button("重新开始");
//*****************************************************
public int getWidth()
{
  return 45;
}

public int getHeight()
{
  return size;
}
//*****************************************************
public ControlPanel()
{  
  setSize(this.getWidth(),this.getHeight());
   
  setLayout(new GridLayout(12,1,0,10));
  setLabel();
  
  
  choice.add("15 X 15");
  choice.add("13 X 13");
  choice.add("11 X 11");
  choice.add(" 7 X 7 ");
  choice.addItemListener(new IL());
  
  add(lblTurn);
  add(lblNum);
  
  add(start);
  add(choice);
  
  add(lblMsg);   
  add(back);
  add(forward);      
  
  back.addActionListener(new AL());
  forward.addActionListener(new AL());
  start.addActionListener(new AL());
  
  setBackground(new Color(120,120,200));      
  
}

public Insets getInsets()
{
  return new Insets(5,5,5,5);
}

private class AL implements ActionListener
{
  public void actionPerformed(ActionEvent evt)
  {
   if(evt.getSource()==back)
    Qipan.this.back();
   else if(evt.getSource()==forward)
    Qipan.this.forward();
   else if(evt.getSource()==start)
    Qipan.this.start();
  }
}      

private class IL implements ItemListener
{
  public void itemStateChanged(ItemEvent evt)
  {
   String s=(String)(evt.getItem());   
   
   int rects=Integer.parseInt(s.substring(0,2).trim() );
   
   if(rects!=Qipan.this.rectnum)
   {
    Qipan.this.rectlen=(_rectlen*_rectnum)/rects;
    Qipan.this.qizilen=rectlen*9/10;   
   
    Qipan.this.rectnum=rects;
    Qipan.this.start();
   }
  }
}

public void setLabel()
{  
  lblTurn.setText(Qipan.this.currentTurn==Qizi._black?"黑 方":"白 方 ");
   
lblTurn.setForeground(Qipan.this.currentTurn==Qizi._black?Color.black:Color.white);
  
  lblNum.setText("第 "+(Qipan.this.num+1)+" 手");
   
lblNum.setForeground(Qipan.this.currentTurn==Qizi._black?Color.black:Color.white);
  
  lblMsg.setText("");
}

public void setMsg(String msg)
{
  lblMsg.setText(msg);
}
}

}
public void judge( )
        {for(int i=0,j=0 ;ct[j]<4;j++)
          for(; ;i++)
         if(ct[j]=4
              lblMsg.setText("黑棋胜");
            else
       lblMsg.setText("白棋胜");
         }
class Qizi
{
public static int _black=0,_white=1;

protected int x,y;
protected int color;

public Qizi(int i,int j,int c)
{
  x=i;
  y=j;
  color=c;
}

public String toString()
{
  String c=(color==_black?"black":"white");
  return "["+x+","+y+"]:"+c;
}
}

class Point
{
int x,y;
public Point(int x,int y)
{
  this.x=x;
  this.y=y;
}
}
      

TOP

调一下这个程序 谢谢了

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

public class Wuziqi extends Applet
{
Qipan qipan;
    int ct[][];//分别存放黑(0)白(1)的四个方向的连子数目,据此判断胜负及长连
                //0横1竖2左斜3右斜
public void init()
{       ct=new int[2][4];
  qipan=new Qipan();
  setLayout(new BorderLayout());
  setLayout(qipan.getSize());
  add(qipan,"Center");
}

public int getWidth()
{
  return qipan.getWidth();
}

public int getHeight()
{
  return qipan.getHeight();
}

public static void main(String[] args)
{
  Frame f=new Frame("wuziqi");  
  f.setResizable(false);  
  f.setLayout(new BorderLayout());

  f.addWindowListener(new WindowAdapter(){
     public void windowClosing(WindowEvent e)
   {
    Frame frm=(Frame)(e.getSource());
    frm.dispose();
    System.exit(0);
   }
    }
  );

  //f.addWindowListener(new util.DefaultWindowListener(f) );  
  
  Wuziqi wuziqi=new Wuziqi();  
  wuziqi.init();
  wuziqi.start();
   
  f.setSize(wuziqi.getWidth(),20+wuziqi.getHeight());  
  f.add(wuziqi,"Center");  
  f.setVisible(true);
  //util.Util.center(f);
}
}


/*
class closeWin extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
  Frame frm=(Frame)(e.getSource());
  frm.dispose();
  System.exit(0);
}
}
*/

//import dbuffer.*;
//**********************************************************
class Qipan extends Panel
{
public static final int _rectlen=22,_rectnum=19;
//默认的方格长度及数目
//*****************************************************
protected Vector qizis;   //保存所有已下的棋子,包括在棋盘上的所有棋子和被提掉的
                                  //若某一次落子没有造成提子,则Vector qizis中保存的就是这个
//棋子
                                  //若某一次落子造成了提子,则Vector qizis中保存的就是一个
//Vector,
                                  //这个Vector中包括所有被这个棋子提掉的棋子及这个棋子本身,
                                  //这个棋子本身位于这个Vector的最后

protected int num;       //已下数目
protected int currentTurn;            //轮到谁下  Qizi._black Or Qizi._white

protected int rectnum,rectlen;       //方格长度及数目
protected int qizilen;      //棋子的直径
protected Qizi[][] map;  //在棋盘上的所有棋子
//**********************************
protected Image offscreen;   //双缓冲用的Image,Graphics
protected Graphics offg;
//**********************************
protected int size;          //棋盘的宽度及高度

protected int top,left;  //棋盘左边及上边的边距
//****************************************
protected Point mouseLoc; //鼠标的位置,即在map数组中的下标
//****************************************
protected ControlPanel controlPanel;  //控制面板
//******************************************************
public int getWidth()
{  
  return size+controlPanel.getWidth()+35;
}

public int getHeight()
{
  return size;
}
//******************************************************
public Qipan()
{
  top=left=20;
  rectnum=_rectnum;
  rectlen=_rectlen;  
  qizilen=rectlen*9/10;
  
  size=2*left+rectnum*rectlen;  
  //****************************************
  addMouseListener(new ML());
  addMouseMotionListener(new MML());   
  //****************************************
  setLayout(new BorderLayout() );
  controlPanel=new ControlPanel();

  setSize(getWidth(),size);
  add(controlPanel,"East");
  
  start();
}

public void addNotify()
{
  super.addNotify();
  offscreen=createImage(size,size);
  offg=offscreen.getGraphics();
}

public void paint(Graphics g)
{
  offg.setColor(new Color(180,150,100) );
  offg.fillRect(0,0,size,size);
  //*********************划出棋盘格子***************************
  offg.setColor(Color.black);
  for(int i=0;i<rectnum+1;i++)
  {
   int x1=left+i*rectlen;
   int x2=x1;
   
   int y1=top;
   int y2=top+rectnum*rectlen;
   offg.drawLine(x1,y1,x2,y2);
   //*************************************
   x1=left;
   x2=left+rectnum*rectlen;
   
   y1=top+i*rectlen;
   y2=y1;
   offg.drawLine(x1,y1,x2,y2);
  }
  //*****************************划出棋子********************************
  for(int i=0;i<rectnum+1;i++)
   for(int j=0;j<rectnum+1;j++)
   {
    if(map[j]==null)
     continue;
         
     
offg.setColor(map[j].color==Qizi._black?Color.black:Color.white);
     
offg.fillOval(left+i*rectlen-qizilen/2,top+j*rectlen-qizilen/2,
          qizilen,qizilen);
   }
  //*************************划出鼠标的位置,即下一步将要下的位置
//****************
  if(mouseLoc!=null)
  {
   offg.setColor(currentTurn==Qizi._black?Color.gray:
            
   new Color(200,200,250) );
   offg.fillOval(left+mouseLoc.x*rectlen-qizilen/2,
        top+mouseLoc.y*rectlen-qizilen/2,
        qizilen,qizilen);
  }
  //*******************把画面一次性画出**************************
  g.drawImage(offscreen,0,0,this);
}

public void update(Graphics g)
{
  paint(g);
}   
//*********************************************************************
class ML extends MouseAdapter
{   //放一颗棋子
  public void mousePressed(MouseEvent evt)
  {
   int xoff=left/2;
   int yoff=top/2;
   int x=(evt.getX()-xoff)/rectlen;
   int y=(evt.getY()-yoff)/rectlen;
   if(x<0 || x>rectnum || y<0 || y>rectnum)
    return;
   
   if(map[x][y]!=null)
    return;
   
   Qizi qizi=new Qizi(x,y,currentTurn);   
   
   map[x][y]=qizi;   
   //************************************
   qizis.addElement(qizi);   
   num++;
   if(currentTurn==Qizi._black)
    currentTurn=Qizi._white;
   else
    currentTurn=Qizi._black;   
   
            //更新控制面板
   controlPanel.setLabel();
  }
  
  public void mouseExited(MouseEvent evt)
  {//鼠标退出时,清除将要落子的位置
   mouseLoc=null;
   repaint();
  }
}

private class MML extends MouseMotionAdapter
    {//取得将要落子的位置
  public void mouseMoved(MouseEvent evt)
  {
   int xoff=left/2;
   int yoff=top/2;
   int x=(evt.getX()-xoff)/rectlen;
   int y=(evt.getY()-yoff)/rectlen;
   if(x<0 || x>rectnum || y<0 || y>rectnum)
    return;
   
   if(map[x][y]!=null)
    return;
   
   mouseLoc=new Point(x,y);
   repaint();  
  }
}
  

//方法mouseDownp2p结束
  
//*************************悔棋*************************
public void back()
{
  if(num==0)
  {
   controlPanel.setMsg("无子可悔");
   return;
  }
   
  Object obj=qizis.elementAt(--num);
  if(obj instanceof Qizi)
  {
   Qizi qizi=(Qizi)obj;
   map[qizi.x][qizi.y]=null;
   
   currentTurn=qizi.color;
  }else
  {   
   Vector v=(Vector)obj;
   for(int i=0;i<v.size();i++)
   {
    Qizi q=(Qizi)(v.elementAt(i) );
    if(i==v.size()-1)
    {
     map[q.x][q.y]=null;
     
     int index=qizis.indexOf(v);
     qizis.setElementAt(q,index);
     currentTurn=q.color;      
     
    }else
    {
     map[q.x][q.y]=q;
    }
   }   
  }
  controlPanel.setLabel();
  repaint();
}
//*********************前进**************************
public void forward()
{
  if(num==qizis.size())
  {
   controlPanel.setMsg("不能前进");
   return;
  }
     
  Object obj=qizis.elementAt(num++);
  
  Qizi qizi;
  if(obj instanceof Qizi)
  {
   qizi=(Qizi)(obj);
   map[qizi.x][qizi.y]=qizi;
  }else
  {
   Vector v=(Vector)obj;
   qizi=(Qizi)(v.elementAt(v.size()-1) );
   
   map[qizi.x][qizi.y]=qizi;
  }
  
  if(qizi.color==Qizi._black)
   currentTurn=Qizi._white;
  else
   currentTurn=Qizi._black;
   
            
  controlPanel.setLabel();
   
  repaint();
}
//******************重新开始游戏*************************
public void start()
{
  qizis=new Vector();
  num=0;
  map=new Qizi[rectnum+1][rectnum+1];
  
  currentTurn=Qizi._black;
  controlPanel.setLabel();
  repaint();
}
//*****************控制面板类************************************
class ControlPanel extends Panel
{
protected Label  lblTurn=new Label("",Label.CENTER);
protected Label  lblNum=new Label("",Label.CENTER);
protected Label  lblMsg=new Label("",Label.CENTER);

protected Choice choice=new Choice();
protected Button back=new Button("〈〈 悔 棋 ");
protected Button forward=new Button(" 前 进 〉〉");
protected Button start=new Button("重新开始");
//*****************************************************
public int getWidth()
{
  return 45;
}

public int getHeight()
{
  return size;
}
//*****************************************************
public ControlPanel()
{  
  setSize(this.getWidth(),this.getHeight());
   
  setLayout(new GridLayout(12,1,0,10));
  setLabel();
  
  
  choice.add("15 X 15");
  choice.add("13 X 13");
  choice.add("11 X 11");
  choice.add(" 7 X 7 ");
  choice.addItemListener(new IL());
  
  add(lblTurn);
  add(lblNum);
  
  add(start);
  add(choice);
  
  add(lblMsg);   
  add(back);
  add(forward);      
  
  back.addActionListener(new AL());
  forward.addActionListener(new AL());
  start.addActionListener(new AL());
  
  setBackground(new Color(120,120,200));      
  
}

public Insets getInsets()
{
  return new Insets(5,5,5,5);
}

private class AL implements ActionListener
{
  public void actionPerformed(ActionEvent evt)
  {
   if(evt.getSource()==back)
    Qipan.this.back();
   else if(evt.getSource()==forward)
    Qipan.this.forward();
   else if(evt.getSource()==start)
    Qipan.this.start();
  }
}      

private class IL implements ItemListener
{
  public void itemStateChanged(ItemEvent evt)
  {
   String s=(String)(evt.getItem());   
   
   int rects=Integer.parseInt(s.substring(0,2).trim() );
   
   if(rects!=Qipan.this.rectnum)
   {
    Qipan.this.rectlen=(_rectlen*_rectnum)/rects;
    Qipan.this.qizilen=rectlen*9/10;   
   
    Qipan.this.rectnum=rects;
    Qipan.this.start();
   }
  }
}

public void setLabel()
{  
  lblTurn.setText(Qipan.this.currentTurn==Qizi._black?"黑 方":"白 方 ");
   
lblTurn.setForeground(Qipan.this.currentTurn==Qizi._black?Color.black:Color.white);
  
  lblNum.setText("第 "+(Qipan.this.num+1)+" 手");
   
lblNum.setForeground(Qipan.this.currentTurn==Qizi._black?Color.black:Color.white);
  
  lblMsg.setText("");
}

public void setMsg(String msg)
{
  lblMsg.setText(msg);
}
}

}
public void judge( )
        {for(int i=0,j=0 ;ct[j]<4;j++)
          for(; ;i++)
         if(ct[j]=4
              lblMsg.setText("黑棋胜");
            else
       lblMsg.setText("白棋胜");
         }
class Qizi
{
public static int _black=0,_white=1;

protected int x,y;
protected int color;

public Qizi(int i,int j,int c)
{
  x=i;
  y=j;
  color=c;
}

public String toString()
{
  String c=(color==_black?"black":"white");
  return "["+x+","+y+"]:"+c;
}
}

class Point
{
int x,y;
public Point(int x,int y)
{
  this.x=x;
  this.y=y;
}
}      

TOP

这是一个application,我平时都是写jsp多      

TOP

似乎还是没有坚持下去啊。      
[IMG]http://3gobbs.rpwt.org/UploadFile/2005-2/200521101633247.jpg[/IMG]

TOP

我想学jsp,我学过php,没用多少东西,现在在用asp,我的搜索都是用它写的。我想把我的网站迁移到FreeBSD上,想用jsp编写程序,不知会不会难啊      
四海导航http://www.gcwww.com,四海论坛http://bbs.gcwww.com,推广网站到四海导航

TOP

发新话题