欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

顯示日歷代碼java,日歷怎么顯示日期

java編寫日歷

我給你貼上我在java核心技術(shù)中看到的代碼吧,當(dāng)然沒有輸入年份和月份,是按照當(dāng)前時(shí)間創(chuàng)建的,寫有我寫的注釋,應(yīng)該能看的懂

創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、網(wǎng)站制作與策劃設(shè)計(jì),海珠網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:海珠等地區(qū)。海珠做網(wǎng)站價(jià)格咨詢:028-86922220

/*

* 2012年5月13日10:37:58

* 日歷程序

* Function:

* 顯示當(dāng)前月份的日歷

* 總結(jié)

* 1. 0-11分別代表1-12月

* 1-7分別代表周日-周六

* 2. 使用GregorianCalendar對象的get方法(參數(shù))獲取月,日,年等信息

* 3.

*/

import java.text.DateFormatSymbols;

import java.util.*;

public class CalendarTest {

public static void main(String[] args) {

//construct d as current date構(gòu)造一個(gè)日期

GregorianCalendar d = new GregorianCalendar();

//獲取今天是這個(gè)月的第幾天

int today = d.get(Calendar.DAY_OF_MONTH); //Calendar.DAY_OF_MONTH作為參數(shù)調(diào)用,得到今天是這個(gè)月的第幾天

int month = d.get(Calendar.MONTH); //月份

d.set(Calendar.DAY_OF_MONTH, 1); //設(shè)置d的日期是本月的1號

int weekDay = d.get(Calendar.DAY_OF_WEEK); //獲取當(dāng)天位于本星期的第幾天,也就確定了星期幾,值的范圍是1-7

int firstDayOfWeek = d.getFirstDayOfWeek(); //獲取一星期的第一天,我們得到的是Calendar.SUNDAY,因?yàn)槲覀円恍瞧诘牡谝惶焓侵苋?/p>

int indent = 0; //為了定位本月第一天,定義索引

while (weekDay != firstDayOfWeek) {

//注意,月份用0-11代表1-12月,為了清晰起見,使用常量代替,下面獲取月份得到的實(shí)際是當(dāng)前月-1的值,所以我們要加1

//System.out.printf("當(dāng)前星期的第%d天,位于當(dāng)月的第%d天, 現(xiàn)在是%d月\n",

// weekDay, d.get(Calendar.DAY_OF_MONTH), d.get(Calendar.MONTH)+1); //Test Code

indent++;//縮進(jìn)個(gè)數(shù)+1

d.add(Calendar.DAY_OF_MONTH, -1);//當(dāng)前天數(shù)-1,如果現(xiàn)在是1號,則執(zhí)行本條代碼后,時(shí)間變?yōu)樯弦粋€(gè)月最后一天

weekDay = d.get(Calendar.DAY_OF_WEEK); //重新獲取當(dāng)天位于本星期的第幾天

}

String[] weekDayNames = new DateFormatSymbols().getShortWeekdays();//獲取簡短形式的星期字符串?dāng)?shù)組

//System.out.println(weekDayNames.length);getShortWeekdays()得到的數(shù)組的長度是8,下標(biāo)為0的是沒有值1為星期日...7為星期六

//注釋代碼1

//Java核心技術(shù)的代碼

/*

do {

//System.out.printf("%4s", weekDayNames[weekDay]); //經(jīng)過上面定義索引,weekDay代表的是本星期日

d.add(Calendar.DAY_OF_MONTH, 1); //天數(shù)加1

weekDay = d.get(Calendar.DAY_OF_WEEK); //重新獲得weekDay的值

} while (weekDay != firstDayOfWeek); //當(dāng)循環(huán)完一個(gè)星期后,這里判斷不成立,退出循環(huán)

*/

//我寫的代碼,替換上面注釋代碼1

for (int i=1; iweekDayNames.length; i++)//打印星期標(biāo)題

System.out.printf("%3s\t", weekDayNames[i]);//引號內(nèi)是一個(gè)全角的空格,因?yàn)槭侵形陌?,不是書上英文環(huán)境,中文和空格對于不上,這里我們用\t解決

//System.out.printf("%3s ", weekDayNames[i]); //方式2

System.out.println();//換行

for (int i=1; i=indent; i++)//確定一星期的一天位置,利用上面indent

System.out.printf("\t");//如用方式2,則這里內(nèi)容是四個(gè)全角空格

//實(shí)現(xiàn)輸出日期

d.set(Calendar.MONTH, month);

d.set(Calendar.DAY_OF_MONTH, 1);

do {

//print day

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

System.out.printf("%3d", day);

if (day == today)

System.out.print("*");

System.out.print("\t");

d.add(Calendar.DATE, 1);//天數(shù)加1

weekDay = d.get(Calendar.DAY_OF_WEEK);//刷新weekDay

if (weekDay == firstDayOfWeek) //如果這天等于星期天則換行

System.out.println();

} while (d.get(Calendar.MONTH) == month);

}

}

編寫java程序,由鍵盤輸入年份,顯示當(dāng)年日歷,要求使用數(shù)組。

首先鍵盤輸入的話多種方式實(shí)現(xiàn),提供兩種,一是使用main方法的arg參數(shù),也就是在使用java命令的時(shí)候后面跟上參數(shù),在main方法里調(diào)用arg[0]即可,第二種方法是使用scanner類來得到system.in的內(nèi)容

然后就是打印全年,這個(gè)只要使用calendar類即可,得到calendar對象以后通過一個(gè)循環(huán)365次,不斷的day加一即可

求一個(gè)JAVA編寫的日歷,用控制臺的形式顯示。

import

java.util.Calendar;

class

CalendarList{

int

year,month;

int

dayNum,i,num,count=0;

Calendar

objCalendar;

int[]

arrDayNum={31,28,31,30,31,30,31,31,30,31,30,31};

CalendarList(){

objCalendar=Calendar.getInstance();

this.year=objCalendar.get(Calendar.YEAR);

this.month=objCalendar.get(Calendar.MONTH)+1;

//要+1

}

CalendarList(String

args0,String

args1){

this.year=Integer.parseInt(args1);

this.month=Integer.parseInt(args0);

objCalendar=Calendar.getInstance();//這里沒有g(shù)et

objCalendar.set(Calendar.YEAR,year);//set是這樣用的

objCalendar.set(Calendar.MONTH,month-1);

}

void

display(){

System.out.println("\t\t\t"+year+"年"+month+"月");

System.out.println("日

六");

//每個(gè)空3個(gè)空格

num=objCalendar.get(Calendar.DAY_OF_WEEK);

if

((year/4==0year/100!=0)||(year/400==0)){

arrDayNum[1]+=1;

}

for

(i=1;i=12;i++){

if

(i==month){

dayNum=arrDayNum[i-1];

break;

}

}

for(i=1;i=num;i++){

System.out.print("

");//5個(gè)空格

count++;

}

for

(i=1;i=dayNum;i++){

System.out.print(i10?"

"+i+"

":i+"

");

//自己改了下

,空格數(shù):1,3,3

count++;

if(count==7){

System.out.println();

count=0;

}

}

System.out.println

();

}

}

public

class

MainClass

{

public

static

void

main(String[]

args)

{

CalendarList

objCalendar=new

CalendarList();

CalendarList

objCalendar1=new

CalendarList("11","2007");

objCalendar.display();

objCalendar1.display();

}

}

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:在原有基礎(chǔ)上修改了以下內(nèi)容:

* 1. 將容器由Frame改為了Dialog,以便在基于對話框的程序中也能夠使用

* 2. 將最小日期由1980改為了1950,考慮到目前球員的出生日期可能早于1980年

* 3. 將初始顯示格式設(shè)置為 yyyy年MM月dd日 格式,原有的小時(shí)去掉了,不適合于出生日期字段

*/

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; // 默認(rèn)【最小】顯示年份

int lastYear = 2050; // 默認(rèn)【最大】顯示年份

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; // 控制條標(biāo)簽文字色

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("時(shí)");

hourLabel.setForeground(controlTextColor);

result.add(hourLabel);

return result;

}

private JPanel createWeekAndDayPanal() {

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

JPanel result = new JPanel();

// 設(shè)置固定字體,以免調(diào)用環(huán)境改變影響界面美觀

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, "日期時(shí)間選擇", 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());

}

}

}

這是一個(gè)專門的選日期的類 ,你看看完了調(diào)用就行了

編寫JAVA程序?qū)崿F(xiàn)一個(gè)簡單的日歷(高分求高手)(追加分)

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.table.*;

