当前位置:首页 > 代码 > 正文

java日历记事本代码(java简单记事本代码)

admin 发布:2022-12-19 23:58 157


今天给各位分享java日历记事本代码的知识,其中也会对java简单记事本代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java简单记事本源代码 带解释

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

class test implements ActionListener

{

JFrame frame;

JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31;

JTextArea ta;

JPanel p1,p2,p3,p4;

JMenuBar mb;

JMenu m1,m2,m3;

JMenuItem mt1,mt2,mt3,mt4,mt5,mt6,mt7;

JRadioButton rb1,rb2;

ButtonGroup bg;

Double d1=0.0,d2=0.0,d3=0.0,d4=1.0,d5=1.0;

String s1="",s2="",s3="",s4="";

int a=0;

char c1;

int i=0;

public static void main(String[] args)

{

test that=new test();

that.go();

}

public void go()

{

frame=new JFrame("计算器");

Container cp= frame.getContentPane();

cp.setLayout(new FlowLayout());

b1=new JButton("7");b2=new JButton("8");b3=new JButton("9");b4=new JButton("/");b5=new JButton("1/x");b6=new JButton("sin");b7=new JButton("log");

b8=new JButton("4");b9=new JButton("5");b10=new JButton("6");b11=new JButton("*");b12=new JButton("x^y");b13=new JButton("cos");b14=new JButton("ln");

b15=new JButton("1");b16=new JButton("2");b17=new JButton("3");b18=new JButton("-");b19=new JButton(new ImageIcon("lanying.gif"));b20=new JButton("tan");b21=new JButton("x^3");

b22=new JButton("0");b23=new JButton("+/-");b24=new JButton(".");b25=new JButton("+");b26=new JButton("√x");b27=new JButton("cot");b28=new JButton("x^2");

b29=new JButton("Backspace");b30=new JButton("C");b31=new JButton("=");

mb=new JMenuBar();

m1=new JMenu("文件(F)");m2=new JMenu("编辑(E)");m3=new JMenu("帮助(H)");

mt1=new JMenuItem("清零");mt2=new JMenuItem("退出");mt3=new JMenuItem("复制");mt4=new JMenuItem("粘贴");mt5=new JMenuItem("版本");mt6=new JMenuItem("标准型");mt7=new JMenuItem("科学型");

ta=new JTextArea(1,30);

p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();

rb1=new JRadioButton("科学型");rb2=new JRadioButton("标准型");

bg=new ButtonGroup();

b1.setForeground(Color.blue);b1.setBackground(Color.white);b2.setForeground(Color.blue);b2.setBackground(Color.white);

b3.setForeground(Color.blue);b3.setBackground(Color.white);b8.setForeground(Color.blue);b8.setBackground(Color.white);

b9.setForeground(Color.blue);b9.setBackground(Color.white);b10.setForeground(Color.blue);b10.setBackground(Color.white);

b15.setForeground(Color.blue);b15.setBackground(Color.white);b16.setForeground(Color.blue);b16.setBackground(Color.white);

b17.setForeground(Color.blue);b17.setBackground(Color.white);b22.setForeground(Color.blue);b22.setBackground(Color.white);

b23.setForeground(Color.blue);b23.setBackground(Color.white);b24.setForeground(Color.blue);b24.setBackground(Color.white);

b4.setForeground(Color.red);b4.setBackground(Color.white);b11.setForeground(Color.red);b11.setBackground(Color.white);

b18.setForeground(Color.red);b18.setBackground(Color.white);b25.setForeground(Color.red);b25.setBackground(Color.white);

b5.setForeground(Color.blue);b5.setBackground(Color.white);b6.setForeground(Color.blue);b6.setBackground(Color.white);

b7.setForeground(Color.blue);b7.setBackground(Color.white);b12.setForeground(Color.blue);b12.setBackground(Color.white);

b13.setForeground(Color.blue);b13.setBackground(Color.white);b14.setForeground(Color.blue);b14.setBackground(Color.white);

b19.setForeground(Color.blue);b19.setBackground(Color.white);b20.setForeground(Color.blue);b20.setBackground(Color.white);

b21.setForeground(Color.blue);b21.setBackground(Color.white);b26.setForeground(Color.blue);b26.setBackground(Color.white);

b27.setForeground(Color.blue);b27.setBackground(Color.white);b28.setForeground(Color.blue);b28.setBackground(Color.white);

b29.setForeground(Color.red);b29.setBackground(Color.white);b30.setForeground(Color.red);b30.setBackground(Color.white);

b31.setForeground(Color.red);b31.setBackground(Color.white);

bg.add(rb1);bg.add(rb2);

p1.setBackground(Color.yellow);

cp.setBackground(Color.CYAN);

m1.setMnemonic(KeyEvent.VK_F);m2.setMnemonic(KeyEvent.VK_E);m3.setMnemonic(KeyEvent.VK_H);

m1.add(mt6);m1.add(mt7);m1.addSeparator();m1.add(mt1);m1.addSeparator();m1.add(mt2);m2.add(mt3);m2.addSeparator();m2.add(mt4);m3.add(mt5);

mb.add(m1);mb.add(m2);mb.add(m3);

frame.setJMenuBar(mb);

p2.setLayout(new GridLayout(4,7));

p3.setLayout(new GridLayout(1,3));

ta.setEditable(false);

p1.add(ta);

p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);p2.add(b5);p2.add(b6);p2.add(b7);

p2.add(b8);p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12);p2.add(b13);p2.add(b14);

p2.add(b15);p2.add(b16);p2.add(b17);p2.add(b18);p2.add(b19);p2.add(b20);p2.add(b21);

p2.add(b22);p2.add(b23);p2.add(b24);p2.add(b25);p2.add(b26);p2.add(b27);p2.add(b28);

p3.add(b29);p3.add(b30);p3.add(b31);

Border etched=BorderFactory.createEtchedBorder();

Border border=BorderFactory.createTitledBorder(etched,"计算类型");

p4.add(rb1);p4.add(rb2);

p4.setBorder(border);

b2.setActionCommand("8");

b2.addActionListener(this);

cp.add(p1);cp.add(p4);cp.add(p2);cp.add(p3);

frame.setSize(400,330);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1.setActionCommand("7");

b1.addActionListener(this);

b2.setActionCommand("8");

b2.addActionListener(this);

b3.setActionCommand("9");

b3.addActionListener(this);

b4.setActionCommand("/");

b4.addActionListener(this);

b5.setActionCommand("1/x");

b5.addActionListener(this);

b6.setActionCommand("sin");

b6.addActionListener(this);

b7.setActionCommand("log");

b7.addActionListener(this);

b8.setActionCommand("4");

b8.addActionListener(this);

b9.setActionCommand("5");

b9.addActionListener(this);

b10.setActionCommand("6");

b10.addActionListener(this);

b11.setActionCommand("*");

b11.addActionListener(this);

b12.setActionCommand("x^y");

b12.addActionListener(this);

b13.setActionCommand("cos");

b13.addActionListener(this);

b14.setActionCommand("ln");

b14.addActionListener(this);

b15.setActionCommand("1");

b15.addActionListener(this);

b16.setActionCommand("2");

b16.addActionListener(this);

b17.setActionCommand("3");

b17.addActionListener(this);

b18.setActionCommand("-");

b18.addActionListener(this);

b19.setActionCommand("x!");

b19.addActionListener(this);

b20.setActionCommand("tan");

b20.addActionListener(this);

b21.setActionCommand("x^3");

b21.addActionListener(this);

b22.setActionCommand("0");

b22.addActionListener(this);

b23.setActionCommand("+/-");

b23.addActionListener(this);

b24.setActionCommand(".");

b24.addActionListener(this);

b25.setActionCommand("+");

b25.addActionListener(this);

