Hey,buddy:What's up?

Happy&Optimistic&Effective

BlogJava 首页 新随笔 联系 聚合 管理
  14 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

2006年4月27日 #

本程序改变自网上的一个datapicker,没有用javax包,而是基于java.awt包。you can use it in your applet.共四个文件。

//1.AbsoluteConstraints.java

import java.awt.Dimension;
import java.awt.Point;

public class AbsoluteConstraints
    implements java.io.Serializable {
  static final long serialVersionUID = 5261460716622152494L;
  public int x;
  public int y;
  public int width = -1;
  public int height = -1;
  public AbsoluteConstraints(Point pos) {
    this(pos.x, pos.y);
  }

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

  public AbsoluteConstraints(Point pos, Dimension size) {
    this.x = pos.x;
    this.y = pos.y;
    if (size != null) {
      this.width = size.width;
      this.height = size.height;
    }
  }

  public AbsoluteConstraints(int x, int y, int width, int height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
  }

  public int getX() {
    return x;
  }

  public int getY() {
    return y;
  }

  public int getWidth() {
    return width;
  }

  public int getHeight() {
    return height;
  }

  public String toString() {
    return super.toString() + " [x=" + x + ", y=" + y + ", width=" + width +
        ", height=" + height + "]";
  }
}



//2.import java.awt.*;

public class AbsoluteLayout
    implements LayoutManager2, java.io.Serializable {
  static final long
      serialVersionUID = -1919857869177070440L;
  protected java.util.Hashtable constraints = new java.util.Hashtable();
  public
      void addLayoutComponent(String name, Component comp) {
    throw new IllegalArgumentException();
  }

  public void
      removeLayoutComponent(Component comp) {
    constraints.remove(comp);
  }

  public Dimension preferredLayoutSize
      (Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (java.util.Enumeration e =
         constraints.keys(); e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints
          ac = (AbsoluteConstraints) constraints.get(comp);
      Dimension size = comp.getPreferredSize();
      int width =
          ac.getWidth();
      if (width == -1)
        width = size.width;
      int height = ac.getHeight();
      if (height == -1)
        height = size.height;
      if (ac.x + width > maxWidth)
        maxWidth = ac.x + width;
      if (ac.y + height >
          maxHeight)
        maxHeight = ac.y + height;
    }
    return new Dimension(maxWidth, maxHeight);
  }

  public
      Dimension minimumLayoutSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    for
        (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
      Dimension size = comp.getMinimumSize();
      int width = ac.getWidth();
      if (width == -1)
        width = size.width;
      int height = ac.getHeight();
      if (height == -1)
        height = size.height;
      if (ac.x + width > maxWidth)
        maxWidth = ac.x + width;
      if
          (ac.y + height > maxHeight)
        maxHeight = ac.y + height;
    }
    return new Dimension(maxWidth, maxHeight);
  }

  public void layoutContainer(Container parent) {
    for (java.util.Enumeration e = constraints.keys();
         e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints ac =
          (AbsoluteConstraints) constraints.get(comp);
      Dimension size = comp.getPreferredSize();
      int width = ac.getWidth();
      if (width == -1)
        width = size.width;
      int height = ac.getHeight();
      if (height == -1)
        height = size.height;
      comp.setBounds(ac.x, ac.y, width, height);
    }
  }

  public void addLayoutComponent
      (Component comp, Object constr) {
    if (! (constr instanceof AbsoluteConstraints))
      throw new
          IllegalArgumentException();
    constraints.put(comp, constr);
  }

  public Dimension maximumLayoutSize(Container
                                     target) {
    return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  }

  public float getLayoutAlignmentX
      (Container target) {
    return 0;
  }

  public float getLayoutAlignmentY(Container target) {
    return 0;
  }

  public void invalidateLayout(Container target) {}
}

// 3DateField.java

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.awt.*;

public final class DateField
    extends Panel {
  private static final long serialVersionUID = 1L;
  private final TextField dateText = new TextField(12);
  private final Button dropdownButton = new Button();
  private DatePicker dp;
  private Dialog dlg;
  Point origin = new Point();
  final class Listener
      extends ComponentAdapter {
    public void componentHidden(final ComponentEvent evt) {
      final Date dt = ( (DatePicker) evt.getSource()).getDate();
      if (null != dt)
        dateText.setText(dateToString(dt));
      dlg.dispose();
    }
  }

  public DateField() {
    super();
    init();
  }

  public DateField(final Date initialDate) {
    super();
    init();
    dateText.setText(dateToString(initialDate));
  }

  public Date getDate() {
    return stringToDate(dateText.getText());
  }

  public void setDate(Date date) {
    String v = dateToString(date);
    if (v == null) {
      v = "";
    }
    dateText.setText(v);
  }

  private void init() {
    setLayout(new BorderLayout());
    dateText.setText("");
    dateText.setEditable(false);
    dateText.setBackground(new Color(255, 255, 255));
    add(dateText, BorderLayout.CENTER);
    dropdownButton.setLabel("选择");
    dropdownButton.setBackground(Color.yellow);
    dropdownButton.addActionListener(new ActionListener() {
      public void actionPerformed(final ActionEvent evt) {
        onButtonClick(evt);
      }
    });
    add(dropdownButton, BorderLayout.EAST);
  }

  private void onButtonClick(final java.awt.event.ActionEvent evt) {
    if ("".equals(dateText.getText()))
      dp = new DatePicker();
    else
      dp = new DatePicker(stringToDate(dateText.getText()));
    dp.addComponentListener(new Listener());
    final Point p = dateText.getLocationOnScreen();
    p.setLocation(p.getX(), p.getY() - 1 + dateText.getSize().getHeight());
    dlg = new Dialog(new Frame(), true);
    dlg.addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        origin.x = e.getX();
        origin.y = e.getY();
      }
    });
    dlg.addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {
        Point p = dlg.getLocation();
        dlg.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y);
      }
    });
    dlg.setLocation(p);
    dlg.setResizable(false);
    dlg.setUndecorated(true);
    dlg.add(dp);
    dlg.pack();
    dlg.setVisible(true);
  }

  private static String dateToString(final Date dt) {
    if (null != dt)
      return DateFormat.getDateInstance(DateFormat.LONG).format(dt);
    return null;
  }

  private static Date stringToDate(final String s) {
    try {
      return DateFormat.getDateInstance(DateFormat.LONG).parse(s);
    }
    catch (ParseException e) {
      return null;
    }
  }

  public static void main(String[] args) {
    Dialog dlg = new Dialog(new Frame(), true);
    DateField df = new DateField();
   //dlg.getContentPane().add(df);
   dlg.add(df);
    dlg.pack();
    dlg.setVisible(true);
    System.out.println(df.getDate().toString());
    System.exit(0);
  }
}

//4.DatePicker.java

import java.awt.*;
import java.awt.event.*;
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.FieldPosition;
/*
import javax.swing.*;
import javax.swing.plaf.BorderUIResource;
*/
public final class DatePicker
    extends Panel {
  private static final long serialVersionUID = 1L;
  private static final int startX = 10;
  private static final int startY = 60;
  private static final Font smallFont = new Font("Dialog", Font.PLAIN, 10);
  private static final Font largeFont = new Font("Dialog", Font.PLAIN, 12);
  private static final Insets insets = new Insets(2, 2, 2, 2);
  private static final Color highlight = Color.YELLOW;//new Color(255, 255, 204);
  private static final Color white = new Color(255, 255, 255);
  private static final Color gray = new Color(204, 204, 204);
  private Component selectedDay = null;
  private GregorianCalendar selectedDate = null;
  private GregorianCalendar originalDate = null;
  private boolean hideOnSelect = true;
  private final Button backButton = new Button();
  private final Label monthAndYear = new Label();
  private final Button forwardButton = new Button();
  private final Label[] dayHeadings = new Label[] {
      new Label("日"),
      new Label("一"),
      new Label("二"),
      new Label("三"),
      new Label("四"),
      new Label("五"),
      new Label("六")};

  private final Label[][] daysInMonth = new Label[][] {
      {
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label()}
      , {
      new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label()}
      , {
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label()}
      , {
      new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label()}
      , {
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label()}
      , {
      new Label(),
      new Label(), new Label(),
      new Label(), new Label(),
      new Label(), new Label()}
  };
  private final Button todayButton = new Button();
  private final Button cancelButton = new Button();
  public DatePicker() {
    super();
    selectedDate = getToday();
    init();
  }

  public DatePicker(final Date initialDate) {
    super();
    if (null == initialDate)
      selectedDate = getToday();
    else
      (selectedDate = new GregorianCalendar()).setTime(initialDate);
    originalDate = new GregorianCalendar(selectedDate.get(Calendar.YEAR),
                                         selectedDate.get(Calendar.MONTH),
                                         selectedDate.get(Calendar.DATE));
    init();
  }

  public boolean isHideOnSelect() {
    return hideOnSelect;
  }

  public void setHideOnSelect(final boolean hideOnSelect) {
    if (this.hideOnSelect != hideOnSelect) {
      this.hideOnSelect = hideOnSelect;
      initButtons(false);
    }
  }

  public Date getDate() {
    if (null != selectedDate)
      return selectedDate.getTime();
    return null;
  }

  private void init() {
    setLayout(new AbsoluteLayout());
    /*
    this.setMinimumSize(new Dimension(161, 226));
    this.setMaximumSize(getMinimumSize());
    this.setPreferredSize(getMinimumSize());
    this.setBorder(new BorderUIResource.EtchedBorderUIResource());
    */
   this.setSize(new Dimension(161, 226));
    backButton.setFont(smallFont);
    backButton.setLabel("<");
  //  backButton.setSize(insets);
 //   backButton.setDefaultCapable(false);
    backButton.addActionListener(new ActionListener() {
      public void actionPerformed(final ActionEvent evt) {
        onBackClicked(evt);
      }
    });
    add(backButton, new AbsoluteConstraints(10, 10, 20, 20));
    monthAndYear.setFont(largeFont);
    monthAndYear.setAlignment((int)TextField.CENTER_ALIGNMENT);
    monthAndYear.setText(formatDateText(selectedDate.getTime()));
    add(monthAndYear, new AbsoluteConstraints(30, 10, 100, 20));
    forwardButton.setFont(smallFont);
    forwardButton.setLabel(">");
 //   forwardButton.setMargin(insets);
//    forwardButton.setDefaultCapable(false);
    forwardButton.addActionListener(new ActionListener() {
      public void actionPerformed(final ActionEvent evt) {
        onForwardClicked(evt);
      }
    });
    add(forwardButton, new AbsoluteConstraints(130, 10, 20, 20));
    int x = startX;
    for (int ii = 0; ii < dayHeadings.length; ii++) {
    //  dayHeadings[ii].setOpaque(true);
      dayHeadings[ii].setBackground(Color.LIGHT_GRAY);
      dayHeadings[ii].setForeground(Color.WHITE);
      dayHeadings[ii].setAlignment((int)TextField.CENTER_ALIGNMENT);
    //  dayHeadings[ii].setHorizontalAlignment(Label.CENTER);
      add(dayHeadings[ii], new AbsoluteConstraints(x, 40, 21, 21));
      x += 20;
    }
    x = startX;
    int y = startY;
    for (int ii = 0; ii < daysInMonth.length; ii++) {
      for (int jj = 0; jj < daysInMonth[ii].length; jj++) {
      //  daysInMonth[ii][jj].setOpaque(true);
        daysInMonth[ii][jj].setBackground(white);
        daysInMonth[ii][jj].setFont(smallFont);
     //   daysInMonth[ii][jj].setHorizontalAlignment(Label.CENTER);
        daysInMonth[ii][jj].setText("");
        daysInMonth[ii][jj].addMouseListener(new MouseAdapter() {
          public void mouseClicked(final MouseEvent evt) {
            onDayClicked(evt);
          }
        });
        add(daysInMonth[ii][jj], new AbsoluteConstraints(x, y, 21, 21));
        x += 20;
      }
      x = startX;
      y += 20;
    }
    initButtons(true);
    calculateCalendar();
  }

  private void initButtons(final boolean firstTime) {
    if (firstTime) {
      final Dimension buttonSize = new Dimension(68, 24);
      todayButton.setLabel("今天");
      todayButton.setSize(buttonSize);
      /*
      todayButton.setMargin(insets);
      todayButton.setMaximumSize(buttonSize);
      todayButton.setMinimumSize(buttonSize);
      todayButton.setPreferredSize(buttonSize);
      todayButton.setDefaultCapable(true);
      todayButton.setSelected(true);
      */
      todayButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent evt) {
          onToday(evt);
        }
      });
      cancelButton.setLabel("取消");
      cancelButton.setSize(buttonSize);
      /*
      cancelButton.setMargin(insets);
      cancelButton.setMaximumSize(buttonSize);
      cancelButton.setMinimumSize(buttonSize);
      cancelButton.setPreferredSize(buttonSize);
      */
      cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent evt) {
          onCancel(evt);
        }
      });
    }
    else {
      this.remove(todayButton);
      this.remove(cancelButton);
    }
    if (hideOnSelect) {
      add(todayButton, new AbsoluteConstraints(25, 190, 52, -1));
      add(cancelButton, new AbsoluteConstraints(87, 190, 52, -1));
    }
    else {
      add(todayButton, new AbsoluteConstraints(55, 190, 52, -1));
    }
  }

  private void onToday(final java.awt.event.ActionEvent evt) {
    selectedDate = getToday();
    setVisible(!hideOnSelect);
    if (isVisible()) {
      monthAndYear.setText(formatDateText(selectedDate.getTime()));
      calculateCalendar();
    }
  }

  private void onCancel(final ActionEvent evt) {
    selectedDate = originalDate;
    setVisible(!hideOnSelect);
  }

  private void onForwardClicked(final java.awt.event.ActionEvent evt) {
    final int day = selectedDate.get(Calendar.DATE);
    selectedDate.set(Calendar.DATE, 1);
    selectedDate.add(Calendar.MONTH, 1);
    selectedDate.set(Calendar.DATE,
                     Math.min(day, calculateDaysInMonth(selectedDate)));
    monthAndYear.setText(formatDateText(selectedDate.getTime()));
    calculateCalendar();
  }

  private void onBackClicked(final java.awt.event.ActionEvent evt) {
    final int day = selectedDate.get(Calendar.DATE);
    selectedDate.set(Calendar.DATE, 1);
    selectedDate.add(Calendar.MONTH, -1);
    selectedDate.set(Calendar.DATE,
                     Math.min(day, calculateDaysInMonth(selectedDate)));
    monthAndYear.setText(formatDateText(selectedDate.getTime()));
    calculateCalendar();
  }

  private void onDayClicked(final java.awt.event.MouseEvent evt) {
    final Label fld = (Label) evt.getSource();
    if (!"".equals(fld.getText())) {
      fld.setBackground(highlight);
      selectedDay = fld;
      selectedDate.set(Calendar.DATE, Integer.parseInt(fld.getText()));
      setVisible(!hideOnSelect);
    }
  }

  private static GregorianCalendar getToday() {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc;
  }

  private void calculateCalendar() {
    if (null != selectedDay) {
      selectedDay.setBackground(white);
      selectedDay = null;
    }
    final GregorianCalendar c = new GregorianCalendar(selectedDate.get(Calendar.
        YEAR), selectedDate.get(Calendar.MONTH), 1);
    final int maxDay = calculateDaysInMonth(c);
    final int selectedDay = Math.min(maxDay, selectedDate.get(Calendar.DATE));
    int dow = c.get(Calendar.DAY_OF_WEEK);
    for (int dd = 0; dd < dow; dd++) {
      daysInMonth[0][dd].setText("");
    }
    int week;
    do {
      week = c.get(Calendar.WEEK_OF_MONTH);
      dow = c.get(Calendar.DAY_OF_WEEK);
      final Label fld = this.daysInMonth[week - 1][dow - 1];
      fld.setText(Integer.toString(c.get(Calendar.DATE)));
      if (selectedDay == c.get(Calendar.DATE)) {
        fld.setBackground(highlight);
        this.selectedDay = fld;
      }
      if (c.get(Calendar.DATE) >= maxDay)
        break;
      c.add(Calendar.DATE, 1);
    }
    while (c.get(Calendar.DATE) <= maxDay); week--;
    for (int ww = week; ww < daysInMonth.length; ww++) {
      for (int dd = dow; dd < daysInMonth[ww].length; dd++) {
        daysInMonth[ww][dd].setText("");
      }
      dow = 0;
    }
    c.set(Calendar.DATE, selectedDay);
    selectedDate = c;
  }

  private static int calculateDaysInMonth(final Calendar c) {
    int daysInMonth = 0;
    switch (c.get(Calendar.MONTH)) {
      case 0:
      case 2:
      case 4:
      case 6:
      case 7:
      case 9:
      case 11:
        daysInMonth = 31;
        break;
      case 3:
      case 5:
      case 8:
      case 10:
        daysInMonth = 30;
        break;
      case 1:
        final int year = c.get(Calendar.YEAR);
        daysInMonth = (0 == year % 1000) ? 29 : (0 == year % 100) ? 28 :
            (0 == year % 4) ? 29 : 28;
        break;
    }
    return daysInMonth;
  }

  private static String formatDateText(final Date dt) {
    final DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
    final StringBuffer mm = new StringBuffer();
    final StringBuffer yy = new StringBuffer();
    final FieldPosition mmfp = new FieldPosition(DateFormat.MONTH_FIELD);
    final FieldPosition yyfp = new FieldPosition(DateFormat.YEAR_FIELD);
    df.format(dt, mm, mmfp);
    df.format(dt, yy, yyfp);
    return (mm.toString().substring(mmfp.getBeginIndex(), mmfp.getEndIndex()) +
            "月 " +
            yy.toString().substring(yyfp.getBeginIndex(), yyfp.getEndIndex()) +
            "年");
  }
}

posted @ 2006-04-27 14:32 Kun Tao's Blog 阅读(268) | 评论 (0)编辑 收藏

2005年10月25日 #

从前,有一座圆音寺,每天都有许多人上香拜佛,香火很旺。在圆音寺庙前的横梁上有个蜘蛛结了张网,由于每天都受到香火和虔诚的祭拜的熏托,蛛蛛便有了佛性。经过了一千多年的修炼,蛛蛛佛性增加了不少。   忽然有一天,佛主光临了圆音寺,看见这里香火甚旺,十分高兴。离开寺庙的时候,不轻易间地抬头,看见了横梁上的蛛蛛。佛主停下来,问这只蜘蛛:“你我相见总算是有缘,我来问你个问题,看你修炼了这一千多年来,有什么真知拙见。怎么样?”蜘蛛遇见佛主很是高兴,连忙答应了。佛主问到:“世间什么才是最珍贵的?”蜘蛛想了想,回答到:“世间最珍贵的是‘得不到’和‘已失去’。”佛主点了点头,离开了。   就这样又过了一千年的光景,蜘蛛依旧在圆音寺的横梁上修炼,它的佛性大增。一日,佛主又来到寺前,对蜘蛛说道:“你可还好,一千年前的那个问题,你可有什么更深的认识吗?”蜘蛛说:“我觉得世间最珍贵的是‘得不到’和‘已失去’。”佛主说:“你再好好想想,我会再来找你的。”   又过了一千年,有一天,刮起了大风,风将一滴甘露吹到了蜘蛛网上。蜘蛛望着甘露,见它晶莹透亮,很漂亮,顿生喜爱之意。蜘蛛每天看着甘露很开心,它觉得这是三千年来最开心的几天。突然, 又刮起了一阵大风,将甘露吹走了。蜘蛛一下子觉得失去了什么,感到很寂寞和难过。这时佛主又来了,问蜘蛛:“蜘蛛这一千年,你可好好想过这个问题:世间什么才是最珍贵的?”蜘蛛想到了甘露,对佛主说:“世间最珍贵的是‘得不到 ’和‘已失去’。”佛主说:“好,既然你有这样的认识,我让你到人间走一朝吧。”   就这样,蜘蛛投胎到了一个官宦家庭,成了一个富家小姐,父母为她取了个名字叫蛛儿。一晃,蛛儿到了十六岁了,已经成了个婀娜多姿的少女,长的十分漂亮,楚楚动人。   这一日,新科状元郎甘鹿中士,皇帝决定在后花园为他举行庆功宴席。来了许多妙龄少女,包括蛛儿,还有皇帝的小公主长风公主。状元郎在席间表演诗词歌赋,大献才艺,在场的少女无一不被他折倒。但蛛儿一点也不紧张和吃醋,因为她知道,这是佛主赐予她的姻缘。   过了些日子,说来很巧,蛛儿陪同母亲上香拜佛的时候,正好甘鹿也陪同母亲而来。上完香拜过佛,二位长者在一边说上了话。蛛儿和甘鹿便来到走廊上聊天,蛛儿很开心,终于可以和喜欢的人在一起了,但是甘鹿并没有表现出对她的喜爱。蛛儿对甘鹿说:“你难道不曾记得十六年前,圆音寺的蜘蛛网上的事情了吗?”甘鹿很诧异,说:“蛛儿姑娘,你漂亮,也很讨人喜欢,但你想象力未免丰富了一点吧。”说罢,和母亲离开了。   蛛儿回到家,心想,佛主既然安排了这场姻缘,为何不让他记得那件事,甘鹿为何对我没有一点的感觉?   几天后,皇帝下召,命新科状元甘鹿和长风公主完婚;蛛儿和太子芝草完婚。这一消息对蛛儿如同晴空霹雳,她怎么也想不同,佛主竟然这样对她。几日来,她不吃不喝,穷究急思,灵魂就将出壳,生命危在旦夕。太子芝草知道了,急忙赶来,扑倒在床边,对奄奄一息的蛛儿说道:“那日,在后花园众姑娘中,我对你一见钟情,我苦求父皇,他才答应。如果你死了,那么我也就不活了。”说着就拿起了宝剑准备自刎。   就在这时,佛主来了,他对快要出壳的蛛儿灵魂说:“蜘蛛,你可曾想过,甘露(甘鹿)是由谁带到你这里来的呢?是风(长风公主)带来的,最后也是风将它带走的。甘鹿是属于长风公主的,他对你不过是生命中的一段插曲。而太子芝草是当年圆音寺门前的一棵小草,他看了你三千年,爱慕了你三千年,但你却从没有低下头看过它。蜘蛛,我再来问你,世间什么才是最珍贵的?”蜘蛛听了这些真相之后,好象一下子大彻大悟了,她对佛主说:“世间最珍贵的不是‘得不到’和‘已失去’,而是现在能把握的幸福。”刚说完,佛主就离开了,蛛儿的灵魂也回位了,睁开眼睛,看到正要自刎的太子芝草,她马上打落宝剑,和太子深深的抱着……   故事结束了,你能领会蛛儿最后一刻的所说的话吗?“世间最珍贵的不是‘得不到’ 和‘已失去’,而是现在能把握的幸福。”
posted @ 2005-10-25 20:14 Kun Tao's Blog 阅读(229) | 评论 (0)编辑 收藏

2005年10月21日 #

     摘要: 2.1.3. 优缺点 优点: 一些开发商开始采用并推广这个框架作为开源项目,有很多先进的实现思想对大型的应用支持的较好有集中的网页导航定义 缺点: 不是业届标准对开发工具的支持不够复杂的taglib,需要比较长的时间来掌握html form 和 actionform的搭配比较封闭,但这也是它的精华所在。 修改建议把actionform属性的设置器和访问器修改成读取或生成xml文档的方法,然后 ht...  阅读全文
posted @ 2005-10-21 20:38 Kun Tao's Blog 阅读(289) | 评论 (0)编辑 收藏

     摘要: 转载说明:本文主要讲述内容:J2EE web架构基线,模型选取以及几个模型的优缺点对比。一、J2EE体系包括java server pages(JSP) ,java SERVLET, enterprise bean,WEB service等技术。怎样把这些技术组合起来形成一个适应项目需要的稳定架构是项目开发过程中一个非常重要的步骤。完成这个步骤可以形成一个主要里程碑基线。1.各种因数初步确定 为了...  阅读全文
posted @ 2005-10-21 20:21 Kun Tao's Blog 阅读(261) | 评论 (0)编辑 收藏

     摘要: 注:目前J2EE的开发工作网络上讨论的热火朝天,各种新技术层出不穷,当然了我们这些新手看的也是一头雾水,感觉的j2ee涉及到的技术太广,各种framework令人眼花缭乱,今天看了这篇介绍性文章,感觉不错,和大家分享一下文章的主要观点。(其中提到的一些技术或规范可能比较老了,主要是学习一下作者的观点) 1.结合商业需求选择合理的架构一般而言,企业信息系统(EIS)都要求自己稳定、安全、可靠、高效、...  阅读全文
posted @ 2005-10-21 19:43 Kun Tao's Blog 阅读(245) | 评论 (0)编辑 收藏

2005年9月21日 #

建立,打包,部署及运行Duke 银行应用程序 
作者:Jimsons
目录
From:http://www.21tx.com/dev/2005/04/23/33123.html
1. 准备工作...
2.    启动服务器...
2.1创建银行数据库...
2.2捕获数据库模式...
2.3创建JDBC数据源...
2.4 将用户和组添加到file域...
3. 编译Duke银行应用程序代码...
4. 打包并部署Duke银行应用程序...
4.1 打包企业Beans.
4.2 打包应用程序客户端...
4.3 打包Web客户端...
4.4 打包并部署应用程序...
5. 运行应用程序客户端Application Client
6. 运行Web客户端...
7. 关于例子源代码中的错误更正...
7.1 NextIdBean代码中的错误...
7.2 Web模块中的错误...
8. 参考资料...  
 
1. 准备工作
假设你的计算机中已经安装了J2EE 1.4 SDK,在建立DUKE银行应用程序之前,你必须到http://java.sun.com/j2ee/1.4/download.html #tutorial下载j2eetutorial压缩包并将其解压缩,假定你解压的路径为<INSTALL>/j2eetutorial14,打开例子的配置文件<INSTALL>/j2eetutorial14/examples/common/build.properties
l         将j2ee.home的值设为你应用程序服务器(Application Server)的安装位置,例如你的应用程序服务器安装在C:/Sun/AppServer,那么你应该设置如下: j2ee.home=C:/Sun/AppServer
l         将j2ee.tutorial.home  的值设置为你j2eetutorial的安装位置,例如: j2ee.tutorial.home=C:/j2eetutorial14
l         假如你安装应用程序服务器的时候管理员的用户名不是用默认的admin,那你要将admin.user的值改为你设置的用户名
l         假如你安装应用程序服务器时不是用默认的8080端口,则要将domain.resources.port的值改为你设置的端口.
l         将<INSTALL>/j2eetutorial14/examples/common/admin-password.txt文件中AS_ADMIN_PASSWORD的值设为你安装应用程序服务器时设置的管理员密码,如: AS_ADMIN_PASSWORD=yourpassword
2.      启动服务器
你必须先启动PointBase数据库服务器并且向数据库中添加客户和帐号的资料,你还要向应用程序服务器中添加一些资源, 最后你才能开始打包,部署和运行例子.
2.1创建银行数据库
你必须先创建数据库并向数据表中输入数据,然后企业Bean才能从中读取或向其中写入数据,请根据以下步骤来创建数据表并输入数据:
1.       启动PointBase数据库服务器
2.       打开命令行,转到<INSTALL>/j2eetutorial14/examples/bank/目录下,执行命令asant create-db_common, 这条命令调用PointBase终端工具库执行<INSTALL>/j2eetutorial14/examples/bank/sql/create-table.sql中的SQL语句, 这些SQL语句的功能是先删除所有已经存在的表并创建新表并向表中插入数据, 因为第一次运行这些语句时这些表并不存在, 所以你会看到一些SQL错误信息,你可以忽略不理这些错误信息.
2.2捕获数据库模式
在创建表并输入数据之后,你可以捕获表间的结构并保存到一个模式文件中,请通过以下步骤来捕获模式:
1.       打开命令行并切换到<INSTALL>/j2eetutorial14/examples/bank/目录
2.       执行以下命令asant capture-db-schema , 执行此命令后生成模式文件<INSTALL>/j2eetutorial14/examples/bank/build/dukesbank.dbschema
2.3创建JDBC数据源
Duke银行的企业Bean用JNDI名jdbc/BankDB来引用数据库,请执行以下步骤:
1.       打开管理终端页面http://localhost:4848/asadmin
2.       展开JDBC分支,选择JDBC Resources, 选择 New
3.       将其命名为jdbc/BankDB并将它映射到 PointBasePool
2.4 将用户和组添加到file域
将用户和组添加到file安全域后,应用程序服务器就能判断哪些用户能访问Web客户端的企业Bean的方法和资源,添加的步骤如下:
1.       打开管理终端页面http://localhost:4848/asadmin
2.       展开Configuration分支并展开Security分支
3.       展开Realms分支并选中file域
4.       点击Manage Users并点击New
5.       根据下表输入Duke银行的用户和组
User
Password
Group
200
j2ee
bankCustomer
bankadmin
j2ee
bankAdmin
 
3. 编译Duke银行应用程序代码
打开命令行,转到<INSTALL>/j2eetutorial14/examples/bank/目录,执行命令asant build ,这个命令就编译了企业Bean,应用程序客户端和Web客户端的全部代码,编译后的代码位于<INSTALL>/j2eetutorial14/examples/bank/build目录下.
4. 打包并部署Duke银行应用程序
以下过程假设你对用部署工具打包企业Bean, 应用程序客户端和Web应用程序的过程都比较熟悉,下面介绍如何打包并部署Duke银行(如果你按照以下步骤做了之后,部署或运行此应用程序还存在问题,那你可以用我们在<INSTALL>/j2eetutorial14/examples/bank/provided-jars/ 目录下提供的EAR文件即打包好的文件来部署和运行这个例子)
4.1 打包企业Beans
1.       创建一个EJB JAR模块并命名为DukesBankEJBJAR ,将其保存到<INSTALL>/j2eetutorial14/examples/bank/目录下.
2.       添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目录下的ejb和util包, 还有 <INSTALL>/j2eetutorial14/examples/bank/build/目录下的dukesbank.dbschema文件.
3.       创建实体Beans(选择添加到DukesBankEJBJAR中)
a. 用企业Bean向导创建下面每个表格中的CMP2.0 (容器管理持久性) 企业bean:
 
AccountBean的设置如下表:
Setting
Value
Local Home Interface
LocalAccountHome
Local Interface
LocalAccount
Persistent Fields
accountId, balance, beginBalance, beginBalanceTimeStamp, creditLine, description, type
Abstract Schema Name
AccountBean
Primary Key Class
Existing field accountId
CustomerBean的设置如下表:
 
Setting
Value
Local Home Interface
LocalCustomerHome
Local Interface
LocalCustomer
Persistent Fields
city, customerId, email, firstName, lastName, middleInitial, phone, state, street, zip
Abstract Schema Name
CustomerBean
Primary Key Class
Existing field customerId
TxBean的设置如下表:
 
Setting
Value
Local Home Interface
LocalTxHome
Local Interface
LocalTx
Persistent Fields
amount, balance, description, timeStamp, txId
Abstract Schema Name
TxBean
Primary Key Class
Existing field txId
NextIdBean的设置如下表:
 
Setting
Value
Local Home Interface
LocalNextIdHome
Local Interface
LocalNextId
Persistent Fields
beanName, id
Abstract Schema Name
NextIdBean
Primary Key Class
Existing field beanName
 
4. 根据下表建立实体bean的关系:
 
Multi-plicity
Bean A
Field Referencing Bean B and Field Type
Bean B
Field Referencing Bean A and Field Type
*:*
AccountBean
customers, java.util.Collection
CustomerBean
accounts, java.util.
Collection
1:*
AccountBean
none
TxBean
account
 
b. 在Sun-specific SettingsàCMP Database 对话框
1.       将JNDI名字命名为jdbc/BankDB
2.       点击Create Database Mappings,选中Map to Tables in Database Schema File并从下拉列表中选择dukesbank.dbschema,如下图所示
3.       每选择一个企业bean,下方就会显示持久域的映射, 请确认那些域和关系.
c. 根据下表为finder设置EJB QL查询语句
 
Duke银行中的finder查询
Enterprise Bean
Method
EJB QL Query
AccountBean
findByCustomerId
select distinct object(a)
from AccountBean a, in (a.customers) as c
where c.customerId = ?1
CustomerBean
findByAccountId
select distinct object(c)
from CustomerBean c, in (c.accounts) as a
where a.accountId = ?1
CustomerBean
findByLastName
select object(c)
from CustomerBean c
where c.lastName = ?1
TxBean
findByAccountId
select object(t)
from TxBean t
where t.account.accountId = ?3
and (t.timeStamp >= ?1 and t.timeStamp <= ?2)
d. 在NextIdBean的Transaction标签中,将 NextIdBean.getNextId 方法的Transaction Attributes属性设置为Requires New.
 
5. 调用企业Bean向导创建下表中的stateful session beans(即有状态会话bean)
 
Session Bean
Home Interface
Remote Interface
Implementation Class
Account
ControllerBean
Account
ControllerHome
Account
Controller
AccountControllerBean
Customer
ControllerBean
Customer
ControllerHome
Customer
Controller
CustomerControllerBean
TxControllerBean
TxControllerHome
TxController
TxBean
    
a.       根据下表列出的添加session beans 到local entity beans 的EJB references即EJB引用.
 
EJB References in AccountControllerBean
Coded Name
EJB Type
Interfaces
Home Interface
Local Interface
Enterprise Bean Name
ejb/account
Entity
Local
Local
AccountHome
LocalAccount
AccountBean
ejb/
customer
Entity
Local
Local
CustomerHome
LocalCustomer
CustomerBean
ejb/nextId
Entity
Local
Local
NextIdHome
LocalNextId
NextIdBean
EJB References in CustomerControllerBean
Coded Name
EJB Type
Interfaces
Home Interface
Local Interface
Enterprise Bean Name
ejb/customer
Entity
Local
Local CustomerHome
Local
Customer
CustomerBean
ejb/nextId
Entity
Local
Local
NextIdHome
Local
NextId
NextIdBean
EJB References in TxControllerBean
Coded Name
EJB Type
Interfaces
Home Interface
Local Interface
Enterprise Bean Name
ejb/account
Entity
Local
Local
AccountHome
Local
Account
AccountBean
ejb/
tx
Entity
Local
Local
TxHome
LocalTx
TxBean
ejb/nextId
Entity
Local
Local
NextIdHome
Local
NextId
NextIdBean
 
b.       将所有session bean的Transaction Management设置为Container-Managed即容器管理
6.       保存这个模块
 
4.2 打包应用程序客户端
       1. 调用 Application Client 向导
a.      创建一个应用程序客户端模块,将它命名为DukesBankACJAR并把它保存到<INSTALL>/j2eetutorial14/examples/bank/目录下
b.      添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目录下的appclient, util, ejb/exception包和 ejb/*/*Controller* 即home和远程接口文件(即AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) 到JAR中.
c.       选择appclient.BankAdmin 作为应用程序客户端的main class (主类)
2. 根据下表添加对session bean的EJB 引用
Coded Name
EJB Type
Interface
JNDI Name of Session Bean
ejb/accountController
Session
Remote
AccountControllerBean
ejb/customerController
Session
Remote
CustomerControllerBean
3. 保存这个模块.
4.3 打包Web客户端
1.      通过Web Component向导创建一个web模块,命名为DukesBankWAR并保存到<INSTALL>/j2eetutorial14/examples/bank/目录下,选择Dispatcher 作为Servlet类,其它保持默认.
2.      添加以下内容到web模块中
a.      添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目录下的web, util, ejb/exception包和 ejb/*/*Controller* 即home和远程接口文件(即AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) 到模块中.
b.      添加<INSTALL>/j2eetutorial14/examples/bank/build/目录下的template目录,所有的jsp页面,所有的WebMessages*.properties文件和tutorial-template.tld文件到模块中.
c.       在添加文件的对话框中将WebMessages*.properties文件从根目录拖到WEB-INF/classes目录下,如下图
 
3.      将context root 设置为 /bank
4.      打开Dispatcher组件的Aliases标签, 添加/accountHist, /accountList, /atm, /atmAck, /main, /transferAck, /transferFunds, and /logoff作为aliases
5.      添加下表列出的session bean对EJB 的引用
Coded Name
EJB Type
Interface
JNDI Name of Session Bean
ejb/accountController
Session
Remote
AccountControllerBean
ejb/customerController
Session
Remote
CustomerControllerBean
ejb/txController
Session
Remote
TxControllerBean
6.      在标签JSP property添加名为bank的组,这个组对应的URL pattern(URL模式)为*.jsp,添加/template/prelude.jspf 到include prelude 中
7.      在Context标签,添加参数名为javax.servlet.jsp.jstl.fmt.localizationContext,值为WebMessages.
8.      在Security标签添加安全控制
a. 选择Form Based作为user authentication方法,在authentication设置中将realm的值设置为file, login page (登录页) 设置为/logon.jsp, error page (错误页)设置为/logonError.jsp.
b. 添加一个security constraint和web resource collection, 用deploytool提供的默认名称
c. 在web resource collection.中添加URL Patterns(URL模式): /main, /accountList, /accountHist, /atm, /atmAck, /transferFunds, 和 /transferAck
d. 选中HTTP方法POST和GET.
e. 添加安全角色(authorized role ) bankCustomer
       9. 保存这个模块
 
4.4 打包并部署应用程序
1.      创建一个J2EE application(J2EE应用程序), 将它命名为DukesBankApp,并保存到<INSTALL>/j2eetutorial14/examples/bank/目录下
2.     添加DukesBankACJAR应用程序客户端模块到DukesBankApp
3.     添加DukesBankEJBJAR即EJB模块到DukesBankApp
4.     添加DukesBankWAR即Web模块到DukesBankApp
5.     添加安全角色(security roles) 名为 bankAdminbankCustomer
6.     为企业bean添加以下的安全设置(security settings)
a.     AccountControllerBean:在Security标签,将方法removeCustomerFromAccount, removeAccount, createAccount, 和 addCustomerToAccount的限制访问权限的安全角色为bankAdmin ;在General标签, 点击Sun-specific Settings,然后在弹出的对话框中点击IOR, 在Context对话框将Required设置为true, 将realm设置为file.
b.     CustomerControllerBean: 在Security标签,将方法getCustomersOfAccount, createCustomer, getCustomersOfLastName, setName, removeCustomer, 和 setAddress的限制访问权限的安全角色为bankAdmin ;在General标签, 点击Sun-specific Settings,然后在弹出的对话框中点击IOR, 在Context对话框将Required设置为true, 将realm设置为file.
c.     TxControllerBean:在Security标签,将方法getTxsOfAccount, makeCharge, deposit, transferFunds, withdraw, 和 makePayment的限制访问权限的安全角色为bankCustomer
7.     如果你还没有启动应用程序服务器(Application Server.)那你现在就启动它.
8.     将bankCustomer角色映射到bankCustomer组
9.     将bankAdmin角色映射到bankAdmin组
10.  保存这个应用程序模块
11.  Deploy(部署)这个应用程序,在部署kesBankApp对话框选中Return Client Jar即返回客户端Jar选项.
12.  在deploytool中选中server,将右边出现的bank选中并启动它.
5. 运行应用程序客户端Application Client
请根据以下步骤来运行应用程序客户端:
1.           打开命令行,转到<INSTALL>/j2eetutorial14/examples/bank/目录下
2.           如果是要运行英文版本的客户端就输入以下命令:        appclient -client DukesBankAppClient.jar
DukesBankAppClient.jar这个文件是你刚才部署时选中返回客户端JAR而返回的文件.
3.           如果想运行西班牙语版本的客户端则运行以下命令:
appclient -client DukesBankAppClient.jar es
4.           在弹出的登录框中,输入用户名bankadmin密码为 j2ee,然后你就可以看到以下的界面.
 
6. 运行Web客户端
请根据以下步骤来运行Web客户端
1.     请在浏览器中打开地址http://localhost:8080/bank/main ,如果查看西班牙版本的客户端则只需在浏览器的语言设置中更改.
2.     在登录页面,输入用户名200,密码j2ee并提交.
3.     当你选择Account List,则你会看到以下画面.
 
7. 关于例子源代码中的错误更正
       7.1 NextIdBean代码中的错误
    此错误会造成部署发生错误不能完成,将<INSTALL>/j2eetutorial14/examples/bank/src/com/sun/ebank/ejb/util/目录下的NextIdBean.java文件打开,找到下面这行代码
public Object ejbCreate() throws CreateException {
将方法ejbCreate()的返回类型由Object更改为String,再重新编译,并在deploytool中更新此文件,重新部署即可成功
       7.2 Web模块中的错误
    打开Web客户端,输入用户名密码然后提交可能会抛出javax.servlet.jsp.JspTagException错误,请根据以下步骤进行更正:
        1. 用文本编辑器新建java文档命名为CustomerHackFilter,保存到<INSTALL>/j2eetutorial14/examples/bank/src/com/sun/ebank/web目录下,内容如下:
package com.sun.ebank.web;
 
import javax.servlet.*;
import javax.servlet.http.*;
import com.sun.ebank.util.Debug;
import com.sun.ebank.web.*;
import java.io.IOException;
 
/**
 * this is a dumb hack.  update 4 seems to broken unless a
 * CustomerBean is placed in the request linked to the BeanManager.
 * Naturally, we need to add a BeanManager to the session here,
 * doing some of the work the dispatcher should have done.
 */
public class CustomerHackFilter  implements Filter
{
    private FilterConfig filterConfig = null;
        public void init(FilterConfig filterConfig)
        throws ServletException
    {
        this.filterConfig = filterConfig;
    }
 
    public void destroy() {
        this.filterConfig = null;
    }
 
    public void doFilter(ServletRequest req, ServletResponse response,
                         FilterChain chain)
        throws IOException,
               ServletException
    {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpSession        session = request.getSession();
 
        BeanManager beanManager =
            (BeanManager) session.getAttribute("beanManager");
 
        if (beanManager == null) {
            Debug.print("hack - Creating bean manager.");
            beanManager = new BeanManager();
            session.setAttribute("beanManager", beanManager);
        }
 
        CustomerBean customerBean = new CustomerBean();
        customerBean.setBeanManager(beanManager);
        request.setAttribute("customerBean", customerBean);
        Debug.print("hack - added customerBean to request");
 
        chain.doFilter(request, response);
    }
}
   2. 重新编译源代码
   3. 选中DukesBankWAR模块,编辑内容,找到com/sun/ebank/web/ CustomerHackFilter.class,将它添加到包中.
   4. 选中DukesBankWAR模块,在Filter Mapping标签,点击Edit Filter List,在弹出的对话框中点击Add Filter,在Filter Class下拉列表中选中com.sun.ebank.web.CustomerHackFilter,Filter Name为CustomerHack,选择OK
   5. 还是在这个标签在,点击Add,弹出 “Add Servlet Filter Mapping”,在Filter Name下拉列表中选CustomerHack,下面选中 “Filter this Servlet”,选OK,如下图.
   6. 保存这个模块并重新部署运行即可修正错误
posted @ 2005-09-21 19:44 Kun Tao's Blog 阅读(427) | 评论 (0)编辑 收藏

2005年9月17日 #

Duke执行环境:
1.J2SE JDK;(download from :http://java.sun.com/j2se/download.html#sdk)
2.J2EE JDK;(download from :http://java.sun.com/j2ee/download.html#sdk)
3.Ant;(download from:http://jakarta.apathe.org/builds/jakarta-ant)
4.Structs;(download from:http://jakarta.apathe.org/builds/jakarta-structs)
5.J2ee Tutorial;(download from :http://java.sun.com/j2ee/download.html#tutorial)
环境配置:
1.略
2.J2EE运行环境的搭建

开发企业级的应用程序需要搭建好J2EE的运行环境。其实也就是到SUN公司的网站上去DOWNJ2EE 1.4 SDK开发工具包。然后双击安装文件,如果你下载的版本与我的一样。那么这个安装文件就会是这个名字:j2eesdk-1_4-dr-windows-eval.exe。同样的我们也将J2EE SDK安装在C盘根目录下。

需要特别提醒大家的是:J2EE运行环境的搭建是以J2SE运行环境的搭建为基础的。其实想也想得到为什么。如果没有JDK,哪里来的编译和运行命令呢(JAVAjavac)。安装完J2EE 1.4 SDK包后,具体的设置与测试步骤如下:

1、  首先右往PATH变量里添加J2EE SDKBIN目录。如:C:\j2sdkee1.3.1\bin。如何往里面添加,前面已经讲过。

2、  然后新建两个变量:一个是JAVA_HOME,变量值为:JDK的安装目录。另一个是J2EE_HOME,变量值为J2EE SDK的安装目录。如图示:
3、  最后往CLASSPATH变量里添加一个关键的JAR包。它就是J2EE.JAR包。比如我添加的就是:C:\j2sdkee1.3.1\lib\j2ee.jar

4、  所有的工作做完以后。大家可以通过以下方式验证一下我们的J2EE环境是否已经搭建成功。在命令提示符状态下输入命令:J2EE Verbose。如果屏幕的最下面看到了这样一句话J2EE server startup complete.那就表示J2EE服务器成功启动了。在我们的J2EE程序要布署和运行的过程中。服务器将一直启动着。

另外提一下,如果你需要停止J2EE服务器,必须再开一个命令窗口,并运行如下命令:J2EE –STOP。成功运行后,将会有提示语句。再去看看启动服务器的那个窗口,你将可以看到提示符了。

5、  这样做了还不够,我们还需要到网页里去测试一下服务器默认页面是否能够正常显示,这样才能保证我们能够进WEB程序的开发。双击IE浏览器的图标,在地址栏里输入:http://localhost:8000,如果你能看到以下窗口中的内容,那就说明你的J2EE环境已经搭建成功。需要说明一点,在localhost:后的是J2EE服务器提供的WEB服务端口号。

需要提醒大家的是:当你打开网页之前,确认你的J2EE服务器是启动着的。如果你机器上没有安装网卡,或是网卡安装不正确,也会导致无法打开J2EE服务器默认页面。

 

posted @ 2005-09-17 20:47 Kun Tao's Blog 阅读(641) | 评论 (0)编辑 收藏

2005年7月19日 #

常用的ant的操作

常用的ant的操作,方便自己查询,所以传到网上,如果有朋友觉得不够,请补充:
主要的内容有

  (1)建立一个项目
  (2)建立属性
  (3)对数据库的操作
  (4)javac编译
  (5)删除目录
  (6)建立目录
  (7)拷贝文件群
  (8)jar为一个包
  (9)拷贝单个文件
  (10)运行
有更多更好的常用的,我没想到的,希望大家补充。  
  
<!--(1)建立一个项目,默认的操作为target=all. -->
<project name="proj" default="all" basedir=".">

  <!--(2)建立一些属性,以供下边的操作用到 -->
  <property name="root"  value="./" />
  <property name="deploy_path"  value="d:/deploy" />
  <property name="srcfile"  value="d:/srcfile" /> 
 
  <target name="all" depends="compile,deploy"/>
 
  <!--(3)对数据库的操作 demo.ddl中写的是sql语句 driver,url,userid,password随具体情况设置--> 
  <!-- Oracle -->
  <target name="db_setup_oracle" description="Database setup for Oracle">
    <antcall target="check_params_results"/>
    <sql driver="oracle.jdbc.driver.OracleDriver"
       url="jdbc:oracle:thin:@192.168.0.1:1521:oa"
       userid="oa" password="oa"
       onerror="continue"
       print="yes"
       src="./demo.ddl"/>
  </target>

  <!--(4)javac编译 --> 
  <target name="compile">  
    <javac srcdir="${srcfile}"
      destdir="${root}/oa/"
      includes="*.java"
      classpath="${CLASSPATH};${CLIENT_CLASSES}/utils_common.jar"   <!--CLASSPATH和CLIENT_CLASSES是环境变量-->
    />
  </target>
 
  <target name="deploy" depends="compile">
    <!-- Create the time stamp -->
    <tstamp/>
   
    <!--(5)删除目录-->   
    <!--(6)建立目录-->

    <delete dir="${root}/dist/"/>   
    <mkdir dir="${root}/dist/"/>      

    <delete dir="${deploy_path}"/>   
    <mkdir dir="${deploy_path}"/>    
 
    <!--(7)拷贝文件群-->
    <copy todir="${root}/dist/">    
            <fileset dir="${root}/oa/">
                <include name="*.class"/>
            </fileset>
    </copy&g

posted @ 2005-07-19 16:56 Kun Tao's Blog 阅读(204) | 评论 (0)编辑 收藏

2005年7月13日 #

The Java interpreter proceeds as follows. First, it finds the environment variable CLASSPATH (set via the operating system, and sometimes by the installation program that installs Java or a Java-based tool on your machine). CLASSPATH contains one or more directories that are used as roots in a search for .class files. Starting at that root, the interpreter will take the package name and replace each dot with a slash to generate a path name from the CLASSPATH root (so package foo.bar.baz becomes foo\bar\baz or foo/bar/baz or possibly something else, depending on your operating system). This is then concatenated to the various entries in the CLASSPATH. That’s where it looks for the .class file with the name corresponding to the class you’re trying to create. (It also searches some standard directories relative to where the Java interpreter resides).
posted @ 2005-07-13 15:08 Kun Tao's Blog 阅读(286) | 评论 (0)编辑 收藏

ps:from Thinking in Java chapter 4

Consider a class called Dog:

  1. The first time an object of type Dog is created (the constructor is actually a static method), or the first time a static method or static field of class Dog is accessed, the Java interpreter must locate Dog.class, which it does by searching through the classpath. 
  2. As Dog.class is loaded (creating a Class object, which you’ll learn about later), all of its static initializers are run. Thus, static initialization takes place only once, as the Class object is loaded for the first time. 
  3. When you create a new Dog( ), the construction process for a Dog object first allocates enough storage for a Dog object on the heap. 
  4. This storage is wiped to zero, automatically setting all the primitives in that Dog object to their default values (zero for numbers and the equivalent for boolean and char) and the references to null
  5. Any initializations that occur at the point of field definition are executed. 
  6. Constructors are executed. As you shall see in Chapter 6, this might actually involve a fair amount of activity, especially when inheritance is involved.
posted @ 2005-07-13 09:22 Kun Tao's Blog 阅读(215) | 评论 (0)编辑 收藏

仅列出标题  下一页