posts - 32,comments - 8,trackbacks - 0

Oops! JMF Quick Start

 

Purpose:

学习完后能够学会操作JMF.

JMFjava media framework,能够控制流媒体

 

Reference :

http://blog.csdn.net/oscar999/archive/2006/12/11/1438694.aspx

 

Precondition:

Eclipse 3.3 europa

jmf-2_1_1e-windows-i586.exe

/Files/pixysoft/jmf-2_1_1e-windows-i586.part1.rar 
/Files/pixysoft/jmf-2_1_1e-windows-i586.part2.rar 
/Files/pixysoft/jmf-2_1_1e-windows-i586.part3.rar 
/Files/pixysoft/jmf-2_1_1e-windows-i586.part4.rar 



Quick Start:

新建一个java project,项目名为Oops_JMF

 

在项目里面添加一个lib目录,并添加以下jar文件,全部可以在jmf-2_1_1e-windows-i586.exe里面找到



 

src目录下面添加以下文件:

SimpleAudioPlayer.java

import javax.media.*;

import java.io.File;

import java.io.IOException;

import java.net.URL;

import java.net.MalformedURLException;

 

public class SimpleAudioPlayer

{

       
private Player audioPlayer = null;

 

       
public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException,

                     CannotRealizeException

       {

              audioPlayer 
= Manager.createRealizedPlayer(url);

       }

 

       
public SimpleAudioPlayer(File file) throws IOException, NoPlayerException,

                     CannotRealizeException

       {

              
this(file.toURL());

       }

 

       
public void play()

       {

              audioPlayer.start();

       }

 

       
public void stop()

       {

              audioPlayer.stop();

              audioPlayer.close();

       }

}

 

TestCase.java

import java.io.File;

import java.io.IOException;

 

import javax.media.CannotRealizeException;

import javax.media.NoPlayerException;

 

public class TestCase

{

 

       
/**

        * 
@param args

        
*/

       
public static void main(String[] args)

       {

              File audioFile 
= new File("demo.mp3");

              
try

              {

                     SimpleAudioPlayer player 
= new SimpleAudioPlayer(audioFile);

                     System.out.println(
"music begin");

                     player.play();

                     System.out.println(
"music end");

 

              } 
catch (NoPlayerException e)

              {

                     
// TODO Auto-generated catch block

                     e.printStackTrace();

              } 
catch (CannotRealizeException e)

              {

                     
// TODO Auto-generated catch block

                     e.printStackTrace();

              } 
catch (IOException e)

              {

                     
// TODO Auto-generated catch block

                     e.printStackTrace();

              }

 

       }

 

}




在项目根目录下面放置一个demo.mp3文件,最后整个项目变成:

 

 

右键点击项目,run as java application



 

设置好运行环境



 

成功!

 

发现很有趣。整个application运行完了,但是音乐还在继续。估计内部开了线程。


posted @ 2007-09-07 14:56 张辰 阅读(897) | 评论 (0)编辑 收藏
 

Oops! JSF Quick Start!

Purpose:

学习使用一个JSF

Precondition:


/Files/pixysoft/jsf_simple_lib.part1.rar
/Files/pixysoft/jsf_simple_lib.part2.rar


Reference:
http://www.exadel.com/tutorial/jsf/jsftutorial-kickstart.html#compile


Tutorial:

新建一个项目Dynamic Web Project,名字Oops_JSF



lib目录下添加以下jar文件



修改
web.xml


<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC 

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 

 "http://java.sun.com/dtd/web-app_2_3.dtd"
>

<web-app>

    
<context-param>

        
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>

        
<param-value>server</param-value>

    
</context-param>

    
<context-param>

        
<param-name>javax.faces.CONFIG_FILES</param-name>

        
<param-value>/WEB-INF/faces-config.xml</param-value>

    
</context-param>

    
<listener>

        
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>

    
</listener>

    
<!-- Faces Servlet -->

    
<servlet>

        
<servlet-name>Faces Servlet</servlet-name>

        
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

        
<load-on-startup> 1 </load-on-startup>

    
</servlet>

    
<!-- Faces Servlet Mapping -->

    
<servlet-mapping>

        
<servlet-name>Faces Servlet</servlet-name>

        
<url-pattern>*.jsf</url-pattern>

    
</servlet-mapping>

    

