需要一个java程序,最好是万年历的,要在500行左右的

2024-05-17

1. 需要一个java程序,最好是万年历的,要在500行左右的

Java-时钟万年历 
                                       
clock.java代码如下:
/**
 * Clock.java
 * Summary 数字时间显示
 * Created on 2005-8-14
 * @author 高?
 * remark 如有改动请发一份代码给我,邮箱gkgklovelove@eyou.com
 */
package Clock;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
class Clock extends Canvas implements Runnable{
    MainFrame mf;
    Thread t;
    String time;
    Clock(MainFrame mf){
    this.mf=mf;
    setSize(400,40);
    setBackground(Color.white);
    t=new Thread(this);                //实例化线程
    t.start();                        //调用线程    
    }
    public void run(){
    while(true){
    try{
    t.sleep(1000);                    //休眠1秒钟
    }catch(InterruptedException e){
    System.out.println("异常");
    }
    this.repaint(100);
    }
    }
    public void paint(Graphics g){
    Font f=new Font("宋体",Font.BOLD,16);    
    SimpleDateFormat SDF=new SimpleDateFormat("yyyy'年'MM'月'dd'日'HH:mm:ss");//格式化时间显示类型
    Calendar now=Calendar.getInstance();
    time=SDF.format(now.getTime());        //得到当前日期和时间
    g.setFont(f);
    g.setColor(Color.orange);
    g.drawString(time,100,25);
    }


MainFrame.java 的代码如下:
/**
 * MainFrame.java
 * Summary 万年历主类
 * Created on 2005-8-14
 * @author 高?
 * remark 如有改动请发一份代码给我,邮箱gkgklovelove@eyou.com
 */
package Clock;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
class MainFrame extends JFrame{
    JPanel panel=new JPanel(new BorderLayout());
    JPanel panel1=new JPanel();
    JPanel panel2=new JPanel(new GridLayout(7,7));
    JPanel panel3=new JPanel();
    JLabel []label=new JLabel[49];
    JLabel y_label=new JLabel("年份");
    JLabel m_label=new JLabel("月份");
    JComboBox com1=new JComboBox();
    JComboBox com2=new JComboBox();
    JButton button=new JButton("查看");
    int re_year,re_month;
    int x_size,y_size;
    String year_num;
    Calendar now=Calendar.getInstance();    //实例化Calendar
    MainFrame(){
        super("万年历");
        setSize(300,350);
        x_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth());
        y_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight());
        setLocation((x_size-300)/2,(y_size-350)/2);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel1.add(y_label);
        panel1.add(com1);
        panel1.add(m_label);
        panel1.add(com2);
        panel1.add(button);
        for(int i=0;i<49;i++){
            label[i]=new JLabel("",JLabel.CENTER);//将显示的字符设置为居中
            panel2.add(label[i]);
        }
        panel3.add(new Clock(this));
        panel.add(panel1,BorderLayout.NORTH);
        panel.add(panel2,BorderLayout.CENTER);
        panel.add(panel3,BorderLayout.SOUTH);
        panel.setBackground(Color.white);
        panel1.setBackground(Color.white);
        panel2.setBackground(Color.white);
        panel3.setBackground(Color.white);
        Init();
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                int c_year,c_month,c_week;
                c_year=Integer.parseInt(com1.getSelectedItem().toString());        //得到当前所选年份
                c_month=Integer.parseInt(com2.getSelectedItem().toString())-1;    //得到当前月份,并减1,计算机中的月为0-11
                c_week=use(c_year,c_month);        //调用函数use,得到星期几
                Resetday(c_week,c_year,c_month);        //调用函数Resetday
            }});
        setContentPane(panel);
        setVisible(true);
        setResizable(false);
    }
    public void Init(){
    int year,month_num,first_day_num;
    String log[]={"日","一","二","三","四","五","六"};
    for(int i=0;i<7;i++){
    label[i].setText(log[i]);
    }
    for(int i=0;i<49;i=i+7){
        label[i].setForeground(Color.red);    //将星期日的日期设置为红色
    }
    for(int i=6;i<49;i=i+7){
        label[i].setForeground(Color.green);//将星期六的日期设置为绿色
    }
    for(int i=1;i<10000;i++){
        com1.addItem(""+i);
    }
    for(int i=1;i<13;i++){
        com2.addItem(""+i);
    }
    month_num=(int)(now.get(Calendar.MONTH));    //得到当前时间的月份
    year=(int)(now.get(Calendar.YEAR));            //得到当前时间的年份
    com1.setSelectedIndex(year-1);                //设置下拉列表显示为当前年
    com2.setSelectedIndex(month_num);            //设置下拉列表显示为当前月
    first_day_num=use(year,month_num);
    Resetday(first_day_num,year,month_num);
    }
    public int use(int reyear,int remonth){
        int week_num;
        now.set(reyear,remonth,1);        //设置时间为所要查询的年月的第一天
        week_num= (int)(now.get(Calendar.DAY_OF_WEEK));//得到第一天的星期
        return week_num;
    }
    public void Resetday(int week_log,int year_log,int month_log){
        int month_score_log;    //判断是否是闰年的标记
        int month_day_score;    //存储月份的天数
        int count;
        month_score_log=0;
        month_day_score=0;
        count=1;
        if(year_log%4==0&&year_log%100!=0||year_log%400==0){//判断是否为闰年
            month_score_log=1;
        }
    month_log=month_log+1;    //将传来的月份数加1
    switch(month_log){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        month_day_score=31;
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        month_day_score=30;
        break;
        case 2:
        if(month_score_log==1){
        month_day_score=29;    
        }
        else{
        month_day_score=28;
        }
        break;
        }
        for(int i=7;i<49;i++){        //初始化标签
            label[i].setText("");
        }
        week_log=week_log+6;        //将星期数加6,使显示正确
        month_day_score=month_day_score+week_log;
        for(int i=week_log;i<month_day_score;i++,count++){
            label[i].setText(count+"");
        }
    }
    public static void main(String [] args){
        JFrame.setDefaultLookAndFeelDecorated(true);
        MainFrame start=new MainFrame();
    }    
}

需要一个java程序,最好是万年历的,要在500行左右的

2. 求大神们给我一份100行左右的java代码,无论什么题目,最好带注释的。

一百航其实很短呀...几下就没了,,如果是规范的代码,,
一行还没几个单词,..

3. 求java小程序,期末大作业,急!最好有文本介绍程序功能作用。最好是都弄好,能直接交上去的那种。

已发送!满意给个采纳!谢谢~

求java小程序,期末大作业,急!最好有文本介绍程序功能作用。最好是都弄好,能直接交上去的那种。

4. 跪求Java编程实例,500行左右的,最好有带注释的,功能不用太复杂,万分感谢!!!分不多,请见谅

5分,写500行。哈哈

5. 求推荐Java题目,大概500行代码左右的作业。

模拟一个资源管理器进行文件操作,包括建立和删除目录、建立和删除文件等基本文件操作。

求推荐Java题目,大概500行代码左右的作业。

6. 求个不少于500行源代码的JAVA小游戏程序,老师要求交大作业了。

我正好有几个, 带详细注释 。  邮箱或者别的方式给我  我发给你

7. 求一个50行左右的JAVA代码,最好每行带注释,谢谢啦

/*这个相当详细了.

程序也不算太难.而且给老师看的时候效果比较好.因为有图形化界面,又实现一个比较实用的功能.老师会比较高兴的. 
建立一个文件名为Change.java就可以编译了*/

/*
* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能
*/ 
import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类 
import java.awt.event.*;//同上

public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)
Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"
Label l1 = new Label("身高(cm)");//创建一个lable.显示身高
Label l2 = new Label("体重(kg)");//创建一个lable 显示体重
double heigth, weigth; //定义变量
double x, y; //定义变量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框

public Change() {//类的构造函数,完成初始化
super("互查表");//创建窗口,标题为互查表
setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局
add(l1);//把lable 身高放到window里
add(tf1);//把Text 框 放到窗口上
add(l2); //把lable 体重放到window里
add(tf2);//Test放到窗口里
add(b);//把button放到窗口上
pack();//自动放到窗口里排列上边的组件
setVisible(true);//可以让用户看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button监听函数
}

class ButtonListener implements ActionListener {//实现click button时功能操作
public void actionPerformed(ActionEvent e) {//当click调用

if (tf1.getText()!=null) {//检查tf1 test 是否为空
try {//取异常
x = Double.parseDouble(tf1.getText());//字符转为double型
weigth = (x - 100) * 0.9;//算重量
tf2.setText("" + weigth);//显示重量
} catch (NumberFormatException ex) {
tf1.setText("");//如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){//tf1是否为空
y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的
heigth = y / 0.9 + 100;  //算身高根据重量

tf1.setText("" + heigth);}//显示身高
}

}

public static void main(String[] args) {//主函数,程序入口
new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}

}

