Climbing的专栏

Life is limited, but art is long

huang ClimbingID:hpdlzu80100
[修改头像]
1579次访问,排名2万外好友5人,关注者6
热爱生活,积极向上,流自己的汗,吃自己的饭!
hpdlzu80100的文章
原创 23 篇
翻译 0 篇
转载 2 篇
评论 0 篇
最近评论
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes
文章分类
收藏
    相册
    存档

    原创 随机单词文章构造器(Random Term Paper Writer)

    新一篇: 程序员必须走向专业化

     

    //Random term paper writer
    //Java how to program, 5/e, Exercise 11.9
    package StringsAndCharacters;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class RandomTermPaperWriter extends JFrame{

        
    private String[] article={"the","a","one","some","any"};
        
    private String[] noun={"boy","girl","dog","town","car"};
        
    private String[] verb={"drove","jumped","ran","walked","skipped"};
        
    private String[] preposition={"to","from","over","under","on"};
        
    private String[] sentences=new String[20];
        
        JTextArea output;
        JScrollPane scroller;
    public RandomTermPaperWriter()
    {   
    super("Random term paper writer");
        
        Container container
    =getContentPane();
        container.setLayout(
    new FlowLayout());
        
        JLabel hint1Label
    =new JLabel("Press ");
        container.add(hint1Label);
        
        JButton startButton
    =new JButton("Start");
        container.add(startButton);
        startButton.addActionListener(
            
    new ActionListener(){
                
    public void actionPerformed(ActionEvent event){
                    displayPaper();
                }
                
            }
        );
        
        JLabel hint2Label
    =new JLabel(" to write paper.");
        container.add(hint2Label);
        output
    =new JTextArea(20,40);
        scroller
    =new JScrollPane(output);
        container.add(scroller);
        
        setSize(
    600,500);
        setVisible(
    true);
        }

    public static void main(String args[])
    {
        RandomTermPaperWriter paperWriter
    =new RandomTermPaperWriter();
        paperWriter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    public void displayPaper(){
        
        
    for (int i=0;i<20;i++){
            
    int[] random=new int[6];
            
    for (int j=0;j<6;j++){
                random[j]
    =(int)(5*Math.random());
            }
            sentences[i]
    =article[random[0]]+" "+noun[random[1]]+" "+verb[random[2]]+" "
                         
    +preposition[random[3]]+" "+article[random[4]]+" "+noun[random[5]];
            output.append(sentences[i]
    +"\n");
        }
        
    }

    }

     

    A snapshot of program execution:

    发表于 @ 2008年04月29日 10:07:36|评论(loading...)|编辑

    旧一篇: 薪水册测试类及结果(Payroll System modification)

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © Climbing