</web-app>



在WEB-INF目录下面添加文件faces-config.xml


<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC

 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"

 "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"
>

<faces-config>

 
<navigation-rule>

   
<from-view-id>/pages/inputname.jsp</from-view-id>

    
<navigation-case>

     
<from-outcome>greeting</from-outcome>

     
<to-view-id>/pages/greeting.jsp</to-view-id>

   
</navigation-case>

 
</navigation-rule>

 
<managed-bean>

    
<managed-bean-name>personBean</managed-bean-name>

    
<managed-bean-class>jsfks.PersonBean</managed-bean-class>

    
<managed-bean-scope>request</managed-bean-scope>

 
</managed-bean>

</faces-config>


在WebContent下面添加pages目录,然后新建2个文件

greeting.jsp

 

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>

<html>

 
<head>

   
<title>greeting page</title>

 
</head>    

 
<body>

     
<f:view>

        
<h3>

     
<h:outputText value="#{msg.greeting_text}"/>,

     
<h:outputText value="#{personBean.personName}"/>

         
<h:outputText value="#{msg.sign}"/>

    
</h3>

     
</f:view>

 
</body>   

</html>



inputname.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>

<html>

 
<head>

 
<title>enter your name page</title>

 
</head>

 
<body>

   
<f:view>

     
<h1>

      
<h:outputText value="#{msg.inputname_header}"/>

     
</h1>

     
<h:form id="helloForm">

      
<h:outputText value="#{msg.prompt}"/>

      
<h:inputText value="#{personBean.personName}"/>

      
<h:commandButton action="greeting" value="#{msg.button_text}"/>

     
</h:form>

   
</f:view>

 
</body>

</html> 



WebContent目录下面添加一个index.jsp文件

 

<html>

 
<body>

 
<jsp:forward page="/pages/inputname.jsf" />

 
</body>

</html>

 

src目录下面添加jsfks目录,再添加PersonBean.java文件


package jsfks;

publicclass PersonBean {

   String personName;

    

   
/**

   *@returnPersonName

   
*/

  
public String getPersonName() {

      returnpersonName;

   }

   
/**

   *@paramPersonName

   
*/

   publicvoid setPersonName(String name) {

      personName 
= name;

   }

}


jsfks目录下添加bundle目录,再添加文件messages.properties

inputname_header=JSFKickStart

prompt
=Tellusyourname:

greeting_text
=WelcometoJSF

button_text
=SayHello

sign
=!



最后整个文件夹为:



最后
Run as … On Server




注意:一定要把之前的
server配置删除,run as 的时候是一个新的server,就因为这个原因我忙了几个小时,才发现出错是因为之前存在了另外一个roject在server上,也不提示。

posted @ 2007-09-04 18:39 张辰 阅读(355) | 评论 (0)编辑 收藏

Oops! JSP + XML Quick Start

/Files/pixysoft/xalan.part1.rar
/Files/pixysoft/xalan.part2.rar

新建一个Dynamic Web Project,名叫Oops_jsp_xml,然后在lib下添加以下jar文件,都可以在JSTL包里面找到。(xalan.jar文件这里下载,解压出来)。在WEB-INF下新建tlds目录,添加c.tld文件。




修改
web.xml文件如下:

 

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

    version
="2.4">

    
<jsp-config>

       
<taglib>

           
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>

           
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>

       
</taglib>

    
</jsp-config>

</web-app>

 

WebContent目录下面添加2个文件:

student.xml

<?xml version="1.0" encoding="UTF-8"?>

<students>

    
<student id="1">

       
<name>

           
<first name="Joe1">Joe</first>

           
<last name="y1">Y</last>

           
<middle name="t1">T</middle>

       
</name>

       
<grade>

           
<points>99</points>

           
<letter>A</letter>

       
</grade>

    
</student>

    
<student id="2">

       
<name>

           
<first name="james1">James</first>

           
<last name="todd">Todd</last>

           
<middle name="k1">K</middle>

       
</name>

       
<grade>

           
<points>92</points>

           
<letter>B</letter>

       
</grade>

    
</student>

    
<student id="3">

       
<name>

           
<first name="kate1">Kate</first>

           
<last name="wang1">Wang</last>

           
<middle name="a1">A</middle>

       
</name>

       
<grade>

           
<points>72</points>

           
<letter>C</letter>

       
</grade>

    
</student>

</students>

index.jsp

 

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>

<html>

<head>

<title>index</title>

</head>

<body>

<c:import var="students" url="student.xml" />

<x:parse var="doc" xml="${students}"/>

<table border="1">

    
<tr>

       
<th>First</th>

       
<th>Last</th>

       
<th>Points</th>

       
<th>Letter</th>

    
</tr>

    
<x:forEach var="student" select="$doc/students/student">

       
<tr>

           
<td><x:out select="name/first/@name" /></td>

           
<td><x:out select="name/last" /></td>

           
<td><x:out select="grade/points" /></td>

           
<td><x:out select="grade/letter" /></td>

       
</tr>

    
</x:forEach>

</table>

</body>

</html>

运行!


 

posted @ 2007-09-02 02:21 张辰 阅读(239) | 评论 (0)编辑 收藏
 

Oops! JSTL Quick Start

Purpose:

掌握jstl入门

Precondition:

eclipse-java-europa-win32.zip

/Files/pixysoft/jakarta-taglibs-standard-current.zip

Tutorial

新建一个Dynamic Web Project,名字叫做Oops_jstl



WebContent/WEB-INF/lib下添加以下jar文件,全部可以在jakarta-taglibs-standard-current.zip里面找到。



webContent/WEB-INF下新建一个tlds目录,添加以下文件



修改web.xml,添加以下内容

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

    version
="2.4">

    
<jsp-config>

       
<taglib>

           
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>

           
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>

       
</taglib>

    
</jsp-config>

</web-app>



在WebContent目录下面添加index.jsp文件

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>

 
<body>

    
<c:if test="${pageContext.request.method=='POST'}">

      
<c:if test="${param.guess=='java'}">You guessed it!

      
<br />

      
<br />

      
</c:if>

      
<c:if test="${param.guess!='java'}">

      You are wrong

      
<br />

      
<br />

      
</c:if>

    
</c:if>

    
<form method="post">Guess what computer language

                        I am thinking of?

    
<input type="text" name="guess" />

    
<input type="submit" value="Try!" />

    
<br />

    
</form>

 
</body>

</html>



运行!




成功!

posted @ 2007-09-01 20:09 张辰 阅读(203) | 评论 (0)编辑 收藏
 

Oops! Eclipse + Hibernate Quick Start

Purpose:

学会使用Hibernate

Precondition:

eclipse-java-europa-win32.zip

hibernate-3.2.5.ga.zip

mysql-5.0.45-win32.zip

Quick Start:

mySql数据库里面添加一张表。



对应的
sql语句是:

CREATE TABLE CUSTOMER(

CID INTEGER,

USERNAME VARCHAR(12) NOT NULL,

PASSWORD VARCHAR(12)

);

ALTER TABLE CUSTOMER ADD CONSTRAINT PK PRIMARY KEY(CID);


eclipse里面新建一个java project, 项目名为:Oops_hibernate


新建一个
lib目录,在lib目录下面添加以下jar包,全部可以在hibernate.zip文件里面找到


选择
project – properties – java build path – libraries – add jars

Oops_hibernate目录下面的所有lib加进来



src目录下面添加以下文件:


Customer.hbm.xml

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

    "-//Hibernate/Hibernate Mapping DTD//EN"

    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
>

<hibernate-mapping>

    
<class name="Customer" table="CUSTOMER">

        
<id name="id" column="CID">

            
<generator class="increment" />

        
</id>

        
<property name="username" column="USERNAME" />

        
<property name="password" column="PASSWORD" />

    
</class>

</hibernate-mapping>


Customer.java


public class Customer {

    

    
private int id;

    
private String username;

    
private String password;

    
public int getId() {

        
return id;

    }

    
public String getPassword() {

        
return password;

    }

    
public String getUsername() {

        
return username;

    }

    
public void setId(int id) {

        
this.id = id;

    }

    
public void setPassword(String password) {

        
this.password = password;

    }

    
public void setUsername(String username) {

        
this.username = username;

    }

}


hibernate.cfg.xml
,注意红色部分要和数据库对应。

         <?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE hibernate-configuration

    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"

    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

   

    <session-factory name="java:/hibernate/HibernateFactory">

       

        <property name="show_sql">true</property>

        <property name="connection.driver_class">

            com.mysql.jdbc.Driver

        </property>

        <property name="connection.url">

            jdbc:mysql://localhost:3306/test

        </property>

        <property name="connection.username">

            root

        </property>

        <property name="connection.password">

            admin

        </property>

        <property name="dialect">

            org.hibernate.dialect.MySQLDialect

        </property>

       

        <mapping resource="Customer.hbm.xml" />

       

    </session-factory>

   

</hibernate-configuration>

Test.java


import org.hibernate.*;

import org.hibernate.cfg.*;

public class Test {

    
public static void main(String[] args) {

        
try {

            SessionFactory sf 
=

                
new Configuration().configure().buildSessionFactory();

            Session session 
= sf.openSession();

           Transaction tx 
= session.beginTransaction();

            
for (int i = 0; i < 200; i++) {

                Customer customer 
= new Customer();

                customer.setUsername(
"customer" + i);

                customer.setPassword(
"customer");

                session.save(customer);

            }

            tx.commit();

            session.close();

        } 
catch (HibernateException e) {

            e.printStackTrace();

        }

    }

}



右键点击项目,Run as – java application



在窗口选择
Test





运行,完成!


posted @ 2007-09-01 14:57 张辰 阅读(454) | 评论 (0)编辑 收藏
Oops! Jsp +  MS Access Quick Start!

 

20070908 最新update

如果使用相对路径,需要修改链接字符串,转化成为绝对路径。
例如demo.mdb放在网站项目的根目录,Oops_JSP_Javabean_Access/demo.mdb,则
String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+ request.getRealPath("demo.mdb");
可以发现此时数据层需要request提供realpath,因此需要从页面上层(或者servlet)传递进来。




目的

通过jsp链接access数据库,进行查询

 

前期条件

eclipse-java-europa-win32.zip

apache-tomcat-5.5.23.exe

tomcatPluginV31.zip

 

正文

在c:盘下面新建一个access数据库,名字为demo.mdb.

 

打开demo.mdb数据库,建立以下表结构,和数据

 

 

新建一个Dynamic Web Project, 名字叫Oops_JSP_Javabean_Access

 

 

在src下建目录beanbase,再建文件


BeanbaseBean.java

要非常注意链接数据库的字段:

String sourceURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\demo.mdb";

这里使用绝对路径指向demo.mdb数据库

 

package beanbase;

 

import java.sql.*;

 

public class BeanbaseBean

{

    
private String timess = "";

    Connection conn 
= null;

    ResultSet rs 
= null;

    String url 
= "jdbc:odbc:demo";

    String sql;

 

    
public void adduser() throws Exception

    {

       
try

       {

           String sourceURL 
= "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\demo.mdb"// DataBase是Access

           
// MDB文件的主文件名

           Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver");

           conn 
= DriverManager.getConnection(sourceURL);

           
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

           
// conn = DriverManager.getConnection(url, "", "");

           Statement stmt 
= conn.createStatement();

           sql 
= "select * from user2 where datess='" + timess + "'";

           rs 
= stmt.executeQuery(sql);

           
while (rs.next())

           {

              System.out.println(rs.getString(
1+ "succeed");

           }

       } 
finally

       {

           conn.close();

       }

    }

 

    
// Access sample property

    
public String gettimess()

    {

       
return timess;

    }

 

    
// Access sample property

    
public void settimess(String newValue)

    {

       
if (newValue != null)

       {

           timess 
= newValue;

       }

    }

}

 

在WebContent下面建立2个jsp文件



beanase.jsp

 

<%@ page contentType="text/html; charset=GBK" %>

<html>

<body>

 

<form method="post" action="doneuser.jsp">

<input type="text" name="timess">

</form>

 

</body>

</html>

 

doneuser.jsp

 

 

<%@ page contentType="text/html; charset=GBK" %>

<html>

<jsp:useBean id="beanbaseBeanId" scope="session" class="beanbase.BeanbaseBean" />

<jsp:setProperty name="beanbaseBeanId" property="*" />

<body>

 

<jsp:getProperty name="beanbaseBeanId" property="timess" />

 

<%beanbaseBeanId.adduser();%>

 

 

</body>

</html>

 

 

右键点击项目,run as – server

 

 

 

在浏览器输入:

http://localhost:8080/Oops_JSP_Javabean_Access/beanbase.jsp




在页面输入:

Dr.Oops

回车,得到结果!




查看Console的输出:

posted @ 2007-08-30 15:12 张辰 阅读(539) | 评论 (0)编辑 收藏
 

 

Oops! JSP+Java Bean Quick Start!


eclipse europa + tomcat 5.5


Purpose:

完成这个项目,能够对使用jsp + javabean

Prerequisite:

eclipse-java-europa-win32.zip

apache-tomcat-5.5.23.exe

tomcatPluginV31.zip


Reference:

http://www.blogjava.net/pixysoft/archive/2007/08/29/141048.html 

Chapter 01

新建一个Dynamic Web Project, 名字叫Oops_JSP_Javabean

 

 

在src目录下建立一个count目录,增加一个java文件

 

 

counter.java

 

package count;

public class counter{