求一个50行左右的JAVA代码,最好每行带注释,谢谢啦

8. Java程序设计大作业

由于这个问题的界面比较简单,所以就没有在代码中做任何优化,楼主可以根据自己的需要调整。主要就是在界面中点击按钮,出发相应的功能,然后输出。大概代码如下(由于写的比较快,不足之处还请指出):
package main;



import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.util.Scanner;



import javax.swing.JButton;

import javax.swing.JFrame;



@SuppressWarnings("serial")

public class Program extends JFrame implements ActionListener {

	private int[] numbers;



	private JButton maxButton;

	private JButton minButton;

	private JButton averageButton;

	private JButton sumButton;

	private JButton sortButton;

	private JButton saveButton;

	private JButton exitButton;



	public void init() {

		setLayout(new FlowLayout());

		setTitle("学生成绩管理系统");

		setSize(500, 300);



		maxButton = new JButton("最大值");

		add(maxButton);

		maxButton.addActionListener(this);



		minButton = new JButton("最小值");

		add(minButton);

		minButton.addActionListener(this);



		averageButton = new JButton("平均值");

		add(averageButton);

		averageButton.addActionListener(this);



		sumButton = new JButton("总和");

		add(sumButton);

		sumButton.addActionListener(this);



		sortButton = new JButton("排序");

		add(sortButton);

		sortButton.addActionListener(this);



		saveButton = new JButton("保存");

		add(saveButton);

		saveButton.addActionListener(this);



		exitButton = new JButton("退出");

		add(exitButton);

		exitButton.addActionListener(this);



		setVisible(true);

		setLocationRelativeTo(null);

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}



	public void read(int n) {

		numbers = new int[n];

		for (int i = 0; i < n; i++) {

			System.out.println("请输入第" + i + "个数");

			Scanner scanner = new Scanner(System.in);

			int temp = scanner.nextInt();

			numbers[i] = temp;

		}

	}



	public int max() {

		int temp = numbers[0];

		int length = numbers.length;

		for (int i = 1; i < length; i++) {

			temp = (temp >= numbers[i]) ? temp : numbers[i];

		}

		return temp;

	}



	public int min() {

		int temp = numbers[0];

		int length = numbers.length;

		for (int i = 1; i < length; i++) {

			temp = (temp <= numbers[i]) ? temp : numbers[i];

		}

		return temp;

	}



	public double sum() {

		double sum = 0;

		int length = numbers.length;

		for (int i = 0; i < length; i++) {

			sum += numbers[i];

		}

		return sum;

	}



	public double average() {

		double sum = sum();

		int length = numbers.length;

		return (sum / length);

	}



	public int[] sort() {

		int length = numbers.length;

		for (int i = 0; i < length; i++) {

			for (int j = i; j < length; j++) {

				if (numbers[i] > numbers[j]) {

					int temp = numbers[i];

					numbers[i] = numbers[j];

					numbers[j] = temp;

				}

			}

		}

		return numbers;

	}



	public void save() {

		File file = new File("output/data.txt");

		try {

			FileOutputStream fos = new FileOutputStream(file);

			OutputStreamWriter osw = new OutputStreamWriter(fos);

			for (int i = 0; i < numbers.length; i++) {

				osw.write(numbers[i] + " ");

			}

			osw.flush();

			osw.close();

			fos.close();

		} catch (FileNotFoundException e) {

			e.printStackTrace();

		} catch (IOException e) {

			e.printStackTrace();

		}



	}



	public void exit() {

		System.exit(0);

	}



	public static void main(String[] args) {

		System.out.println("请输入学生的人数: ");

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();

		Program program = new Program();

		program.read(n);

		program.init();

	}



	@Override

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == maxButton) {

			int max = max();

			System.out.println("最大值:" + max);

		} else if (e.getSource() == minButton) {

			int min = min();

			System.out.println("最小值:" + min);

		} else if (e.getSource() == averageButton) {

			double average = average();

			System.out.println("平均值:" + average);

		} else if (e.getSource() == sumButton) {

			double sum = sum();

			System.out.println("总和:" + sum);

		} else if (e.getSource() == sortButton) {

			int[] result = sort();

			System.out.println("排序后结果为:");

			for (int i = 0; i < result.length; i++) {

				System.out.print(((int) result[i]));

				System.out.print(" ");

			}

		} else if (e.getSource() == saveButton) {

			save();

			System.out.println("保存成功!");

		} else if (e.getSource() == exitButton) {

			exit();

		}

	}

}