public class MyCalendar extends JApplet {

public static final String WEEK_SUN = "SUN";

public static final String WEEK_MON = "MON";

public static final String WEEK_TUE = "TUE";

public static final String WEEK_WED = "WED";

public static final String WEEK_THU = "THU";

public static final String WEEK_FRI = "FRI";

public static final String WEEK_SAT = "SAT";

public static final Color background = Color.white;

public static final Color foreground = Color.black;

public static final Color headerBackground = Color.blue;

public static final Color headerForeground = Color.white;

public static final Color selectedBackground = Color.blue;

public static final Color selectedForeground = Color.white;

private JPanel cPane;

private JLabel yearsLabel;

private JSpinner yearsSpinner;

private JLabel monthsLabel;

private JComboBox monthsComboBox;

private JTable daysTable;

private AbstractTableModel daysModel;

private Calendar calendar;

public MyCalendar() {

cPane = (JPanel) getContentPane();

}

public void init() {

cPane.setLayout(new BorderLayout());

calendar = Calendar.getInstance();

calendar = Calendar.getInstance();

yearsLabel = new JLabel("Year: ");

yearsSpinner = new JSpinner();

yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));

yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR)));

yearsSpinner.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent changeEvent) {

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

calendar.set(Calendar.DAY_OF_MONTH, 1);

calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue()).intValue());

int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

calendar.set(Calendar.DAY_OF_MONTH, day maxDay ? maxDay : day);

updateView();

}

});

JPanel yearMonthPanel = new JPanel();

cPane.add(yearMonthPanel, BorderLayout.NORTH);

yearMonthPanel.setLayout(new BorderLayout());

yearMonthPanel.add(new JPanel(), BorderLayout.CENTER);

JPanel yearPanel = new JPanel();

yearMonthPanel.add(yearPanel, BorderLayout.WEST);

yearPanel.setLayout(new BorderLayout());

yearPanel.add(yearsLabel, BorderLayout.WEST);

yearPanel.add(yearsSpinner, BorderLayout.CENTER);

monthsLabel = new JLabel("Month: ");

monthsComboBox = new JComboBox();

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

monthsComboBox.addItem(new Integer(i));

}

monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH));

monthsComboBox.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent actionEvent) {

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

calendar.set(Calendar.DAY_OF_MONTH, 1);

calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex());

int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

calendar.set(Calendar.DAY_OF_MONTH, day maxDay ? maxDay : day);

updateView();

}

});

JPanel monthPanel = new JPanel();

yearMonthPanel.add(monthPanel, BorderLayout.EAST);

monthPanel.setLayout(new BorderLayout());

monthPanel.add(monthsLabel, BorderLayout.WEST);

monthPanel.add(monthsComboBox, BorderLayout.CENTER);

daysModel = new AbstractTableModel() {

public int getRowCount() {

return 7;

}

public int getColumnCount() {

return 7;

}

public Object getValueAt(int row, int column) {

if (row == 0) {

return getHeader(column);

}

row--;

Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();

calendar.set(Calendar.DAY_OF_MONTH, 1);

int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;

int index = row * 7 + column;

int dayIndex = index - moreDayCount + 1;

if (index moreDayCount || dayIndex dayCount) {

return null;

} else {

return new Integer(dayIndex);

}

}

};

daysTable = new CalendarTable(daysModel, calendar);

daysTable.setCellSelectionEnabled(true);

daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() {

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,

boolean hasFocus, int row, int column) {

String text = (value == null) ? "" : value.toString();

JLabel cell = new JLabel(text);

cell.setOpaque(true);

if (row == 0) {

cell.setForeground(headerForeground);

cell.setBackground(headerBackground);

} else {

if (isSelected) {

cell.setForeground(selectedForeground);

cell.setBackground(selectedBackground);

} else {

cell.setForeground(foreground);

cell.setBackground(background);

}

}

return cell;

}

});

updateView();

cPane.add(daysTable, BorderLayout.CENTER);

}

public static String getHeader(int index) {

switch (index) {

case 0:

return WEEK_SUN;

case 1:

return WEEK_MON;

case 2:

return WEEK_TUE;

case 3:

return WEEK_WED;

case 4:

return WEEK_THU;

case 5:

return WEEK_FRI;

case 6:

return WEEK_SAT;

default:

return null;

}

}

public void updateView() {

daysModel.fireTableDataChanged();

daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),

calendar.get(Calendar.WEEK_OF_MONTH));

daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1,

calendar.get(Calendar.DAY_OF_WEEK) - 1);

}

