2012年6月27日		  
		
			
			
			<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Card" table="tbl_card">
  <id name="cardId" column="pk_card_id">
   <generator class="native"/>
  </id>  
  <property name="cardNo" column="card_no"/>  
  <!-- 需要维护关系的属性,就不是普通属性 -->
  <!-- Person和Card沟通的桥梁是外键fk_card_id -->
  <one-to-one name="person" property-ref="card"/>  
  <!-- property-ref="card":通过Person的外键pk_card_id,可以得到pk_person_id -->
 </class>
</hibernate-mapping>
<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Person" table="tbl_person">
  <id name="personId" column="pk_person_id">
   <generator class="native"/>
  </id>  
  <property name="personName" column="person_name"/>  
  <!-- 唯一外键约束 -->
  <!-- 此一对一属于多对一的特例 -->
  <!-- 先假设多个人共用一张卡,再给fk_card_id添加唯一约束,就变成了一对一关系 -->
  <many-to-one name="card" column="fk_card_id" unique="true" cascade="all"/>
 </class>
</hibernate-mapping>
			
			
		
 
	
		
			
			
			<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Clazz" table="tbl_class">
  <id name="classId" column="pk_class_id">
   <generator class="native"/>
  </id>  
  <property name="className" column="class_name"/>  
  <!-- inverse="false":不放弃维护关系的权利,由Clazz维护关系 -->
  <!-- inverse="true":放弃维护关系的权利,由Student维护关系 -->
  <set name="students" inverse="true" cascade="all">
   <!-- 一的一方为多的一方指定外键 -->
   <key column="fk_class_id"/>
   <!-- 让Clazz认识认识students是什么 -->
   <one-to-many class="Student"/>
  </set>
 </class>
</hibernate-mapping>
<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Student" table="tbl_student">
  <id name="studentId" column="pk_student_id">
   <generator class="native"/>
  </id>  
  <property name="studentName" column="student_name"/>  
  <many-to-one name="clazz" column="fk_class_id" cascade="all"/>
 </class>
</hibernate-mapping>
			
			
		
 
	
		
			
			
			<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Role" table="tbl_role">
  <id name="roleId" column="pk_role_id">
   <generator class="native"/>
  </id>  
  <property name="roleName" column="role_name"/>  
  <!-- 对于多对多的关系,需要一张中间表 -->
  <set name="users" table="tbl_user_role">
   <!-- 中间表,通过什么字段,跟Role表产生关系 -->
   <key column="fk_role_id"/>
   <!-- 让Role认识User --><!-- 中间表,通过什么字段,跟User表产生关系 -->
   <many-to-many class="User" column="fk_user_id"/>
  </set>
 </class>
</hibernate-mapping>
<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="User" table="tbl_user">
  <id name="userId" column="pk_user_id">
   <generator class="native"/>
  </id>  
  <property name="userName" column="uesr_name"/>  
  <set name="roles" table="tbl_user_role">
   <key column="fk_user_id"/>
   <many-to-many class="Role" column="fk_role_id"/>
  </set>
 </class>
</hibernate-mapping>
			
			
		
 
	
		
			
			
			public class Export{
 
 private void mian(String[] args) {
  Configuration cfg = new Configuration().configure();
  
  SchemaExport export = new SchemaExport(cfg);
  
  export.create(true, true);
  
 }
}
			
			
		 
	
	
		
	
	2012年5月16日		  
		
			
			
			package com.wepull.test;
 
 import java.awt.Color; 
 import java.awt.Graphics; 
 import java.awt.Toolkit; 
 import java.awt.event.ActionEvent; 
 import java.awt.event.ActionListener; 
 import java.awt.event.InputEvent; 
 import java.awt.event.KeyEvent; 
 import java.awt.event.KeyListener; 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.KeyStroke;
 
  
 public class 贪吃蛇 extends JFrame implements ActionListener, KeyListener,Runnable { 
 /**
   * 
   */
 private static final long serialVersionUID = 1L;
 private JMenuBar menuBar; 
 private JMenu youXiMenu,nanDuMenu,fenShuMenu,guanYuMenu; 
 private JMenuItem kaiShiYouXi,exitItem,zuoZheItem,fenShuItem; 
 private JCheckBoxMenuItem cJianDan,cPuTong,cKunNan; 
 private int length = 6; 
 private Toolkit toolkit; 
 private int i,x,y,z,objectX,objectY,object=0,growth=0,time;//bojectX,Y
 private int m[]=new int[50]; 
 private int n[]=new int[50]; 
 private Thread she = null; 
 private int life=0; 
 private int foods = 0; 
 private int fenshu=0; 
  
 public void run(){  
   time=500; 
   for(i=0;i<=length-1;i++) 
   { 
    m[i]=90-i*10;n[i]=60; 
   } 
   
   x=m[0]; 
   y=n[0]; 
   z=4; 
   
   
   while(she!=null) 
   { 
    
    check(); 
    try 
    { 
     Thread.sleep(time); 
    } 
    catch(Exception ee) 
    { 
     System.out.println(z+""); 
    } 
   } 
 } 
 public 贪吃蛇() { 
  
   setVisible(true); 
   menuBar = new JMenuBar(); 
   toolkit=getToolkit(); 
  
   youXiMenu = new JMenu("游戏"); 
   kaiShiYouXi = new JMenuItem("开始游戏"); 
   exitItem = new JMenuItem("退出游戏"); 
  
   nanDuMenu = new JMenu("困难程度"); 
   cJianDan = new JCheckBoxMenuItem("简单"); 
   cPuTong = new JCheckBoxMenuItem("普通"); 
   cKunNan = new JCheckBoxMenuItem("困难"); 
  
   fenShuMenu = new JMenu("积分排行"); 
   fenShuItem = new JMenuItem("最高记录"); 
   guanYuMenu = new JMenu("关于"); 
   zuoZheItem = new JMenuItem("关于作者"); 
  
   guanYuMenu.add(zuoZheItem); 
   nanDuMenu.add(cJianDan); 
   nanDuMenu.add(cPuTong); 
   nanDuMenu.add(cKunNan); 
  fenShuMenu.add(fenShuItem); 
  youXiMenu.add(kaiShiYouXi); 
   youXiMenu.add(exitItem); 
  menuBar.add(youXiMenu); 
   menuBar.add(nanDuMenu); 
   menuBar.add(fenShuMenu); 
   menuBar.add(guanYuMenu); 
 zuoZheItem.addActionListener(this); 
   kaiShiYouXi.addActionListener(this); 
   exitItem.addActionListener(this); 
   addKeyListener(this); 
   fenShuItem.addActionListener(this); 
   KeyStroke keyOpen = KeyStroke.getKeyStroke('O',InputEvent.CTRL_DOWN_MASK); 
   kaiShiYouXi.setAccelerator(keyOpen); 
   KeyStroke keyExit = KeyStroke.getKeyStroke('X',InputEvent.CTRL_DOWN_MASK); 
   exitItem.setAccelerator(keyExit); 
   setJMenuBar(menuBar); 
   setTitle("贪吃蛇"); 
   setResizable(false); 
   setBounds(300,200,400,400); 
   validate(); 
   setDefaultCloseOperation(EXIT_ON_CLOSE);   
 } 
  
 public static void main(String args[]) { 
    new 贪吃蛇(); 
 } 
 public void actionPerformed(ActionEvent e){ 
   if(e.getSource()==kaiShiYouXi) 
   { 
    length = 6; 
    life = 0; 
    foods = 0; 
    if(she==null) 
    { 
     she=new Thread(this); 
     she.start(); 
    } 
    else if(she!=null) 
    { 
     she=null; 
     she= new Thread(this); 
     she.start(); 
    } 
   } 
   if(e.getSource()==exitItem) 
   { 
    System.exit(0); 
   } 
   if(e.getSource()==zuoZheItem) 
   { 
    JOptionPane.showMessageDialog(this, "千面独行客"+"\n\n"+"                  "+"QQ号:244897789"+"\n"); 
   } 
   if(e.getSource()==fenShuItem) 
   { 
       JOptionPane.showMessageDialog(this,"最高记录为"+fenshu+"");  
   } 
   
 } 
 public void check(){ 
   isDead(); 
   if(she!=null) 
   { 
    if(growth==0) 
    { 
     reform(); //得到食物 
    } 
    else 
    { 
     upgrowth(); //生成食物 
    } 
    if(x==objectX&&y==objectY) 
    { 
     object=0; 
     growth=1; 
     toolkit.beep(); 
    } 
    if(object==0) 
    { 
     object=1; 
     objectX=(int)Math.floor(Math.random()*39)*10; 
     objectY=(int)Math.floor(Math.random()*29)*10+50; 
    } 
    this.repaint(); //重绘 
   } 
 } 
 void isDead() 
 { 
   //判断游戏是否结束的方法 
   if(z==4) 
   { 
    x=x+10; 
   } 
   else if(z==3) 
      { 
         x=x-10; 
      } 
   else if(z==2) 
      { 
         y=y+10; 
      } 
   else if(z==1) 
      { 
         y=y-10; 
      } 
   if(x<0||x>390||y<50||y>390) 
   { 
    she=null; 
   } 
   for(i=1;i<length;i++) 
   { 
    if(m[i]==x&&n[i]==y) 
    { 
     she=null; 
    } 
   } 
    
 } 
 public void upgrowth() 
 {  
   //当蛇吃到东西时的方法 
   if(length<50) 
   { 
    length++; 
   }  
   growth--; 
   time=time-10; 
   reform(); 
   life+=100; 
   if(fenshu<life) 
   { 
    fenshu = life; 
   } 
   foods++; 
 } 
 public void reform() 
 { 
   for(i=length-1;i>0;i--) 
   { 
    
    m[i]=m[i-1]; 
    n[i]=n[i-1]; 
   } 
   if(z==4) 
   { 
    m[0]=m[0]+10; 
   } 
   if(z==3) 
   { 
    m[0]=m[0]-10; 
   } 
   if(z==2) 
   { 
    n[0]=n[0]+10; 
   } 
   if(z==1) 
   { 
    n[0]=n[0]-10; 
   } 
 } 
 public void keyPressed(KeyEvent e) 
 { 
   if(she!=null) 
   { 
    if(e.getKeyCode()==KeyEvent.VK_UP) 
    { 
     if(z!=2) 
     { 
      z=1; 
      check(); 
     } 
    } 
    else if(e.getKeyCode()==KeyEvent.VK_DOWN) 
    { 
     if(z!=1) 
     { 
      z=2; 
      check(); 
     } 
    } 
    else if(e.getKeyCode()==KeyEvent.VK_LEFT) 
    { 
     if(z!=4) 
     { 
      z=3; 
      check(); 
     } 
    } 
    else if(e.getKeyCode()==KeyEvent.VK_RIGHT) 
    { 
     if(z!=3) 
     { 
      z=4; 
      check(); 
     } 
    } 
   
   } 
   
 } 
 public void keyReleased(KeyEvent e) 
 { 
   
 } 
 public void keyTyped(KeyEvent e) 
 { 
   
 } 
 public void paint(Graphics g)  { 
   g.setColor(Color.DARK_GRAY); //设置背景 
   g.fillRect(0,50,400,400); 
   g.setColor(Color.pink); 
   for(i=0;i<=length-1;i++) 
   { 
    g.fillRect(m[i],n[i],10,10); 
   } 
   g.setColor(Color.green); //蛇的食物 
   g.fillRect(objectX,objectY,10,10); 
   g.setColor(Color.white); 
   g.drawString("当前      分数"+this.life,6,60); 
   g.drawString("当前已吃食物数"+this.foods,6,72); 
 } 
 }
 
 
			
			
		 
	
	
		
	
	2012年5月12日		  
		
			
			
			我曾经有一个梦想
我希望轰轰烈烈地过一生
就如同在这个江湖
可在生活中
我普通的值剩下一个名字
我自恃清高、懒惰、傲慢、偏激
假如生命可以被设计的话
我不要长衫
不要斗笠
不要长剑
不要足以湮没我一生的雨季
我只想活在这个世界里
给自己一个名字
再给自己一个江湖!!!
			
			
		
 
	
	
		
	
	2012年4月25日		  
		
			
			
			 
  有一对小兔子,如果第二个月它们成年,第三个月开始每个月都生下一对小兔,而所生小兔亦在第二个月成年,第三个月开始也每个月生下一对小兔(这里假定每个月所生下的一对小兔必为一雌一雄,且均无死亡),试问一年后共有几对小兔?
 
public int Number(int months) {
  int number;
  if (months == 1 || months == 2)
   return number = 1;
  else {
   return number = Number(months - 1) + Number(months - 2);
  }
 }
 public static void main(String[] args) {
  Hare r = new Hare();
  System.out.println(r.Number(12));
 }
			
			
		 
	
		
			
			
			public static void main(String[] args) {
      for (int i = 1, j = 1; j <= 9; i++) {
        System.out.print(i + "*" + j + "=" + i * j + " ");
        if (i == j) {
           i = 0;
           j++;
           System.out.println();
        }
      }
 
}
			
			
		 
	
	
		
	
	2012年4月20日		  
		
			
			
			public static void main(String[] args) {
  int a[] = { 3, 7, 80, 56, 97, 34 };
  for (int i = 1; i < a.length; i++) {
   for (int j = 0; j < a.length-1; j++) {
    if (a[j] > a[j+1]) {
     a[j] = a[j+1] + a[j];
     a[j+1] = a[j] - a[j+1];
     a[j] = a[j] - a[j+1];
    }
   }
   System.out.println("a[i]="+a[i]);
  }
 }