 int count=0;

public counter(){}

public int getCount(){

count++;

return count;

}

public void setCount(int count){

this.count=count;}

}

 

 

在WebContent下面增加一个文件



counter.jsp

 

<html>

<body>

<jsp:useBean id="bean0" scope="application" class="count.counter"/>

<%

out.println("The Counter is : "+ bean0.getCount() +"<br>");

%>

</body>

</html>

 

 

 

右键点击项目,run as – server

 

在浏览器输入:



刷新几次能够看见变化!

posted @ 2007-08-30 14:17 张辰 阅读(267) | 评论 (0)编辑 收藏
无聊吠一下




有时候很讨厌互联网(说到实质,就是讨厌一些人的人品)。google到一些有用资料,一点击下载,不是注册会员,就是交钱。妈的,你这么缺钱啊。简直恶心。

还有看了有些博客,说什么xxx+spring + hibernate教程,什么非常优秀。一打开,不是要email,就是联系qq,压根就没把内容帖出来。md你这么想收集人的email是不是啊。

还有些人,一打开blog,仿佛很繁华,一堆程序下载,还有一堆好像是马甲的在跟帖,吹的神乎其神。靠,下载后,随便运行一下就是一堆fatal error,直接导致关机。你丫的懂不懂编程的,连基本的程序结构都不同,连异常都不会抛,连基本的备选流use case都不知道。还什么xxx数据库框架,xxx持久层,恶心。

有些人就是恶心。什么狗屁资料,不就也是从internet上搜的,你算条毛。

去 codeproject看看,什么叫差异,什么叫道德差异。程序员,要从做人开始学起。
posted @ 2007-08-30 10:27 张辰 阅读(211) | 评论 (1)编辑 收藏

Oops! Spring Framework Quick Start!


eclipse europa + tomcat 5.5+spring 2.06+lomboz S3.3RC1


Purpose:

完成这个项目,能够对spring框架有个整体认识,包括IoC之类的。

Prerequisite:

eclipse-java-europa-win32.zip

apache-tomcat-5.5.23.exe

tomcatPluginV31.zip

spring-framework-2.0.6-with-dependencies.zip

org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip


Reference:

http://www.blogjava.net/pixysoft/archive/2007/08/29/141048.html 



Chapter 01
 

新建一个Java Project,项目名为OopsSpringFramework

 

 

 

选择project – properties – Libraries添加以下类库。所有类库可以在spring-framework-2.0.6.zip里面找到,包括dist目录和lib目录里面。

 

 

 

src目录下面添加以下文件:



beanRefDataAccess.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<beans>
    
<bean id="helloWorldDAO1" class="HelloWorld1" />
    
<bean id="helloWorldDAO2" class="HelloWorld2" />
</beans>


beanRefFactory.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<beans>
    
<bean id="beanFactory"
        class
="org.springframework.context.support.ClassPathXmlApplicationContext">
        
<constructor-arg>
            
<list>
                
<value>beanRefDataAccess.xml</value>
                
<value>beanRefService.xml</value>
                
<value>beanRefMVC.xml</value>
            
</list>
        
</constructor-arg>
    
</bean>
</beans>


beanRefMVC.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<beans>
    
<bean id="helloWorldMVC1" class="HelloWorld1" />
    
<bean id="helloWorldMVC2" class="HelloWorld2" />
</beans>

beanRefService.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<beans>
    
<bean id="helloWorld1" class="HelloWorld1" />
    
<bean id="helloWorld2" class="HelloWorld2" />
    
<bean id="springDemoConstructor" class="SpringDemoConstructor">
        
<constructor-arg>
            
<value>Spring IDE Constructor</value>
        
</constructor-arg>
        
<property name="helloWorld">
            
<ref bean="helloWorld1"></ref>
        
</property>
    
</bean>
    
<bean id="springDemoSetter" class="SpringDemoSetter">
        
<property name="hello" value="Spring IDE Setter" />
        
<property name="helloWorld">
            
<ref bean="helloWorld2"></ref>
        
</property>
    
</bean>
</beans>


HelloWorld1.java

public class HelloWorld1 implements IHelloWorld
{
    
public HelloWorld1()
    {
        
super();
    }

    
public String sayHelloWorld()
    {
        
return "Hello World HelloWorld1";
    }
}

HelloWorld2.java

public class HelloWorld2 implements IHelloWorld
{
    
public HelloWorld2()
    {
        
super();
    }

    
public String sayHelloWorld()
    {
        
return "Hello World HelloWorld2";
    }
}

IHelloWorld.java

 

public interface IHelloWorld
{
    String sayHelloWorld();
}


ISpringDemo.java

public interface ISpringDemo
{
    IHelloWorld getHelloWorld();