public static class CalendarTable extends JTable {

private Calendar calendar;

public CalendarTable(TableModel model, Calendar calendar) {

super(model);

this.calendar = calendar;

}

public void changeSelection(int row, int column, boolean toggle, boolean extend) {

super.changeSelection(row, column, toggle, extend);

if (row == 0) {

return;

}

Object obj = getValueAt(row, column);

if (obj != null) {

calendar.set(Calendar.DAY_OF_MONTH, ((Integer)obj).intValue());

}

}

}

public static void main(String[] args) {

JFrame frame = new JFrame("Calendar Application");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

MyCalendar myCalendar = new MyCalendar();

myCalendar.init();

frame.getContentPane().add(myCalendar);

frame.setSize(240, 172);

frame.show();

}

}

日歷輸出程序java控制流程

import java.util.Calendar;

import java.util.Date;

import java.util.Scanner;

public class MyCalendar

{

public static void main(String[] args)

{

Scanner scanner = new Scanner(System.in);

String reg = "^(\\d+)[^\\d]+((0?[1-9])|(1[012]))$";

while(true)

{

System.out.println("輸入年月(年和月用非數(shù)字隔開:如2015.1)(什么都不輸入直接退出)");

String line = scanner.nextLine().trim();

if("".equals(line))

{

scanner.close();

break;

}

if(!line.matches(reg))

{

continue;

}

int year = Integer.parseInt(line.replaceAll(reg, "$1"));

int month = Integer.parseInt(line.replaceAll(reg, "$2"));

System.out.println("日\t一\t二\t三\t四\t五\t六");

Calendar calendar = Calendar.getInstance();

// 這個(gè)月的1號是星期幾

calendar.set(year, month - 1, 1);

int day = calendar.get(Calendar.DAY_OF_WEEK);

int start = Calendar.SUNDAY;

calendar.add(Calendar.DATE, -day + start);

while(start day)

{

System.out.print(calendar.get(Calendar.DATE) + "\t");

calendar.add(Calendar.DATE, 1);

start++;

}

calendar.set(year, month - 1, 1);

Date now = calendar.getTime();

calendar.set(year, month, 1);

Date next = calendar.getTime();

for(Date cur = now; cur.before(next);)

{

calendar.setTime(cur);

int x = calendar.get(Calendar.DATE);

String tmp = x 10 ? "0" + x : x + "";

System.out.print(tmp + "\t");

if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)

{

System.out.println();

}

calendar.add(Calendar.DATE, 1);

cur = calendar.getTime();

}

calendar.add(Calendar.DATE, -1);

int to = calendar.get(Calendar.DAY_OF_WEEK);

int end = Calendar.SATURDAY;

while(to end)

{

calendar.add(Calendar.DATE, 1);

int x = calendar.get(Calendar.DATE);

String tmp = x 10 ? "0" + x : x + "";

System.out.print(tmp + "\t");

to++;

}

System.out.println("\r\n");

}

}

}

分享名稱:顯示日歷代碼java,日歷怎么顯示日期
標(biāo)題路徑:http://aaarwkj.com/article26/hsodcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、服務(wù)器托管微信公眾號、自適應(yīng)網(wǎng)站、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
性生活的视频免费观看麻豆| 未满十八周岁禁看视频| 黄色高清无遮挡在线观看| 一区二区在线日韩视频| 欧美日韩一区二区综合在线视频| 91午夜福利视频在线观看| 两性色午夜视频在线观看| 中文字幕亚洲精品乱码在线| 凹凸69堂国产成人精品| 人妻免费精品久久一区| 福利视频免费观看欧美| 日本亚洲精品一区二区三| 麻豆视频传媒入口在线播放| 91日本精品免费在线视频| 精品人妻一区二区三区蜜桃视频| 97色伦综合在线欧美| 国产精品白丝一区二区三区| 无人区乱码一区二区三区| 亚洲国产精品激情在线| 亚洲欧美高清一区二区| 熟女一区二区蜜桃视频| 午夜精品久久99蜜桃| 国产日韩精品一区二区三区在线| 国产成人综合久久二区| av免费观看男人的天堂| 人人爽久久爱夜夜躁一区| 国产精品国产不卡在线| 欧洲亚洲精品免费二区| 日韩电影在线观看二区| 日韩高清一级黄色大片网站| 欧美亚洲一区二区三区精品| 91国产熟女自拍视频| 国产一区二区三区av在线播放| 国产精品欧美一区久久| 国产黄片大秀在线观看| 97久久精品人妻一区二区三区 | 人妻少妇中文字幕一区| 国产中文字幕精品在线观看| 日韩在线一区中文字幕| 成人黄色一级电影免费看| 日韩欧美在线观看一区二区|