b26.setActionCommand("√x");

b26.addActionListener(this);

b27.setActionCommand("cot");

b27.addActionListener(this);

b28.setActionCommand("x^2");

b28.addActionListener(this);

b29.setActionCommand("Backspace");

b29.addActionListener(this);

b30.setActionCommand("C");

b30.addActionListener(this);

b31.setActionCommand("=");

b31.addActionListener(this);

rb1.setActionCommand("kxx");

rb1.addActionListener(this);

rb2.setActionCommand("bzx");

rb2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) //throws Exception

{

if (e.getActionCommand()=="bzx")

{

b5.setEnabled(false);b6.setEnabled(false);b7.setEnabled(false);

b12.setEnabled(false);b13.setEnabled(false);b14.setEnabled(false);

b19.setEnabled(false);b20.setEnabled(false);b21.setEnabled(false);

b26.setEnabled(false);b27.setEnabled(false);b28.setEnabled(false);

}

if (e.getActionCommand()=="kxx")

{

b5.setEnabled(true);b6.setEnabled(true);b7.setEnabled(true);

b12.setEnabled(true);b13.setEnabled(true);b14.setEnabled(true);

b19.setEnabled(true);b20.setEnabled(true);b21.setEnabled(true);

b26.setEnabled(true);b27.setEnabled(true);b28.setEnabled(true);

}

if (e.getActionCommand()=="1")

{

ta.append("1");

}

if (e.getActionCommand()=="2")

{

ta.append("2");

}

if (e.getActionCommand()=="3")

{

ta.append("3");

}

if (e.getActionCommand()=="4")

{

ta.append("4");

}

if (e.getActionCommand()=="5")

{

ta.append("5");

}

if (e.getActionCommand()=="6")

{

ta.append("6");

}

if (e.getActionCommand()=="7")

{

ta.append("7");

}

if (e.getActionCommand()=="8")

{

ta.append("8");

}

if (e.getActionCommand()=="9")

{

ta.append("9");

}

if (e.getActionCommand()=="0")

{

ta.append("0");

}

if (e.getActionCommand()=="+")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=1;

}

if (e.getActionCommand()=="-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=2;

}

if (e.getActionCommand()=="*")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=3;

}

if (e.getActionCommand()=="/")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=4;

}

if (e.getActionCommand()=="=")

{

s2=ta.getText();

d2=Double.parseDouble(s2);

if(i==1)

{

d3=d1+d2;

ta.setText( d3.toString());

}

if(i==2)

{

d3=d1-d2;

ta.setText( d3.toString());

}

if(i==3)

{

d3=d1*d2;

ta.setText( d3.toString());

}

if(i==4)

{

if(d2==0.0)

ta.setText("ERROR");

else

{

d3=d1/d2;

ta.setText( d3.toString());

}

}

if (i==5)

{

s2=ta.getText();

d2 = Double.parseDouble(s2);

for (int l=1;l=d2 ; l++)

{

d5=d5*d1;

}

ta.setText( d5.toString());

}

}

if (e.getActionCommand()=="C")

{

ta.setText("");

d4=1.0;

d5=1.0;

}

/*if (e.getActionCommand()=="Backspace")

{

s3=ta.getText();

a=s3.length();

//ta.cut(ta.select(a-1,a));

s4=ta.getText(1,3);

ta.setText(s4);

}

*/

if (e.getActionCommand()=="1/x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=1/d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()==".")

{

ta.append(".");

}

if (e.getActionCommand()=="+/-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=0-d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^2")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^3")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^y")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=5;

// d2=d1*d1*d1;

// ta.setText( d2.toString());

}

if (e.getActionCommand()=="√x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sqrt(d1);

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x!")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

if (d10)

{

ta.setText( "error");

}

else if (d1==0)

{

ta.setText( "0.0");

}

else {

for (int k=1;k=d1 ;k++ )

d4=d4*k;

ta.setText( d4.toString());

}

}