    String getHello();
}


ServiceFactory.java

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;

public final class ServiceFactory
{
    
private static BeanFactoryLocator bfLocator = null;
    
private static BeanFactoryReference bfReference = null;
    
private static BeanFactory factory = null;
    
static
    {
        bfLocator 
= SingletonBeanFactoryLocator.getInstance();
        bfReference 
= bfLocator.useBeanFactory("beanFactory");
        factory 
= bfReference.getFactory();
    }

    
private ServiceFactory()
    {
        
super();
    }

    
public static Object getBeanByName(final String beanName)
    {
        
return factory.getBean(beanName);
    }
}

SpringDemoConstructor.java

public class SpringDemoConstructor implements ISpringDemo
{
    
private String hello;
    
private IHelloWorld helloWorld;

    
public SpringDemoConstructor(String hello)
    {
        
this.hello = hello;
    }

    
public String getHello()
    {
        
return hello;
    }

    
public IHelloWorld getHelloWorld()
    {
        
return helloWorld;
    }

    
public void setHelloWorld(IHelloWorld helloWorld)
    {
        
this.helloWorld = helloWorld;
    }
}

SpringDemoSetter.java

public class SpringDemoSetter implements ISpringDemo
{
    
private String hello;
    
private IHelloWorld helloWorld;

    
public String getHello()
    {
        
return hello;
    }

    
public void setHello(String hello)
    {
        
this.hello = hello;
    }

    
public IHelloWorld getHelloWorld()
    {
        
return helloWorld;
    }

    
public void setHelloWorld(IHelloWorld helloWorld)
    {
        
this.helloWorld = helloWorld;
    }
}


SpringIDETest.java

import junit.framework.TestCase;

public class SpringIDETest extends TestCase
{
    
private IHelloWorld helloWorld = null;
    
private ISpringDemo springDemo = null;
    
private final static String hello1 = "Hello World HelloWorld1";
    
private final static String hello2 = "Hello World HelloWorld2";
    
private final static String helloset = "Spring IDE Setter";
    
private final static String hellocon = "Spring IDE Constructor";

    
public void testSpringBeans()
    {
        helloWorld 
= (IHelloWorld) ServiceFactory.getBeanByName("helloWorld1");
        assertEquals(hello1, helloWorld.sayHelloWorld());
        helloWorld 
= (IHelloWorld) ServiceFactory.getBeanByName("helloWorld2");
        assertEquals(hello2, helloWorld.sayHelloWorld());
    }

    
public void testIoCConstructor()
    {
        
// Constructor
        springDemo = (ISpringDemo) ServiceFactory
                .getBeanByName(
"springDemoConstructor");
        assertEquals(hellocon, springDemo.getHello());
        assertEquals(hello1, springDemo.getHelloWorld().sayHelloWorld());
    }

    
public void testIoCSetter()
    {
        
// Setter
        springDemo = (ISpringDemo) ServiceFactory
                .getBeanByName(
"springDemoSetter");
        assertEquals(helloset, springDemo.getHello());
        assertEquals(hello2, springDemo.getHelloWorld().sayHelloWorld());
    }
}




鼠标右点击OopsSpringFramework,选择 Add Spring Project Nature


 

打开Spring Explorer窗口

 

 

 



SpringExplorer里面右选择项目,properties.



选择
Beans Support,Add xml



 

之后得到以下内容


 

选择Config SetsNew,输入以下内容

 

之后Spring-Explorer出现以下内容



右键点击项目,选择Run as.. JUnit …

 


完成!


posted @ 2007-08-30 10:11 张辰 阅读(888) | 评论 (0)编辑 收藏
Oops! Eclispe Quick Start!



Introduction:

本章主要介绍搭建一个能够开发java的环境。


Chapter X

Eclipse最新版本 eclipse-java-europa-win32.zip
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/20070702/eclipse-java-europa-win32.zip&r=1&protocol=http

Tomcat 5.5 一个服务器
http://apache.mirror.phpchina.com/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.zip

TomcatPluginV31 插件
/Files/pixysoft/tomcatPluginV31.zip

Lomboz插件
http://download.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip
or
http://download.fr2.forge.objectweb.org/lomboz/org.objectweb.lomboz-and-prereqs-S-3.3RC1-200708181505.zip

mySQL database
http://dev.mysql.com/downloads/mysql/5.0.html#win32

mySQL Connector java链接mysql的驱动程序
http://dev.mysql.com/downloads/connector/j/5.0.html

Chapter Y 安装

把eclipse解压出来。

安装Tomcat,根据提示。

把TOmcatPluginV31插件解压到和eclipse一样的目录。

解压lomboz插件,和上面方法一样。

run eclipse.exe



安装成功!

安装mySQL

现在一个比较初级的java开发环境已经搭建起来了。
posted @ 2007-08-29 18:42 张辰 阅读(392) | 评论 (0)编辑 收藏
仅列出标题
共4页: 上一页 1 2 3 4 下一页