怎样把图片用到我写的这个日历记事本上package myjishiben;
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;//java.io
JTextField showDay[];//是一个轻量级组件,它允许编辑单行文本
JLabel title[];//来显示和编辑规则的二维单元表
Calendar rili;//Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法
int whichweekday;
Image img;//444444444444
NotePad notpad=null;
Month modifyMonth;
Year modifyYear;
String week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
JPanel leftPanel, rithPanel;//是一般轻量级容器。有关 JPanel 的示例和面向任务的文档
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));
rithPanel = new JPanel();
this.year = year;
this.month =month;
this.day = day;
modifyYear = new Year(this);
modifyMonth = new Month(this);
title = new JLabel[7];
showDay = new JTextField[42];
for(int j=0;j<7;j++){
title[j]=new JLabel();
title[j].setText(week[j]);
title[j].setBorder(BorderFactory.createEmptyBorder() );
leftCenter.add(title[j]);
}
title[0].setForeground(Color.red);
title[6].setForeground(Color.blue);
for(int k =0;k<42;k++)
{
showDay[k] = new JTextField();
showDay[k].addMouseListener(this);
showDay[k].setEditable(false);
leftCenter.add(showDay[k]);
}
rili = Calendar.getInstance();
Box box = Box.createHorizontalBox();
box.add(modifyYear);
box.add(modifyMonth);
leftNorth.add(box);
leftPanel.setLayout( new BorderLayout());
leftPanel.add(leftNorth, BorderLayout.NORTH);
leftPanel.add(leftCenter, BorderLayout.CENTER);
leftPanel.add(new Label("请在年份输入框中输入所查年份,并回车确定"), BorderLayout.SOUTH);
leftPanel.validate();
Container con = getContentPane();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rithPanel);
con.add(split,BorderLayout.SOUTH);
con.validate();
//con.add(split,BorderLayout.SOUTH);
hashtable = new Hashtable();
file = new File("日历记事本.txt");
if (!file.exists())
{
try{
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(out);
objectOut.writeObject( hashtable);
objectOut.close();
out.close();
}catch(Exception t){
}
}
notpad=new NotePad(this);
rithPanel.add(notpad);
// System.out.println(" "+year+" "+month+" "+day);
setRilipai(year, month);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.setVisible(true);
this.setBounds(200,100,700,500);
this.validate();
}
public void setRilipai(int year,int month){
rili.set(year,month-1,1);
whichweekday = rili.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
pailihaoma(whichweekday,31,month,year);
}
if(month==4||month==6||month==9||month==11){
pailihaoma(whichweekday,30,month,year);
}
if(month==2){
if((year%4==0&&year%100!=0)||(year%400==0)){
pailihaoma(whichweekday,29,month,year);
}
else{
pailihaoma(whichweekday,28,month,year);
}
}
}
public void pailihaoma( int whichweekday , int yuetianshu,int month,int year){
//System.out.println("paili "+whichweekday+"paili"+yuetianshu);
Calendar calendar = Calendar.getInstance();
int y2 = calendar.get(Calendar.YEAR);
int m2 = calendar.get(Calendar.MONTH)+1;
int d2 = calendar.get(Calendar.DAY_OF_MONTH);
for( int i=whichweekday,n=1;i<whichweekday+yuetianshu;i++){
showDay[i].setText(" "+n);
if(n==d2&&month==m2&&year==y2){
showDay[i].setForeground(Color.green);
showDay[i].setFont(new Font("TemesRoman",Font.BOLD,20));
}
else{
showDay[i].setForeground(Color.black);
showDay[i].setFont(new Font("TemesRoman",Font.BOLD,12));
}
if(i%7==6){
showDay[i].setForeground(Color.blue);
}
if(i%7==0){
showDay[i].setForeground(Color.red);
}
n++;
}
for(int i=0;i<whichweekday;i++){
showDay[i].setText(" ");
}
for(int i=whichweekday+yuetianshu;i<42;i++){
showDay[i].setText(" ");
}
}
public int getYear(){
return year;
}
public void setYear(int y){
year=y;
notpad.setYear(year);
}
public int getMonth(){
return month;
}
public void setMonth(int m ){
month=m;
notpad.setMonth(month);
}
public int getDay(){
return day;
}
public void setDay(int d){
day=d;
notpad.setDay(day);
}
public Hashtable getHashtabel(){
return hashtable;
}
public File getFile(){
return file;
}
public void mousePressed(MouseEvent e){
JTextField source = (JTextField)e.getSource();
String s = source.getText().trim();
try{
day=Integer.parseInt(s);
notpad.setDay(day);
notpad.shezhixinxitiao(year,month,day);
notpad.shezhiwenbenqu(null);
notpad.huoqurizhiwenben(year,month,day);
}catch(Exception ee){
System.out.println(ee);
}
}
public void mouseClicked(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public static void main(String args[]){
Calendar calendar = Calendar.getInstance();
int y = calendar.get(Calendar.YEAR);
int m = calendar.get(Calendar.MONTH);
int d = calendar.get(Calendar.DAY_OF_MONTH);
//System.out.println(" main "+y+m+d);
new CalendarPad(y,m+1,d);
} }
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;//java.io
JTextField showDay[];//是一个轻量级组件,它允许编辑单行文本
JLabel title[];//来显示和编辑规则的二维单元表
Calendar rili;//Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法
int whichweekday;
Image img;//444444444444
NotePad notpad=null;
Month modifyMonth;
Year modifyYear;
String week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
JPanel leftPanel, rithPanel;//是一般轻量级容器。有关 JPanel 的示例和面向任务的文档
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));
rithPanel = new JPanel();
this.year = year;
this.month =month;
this.day = day;
modifyYear = new Year(this);
modifyMonth = new Month(this);
title = new JLabel[7];
showDay = new JTextField[42];
for(int j=0;j<7;j++){
title[j]=new JLabel();
title[j].setText(week[j]);
title[j].setBorder(BorderFactory.createEmptyBorder() );
leftCenter.add(title[j]);
}
title[0].setForeground(Color.red);
title[6].setForeground(Color.blue);
for(int k =0;k<42;k++)
{
showDay[k] = new JTextField();
showDay[k].addMouseListener(this);
showDay[k].setEditable(false);
leftCenter.add(showDay[k]);
}
rili = Calendar.getInstance();
Box box = Box.createHorizontalBox();
box.add(modifyYear);
box.add(modifyMonth);
leftNorth.add(box);
leftPanel.setLayout( new BorderLayout());
leftPanel.add(leftNorth, BorderLayout.NORTH);
leftPanel.add(leftCenter, BorderLayout.CENTER);
leftPanel.add(new Label("请在年份输入框中输入所查年份,并回车确定"), BorderLayout.SOUTH);
leftPanel.validate();
Container con = getContentPane();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rithPanel);
con.add(split,BorderLayout.SOUTH);
con.validate();
//con.add(split,BorderLayout.SOUTH);
hashtable = new Hashtable();
file = new File("日历记事本.txt");
if (!file.exists())
{
try{
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(out);
objectOut.writeObject( hashtable);
objectOut.close();
out.close();
}catch(Exception t){
}
}
notpad=new NotePad(this);
rithPanel.add(notpad);
// System.out.println(" "+year+" "+month+" "+day);
setRilipai(year, month);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.setVisible(true);
this.setBounds(200,100,700,500);
this.validate();
}
public void setRilipai(int year,int month){
rili.set(year,month-1,1);
whichweekday = rili.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
pailihaoma(whichweekday,31,month,year);
}
if(month==4||month==6||month==9||month==11){
pailihaoma(whichweekday,30,month,year);
}
if(month==2){
if((year%4==0&&year%100!=0)||(year%400==0)){
pailihaoma(whichweekday,29,month,year);
}
else{
pailihaoma(whichweekday,28,month,year);
}
}
}
public void pailihaoma( int whichweekday , int yuetianshu,int month,int year){
//System.out.println("paili "+whichweekday+"paili"+yuetianshu);
Calendar calendar = Calendar.getInstance();
int y2 = calendar.get(Calendar.YEAR);
int m2 = calendar.get(Calendar.MONTH)+1;
int d2 = calendar.get(Calendar.DAY_OF_MONTH);
for( int i=whichweekday,n=1;i<whichweekday+yuetianshu;i++){
showDay[i].setText(" "+n);
if(n==d2&&month==m2&&year==y2){
showDay[i].setForeground(Color.green);
showDay[i].setFont(new Font("TemesRoman",Font.BOLD,20));
}
else{
showDay[i].setForeground(Color.black);
showDay[i].setFont(new Font("TemesRoman",Font.BOLD,12));
}
if(i%7==6){
showDay[i].setForeground(Color.blue);
}
if(i%7==0){
showDay[i].setForeground(Color.red);
}
n++;
}
for(int i=0;i<whichweekday;i++){
showDay[i].setText(" ");
}
for(int i=whichweekday+yuetianshu;i<42;i++){
showDay[i].setText(" ");
}
}
public int getYear(){
return year;
}
public void setYear(int y){
year=y;
notpad.setYear(year);
}
public int getMonth(){
return month;
}
public void setMonth(int m ){
month=m;
notpad.setMonth(month);
}
public int getDay(){
return day;
}
public void setDay(int d){
day=d;
notpad.setDay(day);
}
public Hashtable getHashtabel(){
return hashtable;
}
public File getFile(){
return file;
}
public void mousePressed(MouseEvent e){
JTextField source = (JTextField)e.getSource();
String s = source.getText().trim();
try{
day=Integer.parseInt(s);
notpad.setDay(day);
notpad.shezhixinxitiao(year,month,day);
notpad.shezhiwenbenqu(null);
notpad.huoqurizhiwenben(year,month,day);
}catch(Exception ee){
System.out.println(ee);
}
}
public void mouseClicked(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public static void main(String args[]){
Calendar calendar = Calendar.getInstance();
int y = calendar.get(Calendar.YEAR);
int m = calendar.get(Calendar.MONTH);
int d = calendar.get(Calendar.DAY_OF_MONTH);
//System.out.println(" main "+y+m+d);
new CalendarPad(y,m+1,d);
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货