一个猴子扮苞谷的程序

先写点习作熟悉一下JAVA的工作

class monky

{

int[] goods = new int[100];

//getGood作为litte monky的行为成员

void getGood(int good,int i)

{

goods[i] = good;

}

//开始计算扳了多少

void count()

{

int all =0;

for(int i=0;i<100;i++)

{

all = all+goods[i];

  System.out.print(goods[i]+",");

}

  System.out.println(" ");

  System.out.print("总重:"+all);

}

}

class monkyPlay

{

public static void main(String[] args)

{

  monky mk = new monky();

for(int i=0;i<100;i++)

//随机产生不同重量的苞谷

  mk.getGood((int)(Math.random()*3000),i); 

  mk.count();  

}

}

从一段小程序重新认识自己

这次主要是看如果自己现在就开始动手写,最多能够写到哪一步,于是随便找了一个Clock 的代码,一边抄写一边理解,

这是我的学习方法,并不要求全部搞懂,但是每一步所完成的功能要知道,然后对照自己过去的编程经验,期望能够找到自己现在的水平在哪里!

下面是学习过程

import java.applet.*;

import java.awt.event.*;

import java.awt.*;

import javax.swing.*;

import java.util.*;

import java.io.*;

import java.awt.geom.*;

import java.awt.image.*;

public class Clock extends Applet implements Runnable, MouseListener,

