📄 main.java
字号:
/*
* Main.java
*
* Created on 2007年5月2日, 上午8:30
*/
package outlook;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
import javax.swing.table.*;
/**
*
*
*/
public class Main extends javax.swing.JFrame {
private Calendar calendar;
private AbstractTableModel daysModel;
private Note note=new Note();
public static Hashtable ht=new Hashtable();
public static Hashtable ct=new Hashtable();
private File a;
private FileInputStream Fin;
private FileOutputStream Fout;
private ObjectInputStream Oin;
private ObjectOutputStream Oout;
/** Creates new form Main */
public Main() {
initComponents();
ct.put("b",Color.PINK);
ct.put("m",Color.YELLOW);
ct.put("g",Color.CYAN);
try {
a=new File("notes.txt");
Fin=new FileInputStream(a);
Oin=new ObjectInputStream(Fin);
}
catch(Exception e) {}
try {
ht=(Hashtable)(Oin.readObject());
Fin.close();
}
catch (IOException e) {}
catch (ClassNotFoundException e) {}
calendar=Calendar.getInstance();
spnYear.setEditor(new JSpinner.NumberEditor(spnYear, "0000"));
spnYear.setValue(calendar.get(Calendar.YEAR));
cmbMonth.setSelectedIndex(calendar.get(Calendar.MONTH));
daysModel = new AbstractTableModel() {
public int getRowCount() {
return 6;
}
public int getColumnCount() {
return 7;
}
public String getColumnName(int column) {
return getHeader(column);
}
public Object getValueAt(int row, int column) {
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 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 (isSelected) {
cell.setForeground(Color.WHITE);
cell.setBackground(Color.BLUE);
}
else if(ht.containsKey((spnYear.getValue()).toString()+"_"+Integer.toString(cmbMonth.getSelectedIndex()+1)+"_"+text)) {
String s=((String)ht.get((spnYear.getValue()).toString()+"_"+Integer.toString(cmbMonth.getSelectedIndex()+1)+"_"+text)).substring(0,1);
if(column==0 || column==6)
cell.setForeground(Color.RED);
else
cell.setForeground(Color.BLACK);
cell.setBackground((Color)ct.get(s));
}
else {
if(column==0 || column==6)
cell.setForeground(Color.RED);
else
cell.setForeground(Color.BLACK);
cell.setBackground(Color.WHITE);
}
return cell;
}
});
daysTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
daysTableMouseClicked(evt);
}
});
updateView();
this.setTitle("日程表 by BJUT 05072115");
bir.setForeground((Color)(ct.get("b")));
met.setForeground((Color)(ct.get("m")));
game.setForeground((Color)(ct.get("g")));
JTable t=daysTable;
String d=(t.getValueAt(t.getSelectedRow(),t.getSelectedColumn())).toString();
d=(spnYear.getValue()).toString()+"_"+Integer.toString(cmbMonth.getSelectedIndex()+1)+"_"+d;
if(!ht.containsKey(d))
txtN.setText("今天没有安排!");
else
txtN.setText(((String)(ht.get(d))).substring(1));
}
public static String getHeader(int index) {
switch (index) {
case 0:
return "星期日";
case 1:
return "星期一";
case 2:
return "星期二";
case 3:
return "星期三";
case 4:
return "星期四";
case 5:
return "星期五";
case 6:
return "星期六";
default:
return null;
}
}
public void updateView() {
daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH)-1,
calendar.get(Calendar.WEEK_OF_MONTH)-1);
daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1,
calendar.get(Calendar.DAY_OF_WEEK) - 1);
jScrollPane1.setViewportView(daysTable);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
cmbMonth = new javax.swing.JComboBox();
spnYear = new javax.swing.JSpinner();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
daysTable = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
txtN = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
bir = new javax.swing.JLabel();
met = new javax.swing.JLabel();
game = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
cmbMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708" }));
cmbMonth.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbMonthActionPerformed(evt);
}
});
cmbMonth.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
cmbMonthPropertyChange(evt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -