成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

打印日歷java代碼 java打印月歷

Java日歷打印,怎么加輸入年份,打印整年12個(gè)月打印,輸入月份打印季節(jié),下面代碼如何優(yōu)化,給個(gè)思路?

建議封裝函數(shù),使用數(shù)組完成所有的打印

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司十多年經(jīng)驗(yàn)成就非凡,專業(yè)從事網(wǎng)站建設(shè)、做網(wǎng)站,成都網(wǎng)頁設(shè)計(jì),成都網(wǎng)頁制作,軟文發(fā)布平臺,一元廣告等。十多年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:13518219792,我們期待您的來電!

比如獲取天數(shù),getDays(int year,int month)

獲取星期,getDay(int allDays)

獲取極度,getQuater(int month)

然后打印重載寫print方法,傳入的flag不同打印年 嫉妒等

在Java中如何用calendar類輸入年和月份打印當(dāng)月的日歷

//日歷存放列表

ListString list = new ArrayListString();

//日期格式

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

//月初

Calendar begin=Calendar.getInstance();

begin.set(Calendar.YEAR, year);

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

begin.set(Calendar.DAY_OF_MONTH,1);

System.out.println(format.format(begin.getTime()));

//月末

Calendar end = Calendar.getInstance();

end.setTime(begin.getTime());

end.add(Calendar.MONTH, 1);

end.add(Calendar.DAY_OF_MONTH,-1);

System.out.println(format.format(end.getTime()));

//創(chuàng)建日歷

while(end.compareTo(begin)=0){

list.add(format.format(begin.getTime()));

begin.add(Calendar.DAY_OF_MONTH, 1);

}

//顯示日歷

for(String date : list){

System.out.println(date);

}

在JAVA中怎么打印出日歷

加分吧?。。?!

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();

}

}

關(guān)于打印日歷的java程序,哪位能幫忙看看哪里錯(cuò)了,幫忙改改?

t.set(year-1900,month,1);

改成

t.set(year, month-1, 1); //year沒什么說的,mouth從0開始,1月既是0月

分享題目:打印日歷java代碼 java打印月歷
分享URL:http://jinyejixie.com/article20/dosdgco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、網(wǎng)站營銷、做網(wǎng)站、企業(yè)網(wǎng)站制作網(wǎng)站改版、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(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)

成都網(wǎng)站建設(shè)公司
兴化市| 岳西县| 藁城市| 三明市| 平凉市| 四平市| 绥中县| 都匀市| 安图县| 永新县| 萍乡市| 望江县| 大冶市| 六枝特区| 南郑县| 霍城县| 兴隆县| 景宁| 陇南市| 六枝特区| 台山市| 涿州市| 黑水县| 娄底市| 兴安盟| 沐川县| 定襄县| 增城市| 屏东市| 自治县| 扎赉特旗| 竹山县| 天全县| 克拉玛依市| 铜梁县| 南澳县| 平武县| 云阳县| 仙桃市| 长泰县| 平遥县|