ActionListener {

//写到这里发现这个Clock居然是Applet的子类,遇到看不明白的当然是手册伺候了,

//翻阅资料发现这个所谓Applet在JDKdom中的介绍为

//"是一种不适合单独运行但可嵌入在其他应用程序中的小程序。"完全看不懂

//而他的定义是public class Applet extends Panel ,^_^居然是Panel的子类

//这样我大概知道了这个Applet应该是一个容器类

//再看这家伙的方法,哇一大堆url,Image一看就是个html像,我心里合计,

//小样!别以为改了名字爷就认不 出你了。

//现在前面看明白了,implements就又有点不了了,决定先放一下,不求甚解从来就是

//本人的优良品德之一。

Image image,image1;

Toolkit tool;

JPanel panel;

Graphics gg;

int width,height,width1,height1;

Thread thread,thread2;

MediaTracker m;

double angel1=0,angel2=0;

int xsec,ysec,xsec2,ysec2,xmin,ymin,xmin2,ymin2,xhou,yhou,xhou2,yhou2;

int c = 0,xstr = 235,ystr = 253;

int y = ystr;

JButton button1 = new JButton();

JButton button2 = new JButton();

JButton button3 = new JButton();

JButton button4 = new JButton();

AudioClip music;

Color colorh = Color.GREEN,colorm= Color.BLACK,colors= Color.YELLOW;

String[] string = new String[5];

int kk = 0;

//上面一大堆罗里吧索的终于结束了

public void init()

{

//等会这个init咋那么眼熟,好像在哪里见过,哦。。。。。

//Applet方法成员之一,立即手册之,

//"由浏览器或 applet viewer 调用,通知此 applet 它已经加载到系统中。"

//看这个意思有点像把主对象容器初始化。

this.setLayout(new BorderLayout());

this.setBackground(Color.BLACK);

tool = getToolkit();

//到这里又看不懂了,怎么getToolkit()既没有对象也没有参数的,这样也可以啊!

//不管了接着看吧

image = tool.getImage("image.PNG");

//看吧PNG网页的东东来了吧

        m = new MediaTracker(this);

        m.addImage(image,0);

        try

        {

        m.waitForID(0);

        }

        catch(Exception e)

        {

        System.out.println(e.getMessage());

        }

//怎么多媒体也出来了,这个倒霉的程序员,没办法手册依旧

//MediaTracker 类是一个跟踪多种媒体对象状态的实用工具类

//要使用媒体跟踪器,需要创建一个 MediaTracker 实例,

//然后对每个要跟踪的图像调用其 addImage 方法。

//另外,还可以为每个图像分配一个惟一的标识符。

//此标识符可控制获取图像的优先级顺序。它还可用于标识可单独等待的惟一图像子集。

//具有较低 ID 的图像比具有较高 ID 的图像优先加载。

//这样后面的都大概看明白了,就是加载了一张图片。

//不由大呼,不愧是JAVA这样简单的操作也搞的如此复杂,偶喜欢。

        width1 = image.getWidth(this);

        height1 = image.getHeight(this);

        width = this.width;

        height = this.height;

//这两句有区别吗?

        this.addMouseListener(this);

//姑且认为是在主容器上添加一个作用于主容器的鼠标事件吧

        button1.setText("时针颜色");

        button1.addActionListener(this);

        button2.setText("分针颜色");

        button2.addActionListener(this);

        button3.setText("秒针颜色");

        button3.addActionListener(this);

        button4.setText("选择皮肤");

        button4.addActionListener(this);

        button1.setBackground(Color.BLACK);

        button1.setForeground(Color.WHITE);

        button2.setBackground(Color.BLACK);

        button2.setForeground(Color.WHITE);

        button3.setBackground(Color.BLACK);

        button3.setForeground(Color.WHITE);

        button4.setBackground(Color.BLACK);

        button4.setForeground(Color.WHITE);

//为什么Color后颜色成员有大小写区分哪?

        JPanel panel = new JPanel();

//手册:JPanel 是一般轻量级容器。不解

        panel.setBackground(Color.BLACK);

        panel.setLayout(new FlowLayout(FlowLayout.CENTER));

        panel.add(button1);

        panel.add(button2);

        panel.add(button3);

        panel.add(button4);

        this.setLayout(new BorderLayout());

        this.add(panel,BorderLayout.SOUTH);

        string[0] = "时间就像海绵里水";

        string[1] = "只要挤总会有的";

        string[2] = "珍惜身边每一个人";

        string[3] = "因为随着岁月流逝,";

        string[4] = "他们将......";

//你不当程序员你还想当诗人啊!

//我有这样想过啊

//省省吧,好好做你这个程序员这么有前途的职业去吧。

        image1 = createImage(getWidth(),getHeight()-35);

//又是一句没头没脑的东西。

        gg = image1.getGraphics();

}

public void start()

{

//亲娘耶,这就开始了?

        if (thread == null)

        {

        thread = new Thread(this);

        thread.start();

        }

        if (thread2 == null)

        {

        thread2 = new Thread(new thread2());

//new一个new的自己??

        thread2.start();

        }

}

public void paint(Graphics g)

{

super.paint(g);

g.drawImage(image1,0,0,this);

Date date = new Date();

int hour = date.getHours();

int min = date.getMinutes();

int sec = date.getSeconds();

String m = Integer.toString(hour)+":"+Integer.toString(min)+":"

  + Integer.toString(sec);

//好像这样也可以 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

//               String m = sdf.format(date);

        double ans = (Math.PI/30)*min;

        double anm = (3.1415926535897931D /30)*min;

        double anh = ((hour +min/60.0)*(2*Math.PI/12));

        xsec2 = 172 + (int) (45 * Math.sin(ans));

        ysec2 = 165 - (int) (45 * Math.cos(ans));

        xsec = 172 - (int) (13 * Math.sin(ans));

        ysec = 165 + (int) (13 * Math.cos(ans));

        xmin2 = 172 + (int) (40 * Math.sin(anm));

        ymin2 = 165 - (int) (40 * Math.cos(anm));

        xmin = 172 - (int) (10 * Math.sin(anm));

        ymin = 165 + (int) (10 * Math.cos(anm));

        xhou = 172 + (int) (30 * Math.sin(anh));

        yhou = 165 - (int) (30 * Math.cos(anh));

        xhou2 = 172 - (int) (10 * Math.sin(anh));

        yhou2 = 165 + (int) (10 * Math.cos(anh));

        g.setColor(colors); //秒针

        g.drawLine(xsec, ysec, xsec2, ysec2);

        g.setColor(colorm); //分针

        g.drawLine(xmin, ymin, xmin2, ymin2);

        g.setColor(colorh); //时针

        g.drawLine(xhou2, yhou2, xhou, yhou);

        g.setColor(Color.RED);

    g.fillOval(169,162,9,9);

    g.drawString(m,150,100);

    g.setColor(Color.RED);

    g.drawString(string[0], xstr, y);

        g.drawString(string[1], xstr, y + 20);

        g.drawString(string[2], xstr, y + 40);

        g.drawString(string[3], xstr, y + 60);

        g.drawString(string[4], xstr, y + 80);

}

public void update(Graphics g)

{

paint(g);

}

/**

* Method main

*

*

* @param args

*

*/

public static void main(String[] args) {

// TODO: Add your code here

}

/**

* Method run

*

*

*/

public void run() {

// TODO: Add your code here

while (true)

//这个true在这里有意义吗?

{

try

{

thread.sleep(1000);

gg.setColor(Color.WHITE);

gg.fillRect(0,0,width,height);

gg.drawImage(image,110,110,width1,height1,this);

repaint();

}

catch (Exception e)

{

System.out.print(e.getMessage());

}

}

}

    private class thread2 implements Runnable

    {

//前面已经有个thread2了,这里有冒出来一个,而且是Runnable接口

//前面那个thread2是Thread类

//难道纯属于该程序员在练习两种线程的创建方法吗?这个问题先放一放

    public void run()

    {

    while (true)

    {

    try

    {

    thread2.sleep(1000);

    }

    catch(Exception e)

    {

    }

    y--;

    if (y<=5)

    {

    y=ystr;

    }

    repaint();

    }

    }

    }

//一堆鼠标事件

public void mouseClicked(MouseEvent e) {

// TODO: Add your code here

System.out.print(e.getX());

        System.out.print(e.getY());

}

public void mousePressed(MouseEvent e) {

// TODO: Add your code here

}

public void mouseReleased(MouseEvent e) {

// TODO: Add your code here

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void fileSelect()

{

JFileChooser choose = new JFileChooser();

//为用户选择文件提供了一种简单的机制

choose.setFileSelectionMode(JFileChooser.FILES_ONLY);

choose.setCurrentDirectory(new File("."));

//new File(".")?????????

        choose.setFileFilter(new javax.swing.filechooser.FileFilter()

        {

        public boolean accept(File file)

        {

        String name = file.getName().toLowerCase();

        return name.endsWith(".gif")||name.endsWith(".jpg")

        ||name.endsWith(".jpeg")||file.isDirectory();

        }

        public String getDescription()

        {

        return "图片文件";

        }

        });

//这里看起来java程序的组件应该全都是动态创建的了。难怪很难写。

        int result = choose.showOpenDialog(this);

        String name = null;

        if(result == JFileChooser.APPROVE_OPTION)

        {

        name = choose.getSelectedFile().getAbsolutePath();

        }

        image = tool.getImage(name);

        m.addImage(image,0);

        try{

        m.waitForAll();

        } catch (Exception e){

        System.out.print(e.getMessage());

        }

}

public void actionPerformed(ActionEvent e) {

// TODO: Add your code here

   if(e.getSource() == button1||e.getSource()==button2||e.getSource() ==button3){

   JColorChooser Choose = new JColorChooser();

   }

}

}

写到这里,机器中病毒了,而且自己也觉得没必要再继续写下去了

所有看不懂的一概跳过,最后发现还是从头学比较好

开始构思学习日记的BLOG视图设计

我已经在学习日记的开源社区的问题跟踪系统提交这个任务20,简述如下:


现在我们程序展现的仅是一个BBS视图。我认为,一个目标,首先是个人的目标,然后才是大家的共同

目标。

  所以,创建学习日记的BLOG视图。BLOG中的一个分类也是一个BBS中的论坛版块。我想,这个工作需

要一些时间来做。它将采用ArgoUML来设计。

这个想法起源于一位网友javar的建议:http://www.learndiary.com/disGoalContentAction.do?goalID=1287

已经完成的添加私人目标和日记的支持也来自他的建议。http://www.learndiary.com/disDiaryContentAction.do?goalID=2086

本站添加帖子中上传文件及图片功能

如:

上传文件:

附件:decomp.zip,575 bytes

上传图片:

普通用户上传限制:

上传文件不大于200K,文件扩展名限于:"zip", "rar", "gif", "jpg", "jpeg", "png";除图片文件,请把非"zip"、"rar"的文件(含压缩文件)用"zip"、"rar"重新压缩一遍上传;本站不对上传文件查毒,请自行负责文件的安全性。

本上传程序是在Struts上传文件例程的基础上并借鉴了http://www.matrix.org.cn的上传页面源文件改写而成。

JSP和JavaScirpt数据交互(转)

(转自:http://www.java3z.com/cwbwebhome/article/article5/5585.jsp?id=912

JSP和JavaScirpt数据交互 点击观看演示

   下载源代码

 

〖 作者:不详 〗〖 大小:2k 〗〖 发布日期:2006-05-31 〗〖 浏览:118 〗

 

 

       对于WEB程序来说,前端(JavaScript)和后端(JSP/Servlet)是没法共用数据的,只能是后端程序(JSP)把数据输出,生成页面到前端,这时候生成的页面中的JavaScript代码才有可能得到所谓jsp的数据。同样的,只有把JavaScript里的数据提交给后端JSP代码,JSP程序中才能得到JavaScript的数据。

    那如何实现在页面的JavaScript中使用jsp中的数据或是在jsp中使用页面的JavaScript数据呢?

一、页面中的JavaScript的数据如何提交给后台的jsp程序

    ① 可以将JavaScript的数据以xxx.JSP?var1=aaa&var2=bbb的形式作为URL的参数传给JSP程序,此时在jsp中用

<%String strVar1=request.getParameter("var1");%>就可以获取到JavaScript脚本传递过来的数据;

    ② 使用JavaScript通过在表单里加入隐藏域信息,然后用表单提交的方式把数据传递给JSP程序。

 

 

二、页面中的JavaScript的数据如何使用后台的JSP程序的数据

    这个比较简单,直接在JavaScript脚本中用<%=strVar1%>就可以把jsp程序中的数据传递给JavaScript脚本使用了。

三、参考下面例子:

1、test.jsp

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

<%

  String s1="Hello ";

  String s2="World!!";

%>

<script language="JavaScript">

<!--

/***************************************************************

* JavaScript脚本,放置在页面中的任何位置都可以

* insertclick()函数获取JSP传递到页面中的变量s1,

* 然后就可以在JavaScript中修改这个变量的值,再通过

* post的方式提交给JSP程序来使用。

***************************************************************/

function insertclick(){

  var1 ="<%=s1 %>";

  document.forms["insertForm"].mc.value = var1 + document.forms["insertForm"].mc.value ;

  document.insertForm.submit();

}

//-->

</script>

<!-- html页面form表单,放置在html页面中的位置不限 -->

<form name="insertForm" method="post" action="get.jsp">

<!-- 下面这一句是获取JSP程序中传递过来的变量值 -->

<input type="hidden" name="mc" value="<%=s2 %>">

<input type="button" value="提交" onclick="insertclick()">

</form>

2、get.jsp

<%

  String strVar1=request.getParameter("mc");

  out.print(strVar1);

%>

 

iframe的用法(转帖2篇)

(转自:http://www.webshu.com/tutorial/tor/7,id=0408.htm

iframe嵌入网页的用法作者:自由勇点击:MT-8000最后更新 2003-10-12

iframe并不是很常用的,在标准的网页中非常少用。但是有朋友经常问到,下面我简单地介绍一下它的用法,你只要熟练掌握这些参数足矣。

<iframe>也应该是框架的一种形式,它与<frame>不同的是,iframe可以嵌在网页中的任意部分。我们举第一个例子,具体代码如:

<iframe width=420 height=330 frameborder=0 scrolling=auto src=URL></iframe>,这里的URL可以是相对路径,也可以是绝对路径,效果如:

width表示宽度,height表示宽度,可根据实际情况调整。

scrolling表示是否显示页面滚动条,可选的参数为auto、yes、no,如果省略这个参数,则默认为auto。

二、如何实现页面上的超链接指向这个嵌入的网页?

只要给这个iframe命名就可以了。方法是<iframe name=**>,例如我命名为aa,写入这句HTML语言<iframe width=420 height=330 name=aa frameborder=0 src=http://www.cctv.com></iframe>,然后,网页上的超链接语句应该写为:<a href=URL target=aa>

效果如下,请点击这里:中央电视台

三、如果把frameborder设为1,效果就像文本框一样,如下:

网页树树版权声明:

此文为Webshu.com独家撰稿,著作权属作者所有。

传统媒体、公众站点转载请事先联系Webshu编辑。

此文网址 http://www.webshu.com/tutorial/tor/7,id=0408.htm

(转自:http://www.htmlhelp.com/reference/html40/special/iframe.html

The Web Design Group

IFRAME - Inline Frame

Syntax <IFRAME>...</IFRAME>

Attribute Specifications

    * SRC=URI (URI of frame content)

    * NAME=CDATA (name of frame)

    * LONGDESC=URI (link to long description)

    * WIDTH=Length (frame width)

    * HEIGHT=Length (frame height)

    * ALIGN=[ top | middle | bottom | left | right ] (frame alignment)

    * FRAMEBORDER=[ 1 | 0 ] (frame border)

    * MARGINWIDTH=Pixels (margin width)

    * MARGINHEIGHT=Pixels (margin height)

    * SCROLLING=[ yes | no | auto ] (ability to scroll)

    * core attributes

Contents Inline elements, block-level elements

Contained in Block-level elements, inline elements except BUTTON

The IFRAME element defines an inline frame for the inclusion of external objects including other HTML documents. IFRAME provides a subset of the functionality of OBJECT; the only advantage to IFRAME is that an inline frame can act as a target for other links. OBJECT is more widely supported than IFRAME, and, unlike IFRAME, OBJECT is included in HTML 4.0 Strict.

IFRAME's SRC attribute provides the location of the frame content--typically an HTML document. The optional NAME attribute specifies the name of the inline frame, allowing links to target the frame.

The content of the IFRAME element is used as an alternative for browsers that are not configured to show or do not support inline frames. The content may consist of inline or block-level elements, though any block-level elements must be allowed inside the containing element of IFRAME. For example, an IFRAME within an H1 cannot contain an H2, but an IFRAME within a DIV can contain any block-level elements.

The LONGDESC attribute gives the URI of a long description of the frame's contents. This is particularly useful for full descriptions of embedded objects. Note that LONGDESC describes the frame content while the content of the IFRAME element acts as a replacement when the external resource cannot be inlined.

An example follows:

<IFRAME SRC="recipe.html" TITLE="The Famous Recipe">

<!-- Alternate content for non-supporting browsers -->

<H2>The Famous Recipe</H2>

<H3>Ingredients</H3>

...

</IFRAME>

The WIDTH and HEIGHT attributes specify the dimensions of the inline frame in pixels or as a percentage of the available space. The FRAMEBORDER attribute specifies whether or not a border should be drawn. The default value of 1 results in a border while a value of 0 suppresses the border. Style sheets allow greater flexibility in suggesting the border presentation.

The ALIGN attribute specifies the alignment of the inline frame. The values top, middle, and bottom specify the frame's position with respect to surrounding content on its left and right.

ALIGN=middle aligns the center of the frame with the current baseline. To center the frame horizontally on the page, place the frame in a centered block, e.g.,

<P ALIGN=center><IFRAME SRC="foo.html" WIDTH=300 HEIGHT=100></IFRAME></P>

The other ALIGN values, left and right, specify a floating frame; the frame is placed at the left or right margin and content flows around it. To place content below the frame, use <BR CLEAR=left|right|all> as appropriate.

The vertical-align and float properties of Cascading Style Sheets provide more flexible methods of aligning inline frames.

The MARGINWIDTH and MARGINHEIGHT attributes define the number of pixels to use as the left/right margins and top/bottom margins, respectively, within the inline frame. The value must be greater than one pixel.

The SCROLLING attribute specifies whether scrollbars are provided for the inline frame. The default value, auto, generates scrollbars only when necessary. The value yes gives scrollbars at all times, and the value no suppresses scrollbars--even when they are needed to see all the content. The value no should never be used.

More Information

    * IFRAME in W3C HTML 4.0 Recommendation

    * Using inline frames

Maintained by Liam Quinn <liam@htmlhelp.com>

Web Design Group ~ HTML 4.0 Reference ~ Elements by Function ~ Elements Alphabetically

Copyright © 1998-2000 Liam Quinn. All rights reserved.

检讨一下自己,懒人一个

  这两天,老婆把家里认真做了一个大扫除,我也该检讨一下自己是不是平时有点懒?我自己的书桌都基本上不大收拾,别说平时把家里好好收拾一下。

  当然除了过年前的大扫除-我是包干了的。因为老婆过年要加班。