if (e.getActionCommand()=="sin")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sin(3.1415926*d1/180);

ta.setText( d2.toString());

}

}

}

JAVA日历代码,怎么做?

import java.util.Date;

import java.util.Calendar;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.text.ParseException;

import java.awt.Color;

import java.awt.Font;

import java.awt.Point;

import java.awt.Dimension;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.Cursor;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JPanel;

import javax.swing.JLabel;

import javax.swing.JSpinner;

import javax.swing.SpinnerNumberModel;

import javax.swing.SwingUtilities;

import javax.swing.SwingConstants;

import javax.swing.event.ChangeListener;

import javax.swing.event.ChangeEvent;

import javax.swing.border.LineBorder;

/**

* @company:NEUSOFT

* @Title:日期选择控件

* @Description:在原有基础上修改了以下内容:

* 1. 将容器由Frame改为了Dialog,以便在基于对话框的程序中也能够使用

* 2. 将最小日期由1980改为了1950,考虑到目前球员的出生日期可能早于1980年

* 3. 将初始显示格式设置为 yyyy年MM月dd日 格式,原有的小时去掉了,不适合于出生日期字段

*/

public class DateChooserJButton extends JButton {

private DateChooser dateChooser = null;

private String preLabel = "";

public DateChooserJButton() {

this(getNowDate());

}

public DateChooserJButton(SimpleDateFormat df, String dateString) {

this();

setText(df, dateString);

}

public DateChooserJButton(Date date) {

this("", date);

}

public DateChooserJButton(String preLabel, Date date) {

if (preLabel != null)

this.preLabel = preLabel;

setDate(date);

setBorder(null);

setCursor(new Cursor(Cursor.HAND_CURSOR));

addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (dateChooser == null)

dateChooser = new DateChooser();

Point p = getLocationOnScreen();

p.y = p.y + 30;

dateChooser.showDateChooser(p);

}

});

}

private static Date getNowDate() {

return Calendar.getInstance().getTime();

}

private static SimpleDateFormat getDefaultDateFormat() {

return new SimpleDateFormat("yyyy年MM月dd日");

}

// 覆盖父类的方法

public void setText(String s) {

Date date;

try {

date = getDefaultDateFormat().parse(s);

} catch (ParseException e) {

date = getNowDate();

}

setDate(date);

}

public void setText(SimpleDateFormat df, String s) {

Date date;

try {

date = df.parse(s);

} catch (ParseException e) {

date = getNowDate();

}

setDate(date);

}

public void setDate(Date date) {

super.setText(preLabel + getDefaultDateFormat().format(date));

}

public Date getDate() {

String dateString = this.getText().substring(preLabel.length());

try {

return getDefaultDateFormat().parse(dateString);

} catch (ParseException e) {

return getNowDate();

}

}

public String getDateString()

{

Date birth =getDate();

DateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");

return formatDate.format(birth).toString();

//return this.getText().substring(preLabel.length());

}

// 覆盖父类的方法使之无效

//public void addActionListener(ActionListener listener) {

//}

private class DateChooser extends JPanel implements ActionListener,

