| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1153 人关注过本帖
标题:JAVA 实验报告 程序
只看楼主 加入收藏
liumang_D
Rank: 2
来 自:计算机
等 级:论坛游民
威 望:1
帖 子:89
专家分:50
注 册:2008-10-20
结帖率:100%
收藏
 问题点数:0 回复次数:2 
JAVA 实验报告 程序
我是搞C的,现在有两个JAVA程序要实现,都是为了应付实验报告,希望大家帮帮我,急啊,晚上7点就要上交!

(1)    设计一个随机显示单词功能,要求:
——显示当前时间;
——每隔3秒钟随机显示一个英文单词;
——要求用多线程技术实现;


(2)    学生选课(学生课程自定):
——所有的课程信息存在一个课程文件中;
——多个学生选课,每个学生选课的信息也存在相应的文件中;
——输出所有课程信息;输出每个学生选课的文件信息;

[[it] 本帖最后由 liumang_D 于 2008-11-16 15:40 编辑 [/it]]
搜索更多相关主题的帖子: JAVA 实验报告 
2008-11-16 15:39
freish
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1223
专家分:437
注 册:2007-6-1
收藏
得分:0 
写了个第一题
程序代码:
import java.awt.Container;
import java.awt.GridLayout;
import java.util.Calendar;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class ThreadTest extends JFrame{
    private Container container;
    private JLabel timeLabel;
    private JTextField timeField;
    private JLabel wordLabel;
    private JTextField wordField;
    
    public ThreadTest() {
        super("多线程");
        container = getContentPane();
        timeLabel = new JLabel("当  前  时  间",JLabel.CENTER);
        timeField = new JTextField(17);
        timeField.setEditable(false);
        wordLabel = new JLabel("随  机  单  词",JLabel.CENTER);
        wordField = new JTextField(17);
        wordField.setEditable(false);
        container.setLayout(new GridLayout(2,2));
        
        container.add(timeLabel);
        container.add(timeField);
        container.add(wordLabel);
        container.add(wordField);
        
        pack();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    
    public void runThread(){
        Thread timeThread = new Thread(new TimeDisplay());
        timeThread.start();
        Thread wordThread = new Thread(new WordDisplay());
        wordThread.start();
    }
    
    public static void main(String[] args) {
        new ThreadTest().runThread();
    }
    
    private class TimeDisplay implements Runnable{
        public void run(){
            while(true){
                timeField.setText(Calendar.getInstance().getTime().toString());
                try{
                    Thread.sleep(1000);
                }catch(Exception e){}
            }
        }
    }
    
    private class WordDisplay implements Runnable{
        private String[] words = 
                ("Java software powers the onboard computers in toys cars planes rockets and " +
                "even the NASA Mars Rover It brings interactivity to the Internet real-time " +
                "graphics to television instant imaging to cameras and multi-player games " +
                "to mobile phones and desktop PCs It connects the largest enterprises and " +
                "smallest businesses to their employees customers and data And it secures the " +
                "vast majority of electronic transactions in retail finance government science " +
                "and medicine In short Java technology goes everywhere you go").toLowerCase().split(" ");
        private Random rand;
        {
            rand = new Random();
        }
        public void run(){
            while(true){
                wordField.setText(words[rand.nextInt(words.length)]);
                try{
                    Thread.sleep(3000);
                }catch(Exception e){}
            }
        }
    }
}

2008-11-16 17:30
liumang_D
Rank: 2
来 自:计算机
等 级:论坛游民
威 望:1
帖 子:89
专家分:50
注 册:2008-10-20
收藏
得分:0 
非常感谢版主
2008-11-16 19:46
快速回复:JAVA 实验报告 程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018609 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved