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"/>
<!-- 需要維護(hù)關(guān)系的屬性,就不是普通屬性 -->
<!-- Person和Card溝通的橋梁是外鍵fk_card_id -->
<one-to-one name="person" property-ref="card"/>
<!-- property-ref="card":通過(guò)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"/>
<!-- 唯一外鍵約束 -->
<!-- 此一對(duì)一屬于多對(duì)一的特例 -->
<!-- 先假設(shè)多個(gè)人共用一張卡,再給fk_card_id添加唯一約束,就變成了一對(duì)一關(guān)系 -->
<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":不放棄維護(hù)關(guān)系的權(quán)利,由Clazz維護(hù)關(guān)系 -->
<!-- inverse="true":放棄維護(hù)關(guān)系的權(quán)利,由Student維護(hù)關(guān)系 -->
<set name="students" inverse="true" cascade="all">
<!-- 一的一方為多的一方指定外鍵 -->
<key column="fk_class_id"/>
<!-- 讓Clazz認(rèn)識(shí)認(rèn)識(shí)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"/>
<!-- 對(duì)于多對(duì)多的關(guān)系,需要一張中間表 -->
<set name="users" table="tbl_user_role">
<!-- 中間表,通過(guò)什么字段,跟Role表產(chǎn)生關(guān)系 -->
<key column="fk_role_id"/>
<!-- 讓Role認(rèn)識(shí)User --><!-- 中間表,通過(guò)什么字段,跟User表產(chǎn)生關(guān)系 -->
<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("開(kāi)始游戲");
exitItem = new JMenuItem("退出游戲");
nanDuMenu = new JMenu("困難程度");
cJianDan = new JCheckBoxMenuItem("簡(jiǎn)單");
cPuTong = new JCheckBoxMenuItem("普通");
cKunNan = new JCheckBoxMenuItem("困難");
fenShuMenu = new JMenu("積分排行");
fenShuItem = new JMenuItem("最高記錄");
guanYuMenu = new JMenu("關(guān)于");
zuoZheItem = new JMenuItem("關(guān)于作者");
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, "千面獨(dú)行客"+"\n\n"+" "+"QQ號(hào):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()
{
//判斷游戲是否結(jié)束的方法
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()
{
//當(dāng)蛇吃到東西時(shí)的方法
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); //設(shè)置背景
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("當(dāng)前 分?jǐn)?shù)"+this.life,6,60);
g.drawString("當(dāng)前已吃食物數(shù)"+this.foods,6,72);
}
}
2012年5月12日
我曾經(jīng)有一個(gè)夢(mèng)想
我希望轟轟烈烈地過(guò)一生
就如同在這個(gè)江湖
可在生活中
我普通的值剩下一個(gè)名字
我自恃清高、懶惰、傲慢、偏激
假如生命可以被設(shè)計(jì)的話(huà)
我不要長(zhǎng)衫
不要斗笠
不要長(zhǎng)劍
不要足以湮沒(méi)我一生的雨季
我只想活在這個(gè)世界里
給自己一個(gè)名字
再給自己一個(gè)江湖!!!
2012年4月25日
有一對(duì)小兔子,如果第二個(gè)月它們成年,第三個(gè)月開(kāi)始每個(gè)月都生下一對(duì)小兔,而所生小兔亦在第二個(gè)月成年,第三個(gè)月開(kāi)始也每個(gè)月生下一對(duì)小兔(這里假定每個(gè)月所生下的一對(duì)小兔必為一雌一雄,且均無(wú)死亡),試問(wèn)一年后共有幾對(duì)小兔?
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]);
}
}