ChangeListener {

int startYear = 1950; // 默认【最小】显示年份

int lastYear = 2050; // 默认【最大】显示年份

int width = 200; // 界面宽度

int height = 200; // 界面高度

Color backGroundColor = Color.gray; // 底色

// 月历表格配色----------------//

Color palletTableColor = Color.white; // 日历表底色

Color todayBackColor = Color.orange; // 今天背景色

Color weekFontColor = Color.blue; // 星期文字色

Color dateFontColor = Color.black; // 日期文字色

Color weekendFontColor = Color.red; // 周末文字色

// 控制条配色------------------//

Color controlLineColor = Color.pink; // 控制条底色

Color controlTextColor = Color.white; // 控制条标签文字色

Color rbFontColor = Color.white; // RoundBox文字色

Color rbBorderColor = Color.red; // RoundBox边框色

Color rbButtonColor = Color.pink; // RoundBox按钮色

Color rbBtFontColor = Color.red; // RoundBox按钮文字色

JDialog dialog;

JSpinner yearSpin;

JSpinner monthSpin;

JSpinner hourSpin;

JButton[][] daysButton = new JButton[6][7];

DateChooser() {

setLayout(new BorderLayout());

setBorder(new LineBorder(backGroundColor, 2));

setBackground(backGroundColor);

JPanel topYearAndMonth = createYearAndMonthPanal();

add(topYearAndMonth, BorderLayout.NORTH);

JPanel centerWeekAndDay = createWeekAndDayPanal();

add(centerWeekAndDay, BorderLayout.CENTER);

}

private JPanel createYearAndMonthPanal() {

Calendar c = getCalendar();

int currentYear = c.get(Calendar.YEAR);

int currentMonth = c.get(Calendar.MONTH) + 1;

int currentHour = c.get(Calendar.HOUR_OF_DAY);

JPanel result = new JPanel();

result.setLayout(new FlowLayout());

result.setBackground(controlLineColor);

yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,

startYear, lastYear, 1));

yearSpin.setPreferredSize(new Dimension(48, 20));

yearSpin.setName("Year");

yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####"));

yearSpin.addChangeListener(this);

result.add(yearSpin);

JLabel yearLabel = new JLabel("年");

yearLabel.setForeground(controlTextColor);

result.add(yearLabel);

monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1,

12, 1));

monthSpin.setPreferredSize(new Dimension(35, 20));

monthSpin.setName("Month");

monthSpin.addChangeListener(this);

result.add(monthSpin);

JLabel monthLabel = new JLabel("月");

monthLabel.setForeground(controlTextColor);

result.add(monthLabel);

hourSpin = new JSpinner(new SpinnerNumberModel(currentHour, 0, 23,

1));

hourSpin.setPreferredSize(new Dimension(35, 20));

hourSpin.setName("Hour");

hourSpin.addChangeListener(this);

result.add(hourSpin);

JLabel hourLabel = new JLabel("时");

hourLabel.setForeground(controlTextColor);

result.add(hourLabel);

return result;

}

private JPanel createWeekAndDayPanal() {

String colname[] = { "日", "一", "二", "三", "四", "五", "六" };

JPanel result = new JPanel();

// 设置固定字体,以免调用环境改变影响界面美观

result.setFont(new Font("宋体", Font.PLAIN, 12));

result.setLayout(new GridLayout(7, 7));

result.setBackground(Color.white);

JLabel cell;

for (int i = 0; i 7; i++) {

cell = new JLabel(colname[i]);

cell.setHorizontalAlignment(JLabel.RIGHT);

if (i == 0 || i == 6)

cell.setForeground(weekendFontColor);

else

cell.setForeground(weekFontColor);

result.add(cell);

}

int actionCommandId = 0;

for (int i = 0; i 6; i++)

for (int j = 0; j 7; j++) {

JButton numberButton = new JButton();

numberButton.setBorder(null);

numberButton.setHorizontalAlignment(SwingConstants.RIGHT);

numberButton.setActionCommand(String

.valueOf(actionCommandId));

numberButton.addActionListener(this);

numberButton.setBackground(palletTableColor);

numberButton.setForeground(dateFontColor);

if (j == 0 || j == 6)

numberButton.setForeground(weekendFontColor);

else

numberButton.setForeground(dateFontColor);

daysButton[i][j] = numberButton;

result.add(numberButton);

actionCommandId++;

}

return result;

}

private JDialog createDialog(JDialog owner) {

JDialog result = new JDialog(owner, "日期时间选择", true);

result.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

result.getContentPane().add(this, BorderLayout.CENTER);

result.pack();

result.setSize(width, height);

return result;

}

