用java做学年设计(不是毕业设计).多简单的都可以.最主要还是想自己去试一下.不能只应付老师.
我现在在学java,不过还是基础知识.想用java去做.刚好也练习一下.但是水平有限,又没什么概念.无从下手.有人建议我做个聊天的小软件.我从网上下了一些,但是又不知从哪看起.我再想,就算是下载的,至少自己要理解每段代码的含义,能组合起来.先学别人的,然后自己再试试.只要实现最基本的功能就可以了.初学,下载的有些复杂.
想看看大家的建议.最好是只用java基础就可以的,或是给些步骤,如何去做.自己真的毫无头绪.进来看的,就请帮帮忙.如果不做聊天的,其他的有什么比较合适的没?
我现在在学java,不过还是基础知识.想用java去做.刚好也练习一下.但是水平有限,又没什么概念.无从下手.有人建议我做个聊天的小软件.我从网上下了一些,但是又不知从哪看起.我再想,就算是下载的,至少自己要理解每段代码的含义,能组合起来.先学别人的,然后自己再试试.只要实现最基本的功能就可以了.初学,下载的有些复杂.
想看看大家的建议.最好是只用java基础就可以的,或是给些步骤,如何去做.自己真的毫无头绪.进来看的,就请帮帮忙.如果不做聊天的,其他的有什么比较合适的没?
ee?做个bbs
me?不知道
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.lang.Integer;
import java.text.*;
import sun.audio.*;
import java.io.*;public class AlarmClock {
JLabel Label[]; ButtonGroup BtnGroup; JRadioButton intervalRadio, specifyRadio; JTextField minuteText, timeText; JCheckBox chkBox; JButton OKBtn, CancleBtn; Container con; GridBagLayout gridBag; JFrame mainJframe; Date today; Timer myTimer; int remainSeconds = 0; boolean startTime = false; private void addComponents(Component obj, GridBagConstraints c) {
gridBag.setConstraints(obj, c);
con.add(obj);
} private String TimeToString(Date day) {
return day.getHours() + ":" + day.getMinutes() + ":" + day.getSeconds();
}//将用户输入的“时:分:秒”转换成为一个整型数,如果有错误,抛出一个异常
private int parseTime(String str) throws ParseException {
int i = 0, hour = 0, minute = 0, second = 0;
int ch; ch = str.charAt(i);
while (i < str.length() && ch != ':') {
if (ch < '0' || ch > '9')
throw new ParseException(str, i);
hour = hour * 10 + ch - '0';
i++;
if (i < str.length())
ch = str.charAt(i);
else
throw new ParseException(str, i);
}
i++;
ch = str.charAt(i);
while (i < str.length() && ch != ':') {
if (ch < '0' || ch > '9')
throw new ParseException(str, i);
minute = minute * 10 + ch - '0';
i++;
if (i < str.length())
ch = str.charAt(i);
else
throw new ParseException(str, i);
}
i++;
ch = str.charAt(i);
while (i < str.length()) {
if (ch < '0' || ch > '9')
throw new ParseException(str, i);
second = second * 10 + ch - '0';
i++;
if (i < str.length())
ch = str.charAt(i);
}
if (hour > 23 || minute > 59 || second > 59)
throw new ParseException(str, i);
return hour * 3600 + minute * 60 + second;
} public AlarmClock() {
final String msg[] = { "当前时间", "", "订于", "分钟后", "订于", "提醒", "现在还差",
" 0 秒" };
Refresh task;
HandleBtn handle = new HandleBtn();
GridBagConstraints c = new GridBagConstraints();
Label = new JLabel[msg.length];
for (int i = 0; i < Label.length; i++)
Label[i] = new JLabel(msg[i], JLabel.CENTER);
mainJframe = new JFrame("小闹钟");
today = new Date();
gridBag = new GridBagLayout();
con = mainJframe.getContentPane();
con.setLayout(gridBag);
c.fill = GridBagConstraints.BOTH; c.gridwidth = 1;
c.insets = new Insets(0, 0, 5, 0);
addComponents(Label[0], c);
c.gridwidth = GridBagConstraints.REMAINDER;
Label[1].setText(TimeToString(today));
addComponents(Label[1], c); c.gridwidth = 1;
intervalRadio = new JRadioButton("间隔时间", true);
intervalRadio.addActionListener(handle);
BtnGroup = new ButtonGroup();
BtnGroup.add(intervalRadio);
addComponents(intervalRadio, c);
addComponents(Label[2], c);
minuteText = new JTextField("10", 6);
addComponents(minuteText, c);
c.gridwidth = GridBagConstraints.REMAINDER;
addComponents(Label[3], c); c.gridwidth = 1;
specifyRadio = new JRadioButton("指定时间", false);
specifyRadio.addActionListener(handle);
BtnGroup.add(specifyRadio);
addComponents(specifyRadio, c);
addComponents(Label[4], c);
timeText = new JTextField(TimeToString(today), 6);
timeText.setEditable(false);
addComponents(timeText, c);
c.gridwidth = GridBagConstraints.REMAINDER;
addComponents(Label[5], c); c.gridwidth = 1;
addComponents(Label[6], c);
c.gridwidth = GridBagConstraints.REMAINDER;
addComponents(Label[7], c); c.gridwidth = 1;
chkBox = new JCheckBox("蹦出来", true);
addComponents(chkBox, c);
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
OKBtn = new JButton("确定");
OKBtn.addActionListener(handle);
CancleBtn = new JButton("取消");
CancleBtn.addActionListener(handle);
panel.add(OKBtn);
panel.add(CancleBtn);
c.gridwidth = GridBagConstraints.REMAINDER;
addComponents(panel, c); mainJframe.setSize(280, 200);
mainJframe.setVisible(true);
mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myTimer = new Timer();
task = new Refresh();
myTimer.schedule(task, 1000, 1000);
} class Refresh extends TimerTask {
public Refresh() {
super();
} public void run() {
today = new Date();
Label[1].setText(TimeToString(today));
if (startTime) {
Label[7].setText(remainSeconds + "秒");
remainSeconds--;
if (remainSeconds == 0) {
startTime = false;
if (chkBox.isSelected())
mainJframe.setState(JFrame.NORMAL);
try {
FileInputStream fileau = new FileInputStream("alert.wav");
AudioStream as = new AudioStream(fileau);
AudioPlayer.player.start(as);
} catch (Exception e) {
}
}
}
}
} class HandleBtn implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object obj;
obj = e.getSource();
if (obj == intervalRadio) {
minuteText.setEditable(true);
timeText.setEditable(false);
} else if (obj == specifyRadio) {
minuteText.setEditable(false);
timeText.setEditable(true);
} else if (obj == OKBtn) {
try {
if (intervalRadio.isSelected()) { // 计算剩余时间
remainSeconds = Integer.parseInt(minuteText.getText(),
10) * 60;
} else { // 计算剩余时间
Date tmpDate = new Date();
int curTime, endTime;
curTime = tmpDate.getHours() * 3600
+ tmpDate.getMinutes() * 60
+ tmpDate.getSeconds();
endTime = parseTime(timeText.getText());
remainSeconds = endTime - curTime;
}
if (remainSeconds > 0) {
startTime = true; // 让Timer开始倒计时
mainJframe.setState(JFrame.ICONIFIED); // 窗口最小化
}
} catch (NumberFormatException el) {
JOptionPane.showMessageDialog(mainJframe, "对不起,输入的时间间隔有错误");
} catch (ParseException el) {
JOptionPane.showMessageDialog(mainJframe, "对不起,指定的时间有错误");
}
}else if(obj==CancleBtn){
startTime=false;
remainSeconds=0;
Label[7].setText(remainSeconds + "秒");
}
}
} public static void main(String[] args) {
new AlarmClock();
}
}
不要怕困难 基础有了 其他的都很快滴PS:在我的印象中,这些课程设计 复杂度一般都不是很大。
如果想做点尝试的话,你应该找你老师,让他带你做点课题。那个才学东西呢。
我们用c写过,还没用java写过。我也是初学者,呵呵……