void showDateChooser(Point position) {

JDialog owner = (JDialog) SwingUtilities

.getWindowAncestor(DateChooserJButton.this);

if (dialog == null || dialog.getOwner() != owner)

dialog = createDialog(owner);

dialog.setLocation(getAppropriateLocation(owner, position));

flushWeekAndDay();

dialog.setVisible(true);

}

Point getAppropriateLocation(JDialog owner, Point position) {

Point result = new Point(position);

Point p = owner.getLocation();

int offsetX = (position.x + width) - (p.x + owner.getWidth());

int offsetY = (position.y + height) - (p.y + owner.getHeight());

if (offsetX 0) {

result.x -= offsetX;

}

if (offsetY 0) {

result.y -= offsetY;

}

return result;

}

private Calendar getCalendar() {

Calendar result = Calendar.getInstance();

result.setTime(getDate());

return result;

}

private int getSelectedYear() {

return ((Integer) yearSpin.getValue()).intValue();

}

private int getSelectedMonth() {

return ((Integer) monthSpin.getValue()).intValue();

}

private int getSelectedHour() {

return ((Integer) hourSpin.getValue()).intValue();

}

private void dayColorUpdate(boolean isOldDay) {

Calendar c = getCalendar();

int day = c.get(Calendar.DAY_OF_MONTH);

c.set(Calendar.DAY_OF_MONTH, 1);

int actionCommandId = day - 2 + c.get(Calendar.DAY_OF_WEEK);

int i = actionCommandId / 7;

int j = actionCommandId % 7;

if (isOldDay)

daysButton[i][j].setForeground(dateFontColor);

else

daysButton[i][j].setForeground(todayBackColor);

}

private void flushWeekAndDay() {

Calendar c = getCalendar();

c.set(Calendar.DAY_OF_MONTH, 1);

int maxDayNo = c.getActualMaximum(Calendar.DAY_OF_MONTH);

int dayNo = 2 - c.get(Calendar.DAY_OF_WEEK);

for (int i = 0; i 6; i++) {

for (int j = 0; j 7; j++) {

String s = "";

if (dayNo = 1 dayNo = maxDayNo)

s = String.valueOf(dayNo);

daysButton[i][j].setText(s);

dayNo++;

}

}

dayColorUpdate(false);

}

public void stateChanged(ChangeEvent e) {

JSpinner source = (JSpinner) e.getSource();

Calendar c = getCalendar();

if (source.getName().equals("Hour")) {

c.set(Calendar.HOUR_OF_DAY, getSelectedHour());

setDate(c.getTime());

return;

}

dayColorUpdate(true);

if (source.getName().equals("Year"))

c.set(Calendar.YEAR, getSelectedYear());

else

// (source.getName().equals("Month"))

c.set(Calendar.MONTH, getSelectedMonth() - 1);

setDate(c.getTime());

flushWeekAndDay();

}

public void actionPerformed(ActionEvent e) {

JButton source = (JButton) e.getSource();

if (source.getText().length() == 0)

return;

dayColorUpdate(true);

source.setForeground(todayBackColor);

int newDay = Integer.parseInt(source.getText());

Calendar c = getCalendar();

c.set(Calendar.DAY_OF_MONTH, newDay);

setDate(c.getTime());

}

}

}

这是一个专门的选日期的类 ,你看看完了调用就行了

急求 日历记事本课程设计报告 java编写

日历记事本课程设计报告

java编写

/*

说明:主程序

*/

import

java.util.Calendar;

import

javax.swing.*;

import

java.awt.*;

import

java.awt.event.*;

import

java.io.*;

import

java.util.Hashtable;

public

class

CalendarPad

extends

JFrame

implements

MouseListener

{

int

year,month,day;

Hashtable

hashtable;

File

file;

JTextField

showDay[];

JLabel

title[];

Calendar

日历;

int

星期几;

NotePad

notepad=null;

Month

负责改变月;

Year

负责改变年;

String

星期[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

JPanel

leftPanel,rightPanel;

public

CalendarPad(int

year,int

month,int

day)

{

leftPanel=new

JPanel();

//左边日历...........

JPanel

leftCenter=new

JPanel();

JPanel

leftNorth=new

JPanel();

leftCenter.setLayout(new

GridLayout(7,7));

rightPanel=new

JPanel();

this.year=year;

this.month=month;

this.day=day;

负责改变年=new

Year(this);

负责改变年.setYear(year);

负责改变月=new

Month(this);

负责改变月.setMonth(month);

title=new

JLabel[7];

showDay=new

JTextField[42];

for(int

j=0;j7;j++)

{

title[j]=new

JLabel();

title[j].setText(星期[j]);

title[j].setBorder(BorderFactory.createRaisedBevelBorder());

leftCenter.add(title[j]);

}

........

看下是不是收到了啊

额外人提问

急求一份用JAVA编写的日历记事本,用Eclipse实现,包括日历,记事本,时钟啊

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Date;

import java.util.GregorianCalendar;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class CalenderTrain extends JFrame implements ActionListener {

private static final long serialVersionUID=1L;

private static final int new_year = 0;

private JComboBox MonthBox =new JComboBox();

private JComboBox YearBox=new JComboBox();//月份和年份的下拉列表框

private JLabel YearLabel=new JLabel("年份");

private JLabel MonthLabel=new JLabel("月份");//月份和年份的标签

private JButton button_ok=new JButton("查看");

private JButton button_today=new JButton("今天");// “查看”和“今天”两个按钮

private Date now_date=new Date();

@SuppressWarnings("deprecation")

private int now_year=now_date.getYear()+1900;

@SuppressWarnings("deprecation")

private int now_month=now_date.getMonth();// 获取今天的日期,年份,月份

@SuppressWarnings("unused")

private boolean tidayFlag=false;//是否显示今天的日期

private JButton [] button_day=new JButton[42];

private final String[] week={"日","一","二","三","四","五","六"};

private JButton[] button_week=new JButton[7];//用一组按钮显示日期,一行7行7列,第一行为星期的名字

private String year_int=null;//保存用户选择的年份

private int month_int;//保存用户选择的月份

private boolean todayFlag;

/**

**构造函数

*/

public CalenderTrain(){

super();

System.out.print(now_month);

this.setTitle("日历");//设置标题

this.init();

this.setLocation(500,300);

this.setResizable(true);//设置面板的大小不能变化

pack();

}

/**

*

* 初始化日历

*/

private void init() {

Font font=new Font("Dialog",Font.BOLD,14);

YearLabel.setFont(font);

MonthLabel.setFont(font);

button_ok.setFont(font);

button_today.setFont(font);

for(int i=new_year-10;i=now_year+20;i++){

YearBox.addItem(i+"");

}//设定年份区间,为当前年份的过去10年到当前年份的未来20 年

YearBox.setSelectedIndex(10);//设定年份下拉列表为当前年份,当前年份处于第10项

for(int i=1;i12;i++){

MonthBox.addItem(i+"");

}//设定月份区间,12个月

MonthBox.setSelectedIndex(now_month);//设定月份下拉表框为当前月份

JPanel panel_ym=new JPanel();//放置下拉列表框和控制按钮的面板

panel_ym.add(YearLabel);

panel_ym.add(YearBox);

panel_ym.add(MonthLabel);

panel_ym.add(MonthBox);

panel_ym.add(button_ok);

panel_ym.add(button_today);

button_ok.addActionListener(this);

button_today.addActionListener(this);// 为两个按钮添加事件监听器

JPanel panel_day=new JPanel();//放置日期面板

panel_day.setLayout(new GridLayout(7,7,3,3));//网格布局管理器,7行7列,网格之间水平和垂直方向间均为5

for(int i=0;i7;i++){

button_week[i]=new JButton("");

button_week[i].setText(week[i]);

button_week[i].setForeground(Color.red);

panel_day.add(button_week[i]);

}//添加星期的名字,并放到面板里面

button_week[0].setForeground(Color.red);

button_week[6].setForeground(Color.red);

for(int i=0;i42;i++){

button_day[i]=new JButton("");

panel_day.add(button_day[i]);

}//添加日期,放到面板里面

this.paintDay();//显示当前年月的日期

JPanel panel_main=new JPanel();//放置以上两个面板

panel_main.setLayout(new BorderLayout());//边界布局管理器

panel_main.add(panel_day,BorderLayout.SOUTH);

panel_main.add(panel_ym,BorderLayout.NORTH);

getContentPane().add(panel_main);

}

/**显示当前年月的日期*/

@SuppressWarnings("deprecation")

private void paintDay() {

if(this.todayFlag){

year_int=now_year+"";

month_int=now_month;//要求显示今天的日期

}else{

year_int=YearBox.getSelectedItem().toString();//否则,从下拉框中获取用户的年月

month_int=MonthBox.getSelectedIndex();//被选的序号

}

int year_sel=Integer.parseInt(year_int)-1900;//获得年份置

@SuppressWarnings({ })

Date firstDay=new Date(year_sel,month_int,1);//构造该余额的第一天

GregorianCalendar cal=new GregorianCalendar();//创建一个Calendar的实例

cal.setTime(firstDay);

int days=0;//存放某个月份的天数

int day_week=0;//存放某个月份的第一天使星期几色数值

if(month_int==0||month_int==2||month_int==4||month_int==6||month_int==7||month_int==9||month_int==11){

days=31;

}else if(month_int==3||month_int==5||month_int==8||month_int==10){

days=30;

}else{

if(cal.isLeapYear(year_sel)){

days=29;

}else{

days=28;

}//二月,如果闰年,则有29天,否则有28他

}//判断是几月份,根据它来设定day的值,其中二月份要判断是否闰年

day_week=firstDay.getDay();

int count=1;

/**

* 绘制按钮。在这里首先要根据选定的月份的第一天是星期几来确定绘制按钮的起始位置

* 其中day_week就是我们要绘制的起始位置,对于那些没有数值可以显示的按钮要置空

*/

for(int i=day_week;iday_week+days;count++,i++){

if(i%7==0||i==6||i==13||i==20||i==27||i==34||i==41){

//如果是边界上的按钮,文字用红色,以来标示周末

if(i==day_week+now_date.getDate()-1){

button_day[i].setForeground(Color.blue);//将与今天一样的日期用蓝色标示

button_day[i].setText(count+"");

}else{

button_day[i].setForeground(Color.red);//其它边界上的按钮中的文字用红色

button_day[i].setText(count+"");

}

}else{

if(i==day_week+now_date.getDate()-1){

button_day[i].setForeground(Color.blue);//将与今天一样的日期用蓝色标示

button_day[i].setText(count+"");

}else{

button_day[i].setForeground(Color.black);//一般位置的按钮上的文字用黑色标示

button_day[i].setText(count+"");

}

}

}

if(day_week==0){

//对于没有日期数值显示的按钮进行置空处理

for(int i=days;i42;i++){

button_day[i].setText("");//如果第一天是周日,则将第一天前面的按钮置空

}

} else{

for(int i=0;iday_week;i++){

button_day[i].setText("");//如果第一天不是周日,则将第一天前面的按钮置空

}

}

}

public void actionPerformed(ActionEvent e){

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

//如果单击“查看”按钮就调用setDay()重新方法绘制按钮

this.todayFlag=false;

this.paintDay();

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

//如果单击“今天”按钮,得到今天的日期

todayFlag=true;

YearBox.setSelectedIndex(10);

MonthBox.setSelectedIndex(now_month);

this.paintDay();

}

}

/**

* @param args

*/

public static void main(String[] args){

CalenderTrain ct=new CalenderTrain();

ct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

ct.setVisible(true);

}

}

关于java日历记事本代码和java简单记事本代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/31336.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载