├── DARK.jpg ├── logo.jpg ├── BLACK.jpg ├── WHITE.jpg ├── YELLOW.jpg ├── 页面展示1.png ├── Java课程设计报告.pdf ├── README.md ├── NiceCalendar.java ├── NiceFrame.java ├── NiceTimer.java ├── NiceSkip.java ├── NiceBase.java ├── NiceAlarm.java ├── NiceClock.java ├── NiceLabels.java ├── NiceMenubar.java └── NicePanel.java /DARK.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/DARK.jpg -------------------------------------------------------------------------------- /logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/logo.jpg -------------------------------------------------------------------------------- /BLACK.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/BLACK.jpg -------------------------------------------------------------------------------- /WHITE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/WHITE.jpg -------------------------------------------------------------------------------- /YELLOW.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/YELLOW.jpg -------------------------------------------------------------------------------- /页面展示1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/页面展示1.png -------------------------------------------------------------------------------- /Java课程设计报告.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwfay/Calendar/HEAD/Java课程设计报告.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 使用说明:将所有的.java文件放在同一个文件夹下,编译NiceCalendar.java,即可运行 2 | 3 | # Calendar 4 | Java 课程设计,万年历(Java Swing) 5 | 制作一个万年历,包括以下功能: 6 | #### 基本功能: 7 | - 获取当前日期并显示 8 | - 获取当前时间并显示 9 | - 能够跳转到任意时期并显示 10 | - 使用图形用户界面 11 | #### 扩展功能: 12 | - 能够显示节日提醒、占卜提示 13 | - 能够更改界面风格(换肤) 14 | - 能够设置闹钟并提醒 15 | 16 | ## 如果觉得有用烦请给个小星星 17 | 18 | **2021.01.28修改:上传了作者当年的课程设计报告,添加了一些界面展示图例** 19 | ![运行方法展示](页面展示1.png) 20 | -------------------------------------------------------------------------------- /NiceCalendar.java: -------------------------------------------------------------------------------- 1 | //NiceCalendar.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | /* 5 | __Name__ : NiceCalendar 5.0 6 | __Authr__ : lofone 7 | __Major__ : computer science 8 | __Term__ : 2018-2019-2 9 | */ 10 | 11 | import java.awt.*; 12 | 13 | public class NiceCalendar{ 14 | public static void main(String[] args){ 15 | NiceFrame NF = new NiceFrame(); //Window 16 | 17 | NF.setBounds(200,200,1200,600); //1200X600 18 | 19 | Image image = Toolkit.getDefaultToolkit().createImage("logo.jpg"); //logo 20 | NF.setIconImage(image); //icon 21 | NF.setTitle("Nice Calendar"); //title 22 | NF.setVisible(true); //let the window visible 23 | }; //end of main 24 | } //end of class NiceCalendar -------------------------------------------------------------------------------- /NiceFrame.java: -------------------------------------------------------------------------------- 1 | //NiceCalendar.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import javax.swing.*; 6 | 7 | public class NiceFrame extends JFrame{ 8 | private static final long serialVersionUID = 1L; //default 9 | 10 | NiceClock NC = new NiceClock(new ImageIcon("WHITE.jpg")); //background 11 | NiceMenubar NM = new NiceMenubar(NC); //combine NiceMenubar 12 | 13 | JPanel Panel_Left = new JPanel(new GridLayout(2, 1)); //set layout 14 | 15 | public NiceFrame(){ //constructer 16 | 17 | setVisible(true); //visible 18 | setDefaultCloseOperation(DISPOSE_ON_CLOSE); //dispose 19 | 20 | Panel_Left.add(NC); //add NiceClock 21 | Panel_Left.add(NM.NP.NL); //add NiceLabels 22 | 23 | 24 | setLayout(new GridLayout(1, 2)); //set layout 25 | setJMenuBar(NM); //add Menubar 26 | add(Panel_Left); //add Panel_Left 27 | add(NM.NP); //add NicePanel 28 | 29 | NM.NP.refresh(); //show default calendar 30 | } //end of constructer 31 | } //end of class NiceFrame -------------------------------------------------------------------------------- /NiceTimer.java: -------------------------------------------------------------------------------- 1 | //NiceTimer.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | public class NiceTimer{ //Timer 5 | 6 | NiceLabels NL; //combine NL 7 | int goalHour; 8 | int goalMinute; 9 | 10 | 11 | NiceTimer(int goalHour, int goalMinute, NiceLabels NL) { //reference NiceLabels 12 | this.goalHour = (goalHour-8)%24; //switch time difference 13 | this.goalMinute = goalMinute; 14 | this.NL = NL; 15 | } 16 | 17 | public void run() { 18 | int currentSecond; 19 | int currentMinute; 20 | int currentHour; 21 | 22 | do{ 23 | long currentTime = System.currentTimeMillis(); //get current time 24 | 25 | currentTime = currentTime / 1000; 26 | currentSecond = (int) (currentTime % 60); //get second 27 | currentTime = currentTime / 60; 28 | currentMinute = (int) (currentTime % 60); //get minute 29 | currentTime = currentTime / 60; 30 | currentHour = (int) (currentTime % 24); //get hour 31 | 32 | if (goalMinute-currentMinute > 0) 33 | System.out.println("Alarm: "+ (goalHour-currentHour) +" : "+ 34 | (goalMinute-currentMinute-1) +" : "+ (59-currentSecond)); 35 | 36 | try { 37 | Thread.sleep(1000); //system pause a second 38 | } 39 | catch (InterruptedException e){ 40 | e.toString(); 41 | } 42 | }while (goalHour*100+goalMinute > currentHour*100+currentMinute); 43 | 44 | NL.Label_Alarm.setText("Alarm: Time Out !"); //time out 45 | } 46 | } -------------------------------------------------------------------------------- /NiceSkip.java: -------------------------------------------------------------------------------- 1 | //NiceSkip.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | 8 | public class NiceSkip extends JFrame implements ActionListener{ 9 | private static final long serialVersionUID = 1L; 10 | 11 | NicePanel NP; 12 | JPanel Panel_Skip = new JPanel(new GridLayout(4, 1)); 13 | JPanel Panel_Row4 = new JPanel(); 14 | JPanel Panel_Row3 = new JPanel(); 15 | JPanel Panel_Row2 = new JPanel(); 16 | JPanel Panel_Row1 = new JPanel(); 17 | 18 | JLabel Label_Tips = new JLabel("When would you wanna jump ? "); 19 | JLabel Label_Y = new JLabel("Which Year : "); 20 | JLabel Label_M = new JLabel("Which Month: "); 21 | 22 | JTextField Textfield_Y = new JTextField(5); 23 | JTextField Textfield_M = new JTextField(5); 24 | 25 | JButton Button_Skip = new JButton("Skip"); 26 | 27 | 28 | 29 | NiceSkip(NicePanel NP){ 30 | 31 | 32 | setBounds(800,450,300, 200); 33 | setTitle("Skip"); 34 | setVisible(true); 35 | 36 | this.NP = NP; 37 | 38 | Panel_Row4.add(Label_Tips); 39 | Panel_Row3.add(Label_Y); 40 | Panel_Row3.add(Textfield_Y); 41 | Panel_Row2.add(Label_M); 42 | Panel_Row2.add(Textfield_M); 43 | Panel_Row1.add(Button_Skip); 44 | 45 | Panel_Row4.setBackground(Color.WHITE); 46 | Panel_Row3.setBackground(Color.WHITE); 47 | Panel_Row2.setBackground(Color.WHITE); 48 | Panel_Row1.setBackground(Color.WHITE); 49 | 50 | Panel_Skip.add(Panel_Row4); 51 | Panel_Skip.add(Panel_Row3); 52 | Panel_Skip.add(Panel_Row2); 53 | Panel_Skip.add(Panel_Row1); 54 | 55 | add(Panel_Skip); 56 | 57 | Button_Skip.addActionListener(this); 58 | } 59 | 60 | void Skip(NicePanel NP){ 61 | NP.NB.setYear(Integer.valueOf(Textfield_Y.getText())); 62 | NP.NB.setMonth(Integer.valueOf(Textfield_M.getText())); 63 | NP.refresh(); 64 | } 65 | @Override 66 | public void actionPerformed(ActionEvent e){ 67 | if(e.getSource() == Button_Skip){ 68 | Skip(NP); 69 | this.dispose(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /NiceBase.java: -------------------------------------------------------------------------------- 1 | //NiceBase.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | 5 | import java.util.Calendar; 6 | 7 | public class NiceBase{ 8 | //private String day[]; 9 | private int year; 10 | private int month; 11 | 12 | NiceBase(){ 13 | year = 2019; 14 | month = 6; 15 | } 16 | 17 | NiceBase(int year, int month){ 18 | setYear(year); 19 | setMonth(month); 20 | } 21 | 22 | public void setYear(int year){ //set year 23 | if(year < 2119 && year > 1919) 24 | this.year = year; 25 | } 26 | 27 | public int getYear(){ //return year 28 | return year; 29 | } 30 | 31 | public void setMonth(int month){ //set month 32 | if(month < 0) 33 | this.month = month + 12; 34 | else if(month > 12) 35 | this.month = month -12; 36 | else 37 | this.month = month; 38 | } 39 | public int getMonth(){ //return month 40 | return month; 41 | } 42 | 43 | public String[] getCalendar(){ //draw calendar 44 | String a[] = new String[42]; 45 | Calendar C = Calendar.getInstance(); 46 | C.set(year, month - 1, 1); //the month is 0 based 47 | int D = C.get(Calendar.DAY_OF_WEEK)-1; 48 | 49 | int day = 0; 50 | if(month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12) 51 | day = 31; //1 3 5 7 8 10 12 they have 31 days a month 52 | 53 | else if(month == 4||month == 6||month == 9||month == 11) 54 | day = 30; //4 6 9 11 they have 30 days a month 55 | 56 | else if(month == 2){ 57 | if(((year % 4 == 0)&&(year % 100!= 0))||(year % 400 == 0)) 58 | day = 29; //sometimes 29 otherwise 28 59 | else 60 | day = 28; 61 | } 62 | 63 | for(int i = D, n = 1; i < D + day; i++){ 64 | a[i] = String.valueOf(n); 65 | n++; 66 | } 67 | 68 | return a; 69 | } 70 | } -------------------------------------------------------------------------------- /NiceAlarm.java: -------------------------------------------------------------------------------- 1 | //NiceAlarm.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | 8 | public class NiceAlarm extends JFrame implements ActionListener{ 9 | private static final long serialVersionUID = 1L; 10 | 11 | NiceLabels NL; 12 | JPanel Panel_Alarm = new JPanel(new GridLayout(4, 1)); 13 | 14 | 15 | JPanel Panel_Row4 = new JPanel(); 16 | JPanel Panel_Row3 = new JPanel(); 17 | JPanel Panel_Row2 = new JPanel(); 18 | JPanel Panel_Row1 = new JPanel(); 19 | 20 | JLabel Label_Tips = new JLabel("Just set a time : "); 21 | JLabel Label_H = new JLabel("Hour : "); 22 | JLabel Label_M = new JLabel("Minute : "); 23 | 24 | JTextField Textfield_H = new JTextField(5); 25 | JTextField Textfield_M = new JTextField(5); 26 | 27 | JButton Button_Set = new JButton("Set"); 28 | 29 | 30 | NiceAlarm(NiceLabels NL){ 31 | this.NL = NL; 32 | 33 | setBounds(800,450,300, 200); 34 | setTitle("Alarm"); 35 | setVisible(true); 36 | 37 | Panel_Row4.add(Label_Tips); 38 | Panel_Row3.add(Label_H); 39 | Panel_Row3.add(Textfield_H); 40 | Panel_Row2.add(Label_M); 41 | Panel_Row2.add(Textfield_M); 42 | Panel_Row1.add(Button_Set); 43 | 44 | Panel_Row4.setBackground(Color.WHITE); 45 | Panel_Row3.setBackground(Color.WHITE); 46 | Panel_Row2.setBackground(Color.WHITE); 47 | Panel_Row1.setBackground(Color.WHITE); 48 | 49 | Panel_Alarm.add(Panel_Row4); 50 | Panel_Alarm.add(Panel_Row3); 51 | Panel_Alarm.add(Panel_Row2); 52 | Panel_Alarm.add(Panel_Row1); 53 | 54 | add(Panel_Alarm); 55 | 56 | Textfield_H.addActionListener(this); 57 | Textfield_M.addActionListener(this); 58 | Button_Set.addActionListener(this); 59 | } 60 | 61 | @Override 62 | public void actionPerformed(ActionEvent e){ 63 | 64 | if(e.getSource() == Textfield_H){ 65 | NL.Label_Alarm.setText("Alarm: "+ 66 | Textfield_H.getText() +":"+ Textfield_M.getText()); 67 | 68 | } 69 | if(e.getSource() == Textfield_M){ 70 | NL.Label_Alarm.setText("Alarm: "+ 71 | Textfield_H.getText() +":"+ Textfield_M.getText()); 72 | } 73 | if(e.getSource() == Button_Set){ 74 | 75 | this.dispose(); 76 | new NiceTimer(Integer.valueOf(Textfield_H.getText()), 77 | Integer.valueOf(Textfield_M.getText()), NL).run(); 78 | 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /NiceClock.java: -------------------------------------------------------------------------------- 1 | //NiceClock.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import java.awt.geom.AffineTransform; 6 | import java.util.Calendar; 7 | 8 | import javax.swing.ImageIcon; 9 | import javax.swing.JPanel; 10 | 11 | class NiceClock extends JPanel{ 12 | private static final long serialVersionUID = 1L; //default 13 | ImageIcon I; 14 | 15 | public void paintComponent(Graphics G){ //draw components 16 | Graphics2D G2D = (Graphics2D)G; 17 | G2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 18 | G2D.setColor(Color.RED); 19 | 20 | G2D.drawImage(I.getImage(), 0, 0, getWidth(), getHeight(), I.getImageObserver()); //set background 21 | 22 | 23 | int x_Wideth = this.getWidth() / 2; //get the width of panel 24 | int y_Wideth = this.getHeight() / 2; //get the height of panel 25 | 26 | int radius = (int) (Math.min(this.getWidth(), this.getHeight()) * 0.8 * 0.5); //calculate the radius of clock 27 | 28 | for(int i = 0; i < 12; i++){ 29 | double angle = Math.PI / 180 * i * (360 / 12); 30 | int x = (x_Wideth - 4) + (int)((radius - 12) * Math.cos(angle)); 31 | int y = (y_Wideth + 4) + (int)((radius - 12) * Math.sin(angle)); 32 | 33 | int j = i + 3; 34 | if (j > 12) 35 | j = j - 12; 36 | 37 | G2D.drawString(Integer.toString(j), x, y); //add numbers to clock 38 | } 39 | 40 | AffineTransform old = G2D.getTransform(); //transform 2D coordinates to another 41 | 42 | for (int i = 0; i < 60; i++){ 43 | int w = i % 5 == 0 ? 6 : 3; 44 | 45 | G2D.fillRect(x_Wideth - 2, 28, w, 3); 46 | G2D.rotate(Math.toRadians(6), x_Wideth, y_Wideth); 47 | } // add marks to clock 48 | 49 | G2D.setTransform(old); 50 | 51 | Calendar C = Calendar.getInstance(); 52 | 53 | int hour = C.get(Calendar.HOUR_OF_DAY); 54 | int minute = C.get(Calendar.MINUTE); 55 | int second = C.get(Calendar.SECOND); 56 | 57 | double hour_angle = (hour - 12 + minute / 60d) * 360d / 12d; 58 | G2D.rotate(Math.toRadians(hour_angle), x_Wideth, y_Wideth); 59 | 60 | int x_hour_array[] = { x_Wideth, x_Wideth + 9, x_Wideth, x_Wideth - 9 }; 61 | int y_hour_array[] = { 65, y_Wideth, y_Wideth + 10, y_Wideth }; 62 | G2D.drawPolygon(x_hour_array, y_hour_array, x_hour_array.length); 63 | G2D.setTransform(old); 64 | 65 | double minute_angle = (minute + second / 60d) * 360d / 60d; 66 | G2D.rotate(Math.toRadians(minute_angle), x_Wideth, y_Wideth); 67 | int x_minute_array[] = { x_Wideth, x_Wideth + 6, x_Wideth, x_Wideth - 6 }; 68 | int y_minute_array[] = { 45, y_Wideth, y_Wideth + 12, y_Wideth }; 69 | G2D.drawPolygon(x_minute_array, y_minute_array, x_minute_array.length); 70 | G2D.setTransform(old); 71 | 72 | G2D.setBackground(Color.WHITE); 73 | } 74 | NiceClock(ImageIcon I){ 75 | this.I = I; 76 | } 77 | } -------------------------------------------------------------------------------- /NiceLabels.java: -------------------------------------------------------------------------------- 1 | //NiceLabels.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.Color; 5 | import java.awt.Font; 6 | import java.awt.GridLayout; 7 | import javax.swing.*; 8 | import java.util.Random; 9 | 10 | public class NiceLabels extends JPanel{ 11 | private static final long serialVersionUID = 1L; 12 | 13 | Color C = Color.WHITE; 14 | Random R = new Random(); 15 | JLabel Label_Alarm = new JLabel("Alarm: 00 : 00"); 16 | JLabel Label_Remind = new JLabel("Reminds: June.1st Children's Day"); 17 | JLabel Label_Tips = new JLabel("Tips: Pray/Marry/Bath/Trip"); 18 | 19 | 20 | NiceLabels(){ 21 | Label_Alarm.setFont(new Font("Arove", 1, 30)); 22 | Label_Alarm.setForeground(Color.BLUE); 23 | 24 | Label_Remind.setFont(new Font("Arove", 1, 30)); 25 | Label_Remind.setForeground(Color.BLUE); 26 | 27 | Label_Tips.setFont(new Font("Arove", 1, 30)); 28 | Label_Tips.setForeground(Color.BLUE); 29 | 30 | setLayout(new GridLayout(3, 1)); 31 | // setBackground(C); 32 | 33 | add(Label_Remind); 34 | add(Label_Tips); 35 | add(Label_Alarm); 36 | } 37 | 38 | String getTips(){ 39 | int i = R.nextInt(10); 40 | String S[] = new String[10]; 41 | S[0] = "Tips: Neither good nor bad"; 42 | S[1] = "Tips: No drink/Travel/Funeral"; 43 | S[2] = "Tips: Visit/Trade/Haircut/Trip"; 44 | S[3] = "Tips: No felling/Marry/Bath"; 45 | S[4] = "Tips: No pray/Build/Plant"; 46 | S[5] = "Tips: Do nothing/Unlucky day"; 47 | S[6] = "Tips: Pray/Marry/Bath/Trip"; 48 | S[7] = "Tips: No marry/No swim/Decorate"; 49 | S[8] = "Tips: No build/No trade/Mo felling"; 50 | S[9] = "Tips: Everything goes well"; 51 | 52 | return S[i]; 53 | } 54 | void getRemind(int num){ 55 | switch(num){ 56 | case 11: Label_Remind.setText("Reminds: Jan.1st NewYear's Day");break; 57 | case 214: Label_Remind.setText("Reminds: Feb.14th Valentine's Day");break; 58 | case 38: Label_Remind.setText("Reminds: Mar.8th Women's Day");break; 59 | case 41: Label_Remind.setText("Reminds: Apr.1st April Fool's Day");break; 60 | case 422: Label_Remind.setText("Reminds: Apr.22th Earth Day");break; 61 | case 51: Label_Remind.setText("Reminds: May 1st Labour Day");break; 62 | case 54: Label_Remind.setText("Reminds: May 4th Youth Day");break; 63 | case 57: Label_Remind.setText("Reminds: May 7th Hui's Birthday Day");break; 64 | case 61: Label_Remind.setText("Reminds: June.1st Children's Day");break; 65 | case 71: Label_Remind.setText("Reminds: July 1st CPC Founding Day");break; 66 | case 81: Label_Remind.setText("Reminds: Aug.1st Army Day");break; 67 | case 96: Label_Remind.setText("Reminds: Sept.6th My Birthday Day");break; 68 | case 910: Label_Remind.setText("Reminds: Sept.10th Teacher's Day");break; 69 | case 101: Label_Remind.setText("Reminds: Oct.1st National Day");break; 70 | case 1128: Label_Remind.setText("Reminds: Nov.28th Thanksgiving Day");break; 71 | case 1224: Label_Remind.setText("Reminds: Dec.24th Christmas Eve");break; 72 | case 1225: Label_Remind.setText("Reminds: Dec.25th Christmas Day");break; 73 | default: Label_Remind.setText("Reminds: NULL"); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /NiceMenubar.java: -------------------------------------------------------------------------------- 1 | //NiceMenuBar.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | 8 | public class NiceMenubar extends JMenuBar implements ActionListener{ 9 | private static final long serialVersionUID = 1L; 10 | 11 | NicePanel NP = new NicePanel(); //combine NicePanel 12 | NiceClock NC; //reference 13 | 14 | JMenu Menu_Start = new JMenu("Start(S) "); //menu Start 15 | JMenu Menu_Function = new JMenu("Function(F)"); //menu Function 16 | JMenu Menu_Help = new JMenu(" Help(H)"); //menu help 17 | 18 | JMenuItem Item_signIn = new JMenuItem("SignIn"); //item sign in //useless 19 | JMenuItem Item_signUp = new JMenuItem("SignUp"); //item sign up //useless 20 | 21 | JMenu Item_changeSkin = new JMenu("Skin"); //item change skin 22 | JMenuItem Item_Exit = new JMenuItem("Exit"); //finish system 23 | 24 | JMenuItem Item_Alarm = new JMenuItem("Alarm"); //item alarm 25 | JMenuItem Item_Skip = new JMenuItem("Skip"); //item skip to anywhere 26 | JMenuItem Item_lastYear = new JMenuItem("LastYear"); //skip to last year 27 | JMenuItem Item_nextYear = new JMenuItem("NextYear"); //skip to next year 28 | JMenuItem Item_lastMonth = new JMenuItem("LastMonth"); //skip to last month 29 | JMenuItem Item_nextMonth = new JMenuItem("NextMonth"); //skip to next month 30 | 31 | JMenuItem Item_Readme = new JMenuItem("Readme"); //show readme 32 | JMenuItem Item_Feedback= new JMenuItem("Feedback"); // show feed back 33 | JMenuItem Item_About = new JMenuItem("About"); //show about 34 | 35 | /*four kind of skins there */ 36 | JMenuItem Item_whiteSkin = new JMenuItem("QuietWhite"); 37 | JMenuItem Item_blackSkin = new JMenuItem("PureBlack"); 38 | JMenuItem Item_darkSkin = new JMenuItem("VesperalDark"); 39 | JMenuItem Item_yellowSkin = new JMenuItem("SoftYellow"); 40 | 41 | NiceMenubar(NiceClock NC){ 42 | this.NC = NC; 43 | 44 | /*add items to menu*/ 45 | Menu_Start.add(Item_signUp); 46 | Menu_Start.add(Item_signIn); 47 | Menu_Start.add(Item_changeSkin); 48 | Menu_Start.add(Item_Exit); 49 | 50 | Menu_Function.add(Item_Alarm); 51 | Menu_Function.add(Item_Skip); 52 | Menu_Function.add(Item_lastYear); 53 | Menu_Function.add(Item_nextYear); 54 | Menu_Function.add(Item_lastMonth); 55 | Menu_Function.add(Item_nextMonth); 56 | 57 | Menu_Help.add(Item_Readme); 58 | Menu_Help.add(Item_Feedback); 59 | Menu_Help.add(Item_About); 60 | 61 | Item_changeSkin.add(Item_whiteSkin); 62 | Item_changeSkin.add(Item_yellowSkin); 63 | Item_changeSkin.add(Item_blackSkin); 64 | Item_changeSkin.add(Item_darkSkin); 65 | 66 | /*add action listener */ 67 | Item_signUp.addActionListener(this); 68 | Item_signIn.addActionListener(this); 69 | Item_changeSkin.addActionListener(this); 70 | Item_Exit.addActionListener(this); 71 | 72 | Item_Alarm.addActionListener(this); 73 | Item_Skip.addActionListener(this); 74 | Item_lastYear.addActionListener(this); 75 | Item_nextYear.addActionListener(this); 76 | Item_lastMonth.addActionListener(this); 77 | Item_nextMonth.addActionListener(this); 78 | 79 | Item_Readme.addActionListener(this); 80 | Item_Feedback.addActionListener(this); 81 | Item_About.addActionListener(this); 82 | 83 | Item_blackSkin.addActionListener(this); 84 | Item_whiteSkin.addActionListener(this); 85 | Item_darkSkin.addActionListener(this); 86 | Item_yellowSkin.addActionListener(this); 87 | 88 | add(Menu_Start); 89 | add(Menu_Function); 90 | add(Menu_Help); 91 | changeSkin(Color.WHITE); //set default skin 92 | } 93 | 94 | public void actionPerformed(ActionEvent e){ 95 | 96 | if(e.getSource() == Item_Exit){ 97 | System.exit(0); //exit(0) 98 | } 99 | 100 | else if(e.getSource() == Item_Alarm){ 101 | new NiceAlarm(NP.NL); 102 | } 103 | 104 | else if(e.getSource() == Item_whiteSkin){ 105 | getComponent().setBackground(Color.WHITE); 106 | changeSkin(Color.WHITE); 107 | NC.I = new ImageIcon("WHITE.jpg"); 108 | NC.repaint(); 109 | } 110 | else if(e.getSource() == Item_blackSkin){ 111 | getComponent().setBackground(Color.BLACK); 112 | changeSkin(Color.BLACK); 113 | NC.I = new ImageIcon("BLACK.jpg"); 114 | NC.repaint(); 115 | } 116 | else if(e.getSource() == Item_darkSkin){ 117 | getComponent().setBackground(Color.DARK_GRAY); 118 | changeSkin(Color.DARK_GRAY); 119 | NC.I = new ImageIcon("DARK.jpg"); 120 | NC.repaint(); 121 | } 122 | else if(e.getSource() == Item_yellowSkin){ 123 | getComponent().setBackground(Color.YELLOW); 124 | changeSkin(Color.YELLOW); 125 | NC.I = new ImageIcon("YELLOW.jpg"); 126 | NC.repaint(); 127 | } 128 | 129 | else if(e.getSource() == Item_Skip){ 130 | new NiceSkip(NP); 131 | } 132 | else if(e.getSource() == Item_lastYear){ 133 | NP.NB.setYear(NP.NB.getYear()-1); //get year and minus one and set year again 134 | NP.refresh(); 135 | } 136 | else if(e.getSource() == Item_nextYear){ 137 | NP.NB.setYear(NP.NB.getYear()+1); 138 | NP.refresh(); 139 | } 140 | 141 | else if(e.getSource() == Item_lastMonth){ 142 | NP.NB.setMonth(NP.NB.getMonth() - 1); 143 | NP.refresh(); 144 | } 145 | else if(e.getSource() == Item_nextMonth){ 146 | NP.NB.setMonth(NP.NB.getMonth() + 1); 147 | NP.refresh(); 148 | } 149 | else if(e.getSource() == Item_Readme){ //readme 150 | JOptionPane.showMessageDialog(this, 151 | "I'm glad that you see this readme.\n" 152 | +"This is a calendar named 'NiceCalendar 5.0'.\n" 153 | +"I made it at 2019/6/3 when is a busy period.\n" 154 | +"Okay, that's all.\n" 155 | +"\t\t\t\tlofone" 156 | ,"Readme", 157 | JOptionPane.CLOSED_OPTION); 158 | } 159 | else if(e.getSource() == Item_About){ //about 160 | JOptionPane.showMessageDialog(this, 161 | "Name: lofone\nTeacher: Lei Lee\nMajor: HAUT CS F1702\nTell: 17073888338\nMore: www.github.com/lofon", 162 | "About", JOptionPane.CLOSED_OPTION); 163 | } 164 | } 165 | 166 | public void changeSkin(Color C){ //set all kinds of background 167 | 168 | NP.NL.setBackground(C); 169 | NP.Button_Current.setBackground(C); 170 | NP.Button_Current.setBackground(C); 171 | NP.Button_lastYear.setBackground(C); 172 | NP.Button_nextYear.setBackground(C); 173 | NP.Button_lastMonth.setBackground(C); 174 | NP.Button_nextMonth.setBackground(C); 175 | NP.Panel_South.setBackground(C); 176 | NP.Panel_North.setBackground(C); 177 | NP.Panel_Center.setBackground(C); 178 | NP.Label_Year.setBackground(C); 179 | NP.Label_Month.setBackground(C); 180 | NP.Label_Calendar.setBackground(C); 181 | 182 | for(int i = 0; i < 42; i ++){ 183 | NP.Button_Day[i].setBackground(C); 184 | } 185 | } //end of change skin 186 | } //end of class NiceMenubar -------------------------------------------------------------------------------- /NicePanel.java: -------------------------------------------------------------------------------- 1 | //NiceMenuPanel.java 2 | //////////////Written by lofone at 2019/6/3///////////////// 3 | 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.util.Calendar; 8 | 9 | import javax.swing.BorderFactory; 10 | import javax.swing.JButton; 11 | import javax.swing.JLabel; 12 | import javax.swing.JPanel; 13 | 14 | public class NicePanel extends JPanel implements ActionListener { 15 | private static final long serialVersionUID = 1L; 16 | NiceBase NB = new NiceBase(); 17 | NiceLabels NL = new NiceLabels(); 18 | 19 | JPanel Panel_Center = new JPanel(); 20 | JPanel Panel_South = new JPanel(); 21 | JPanel Panel_North = new JPanel(); 22 | 23 | JButton Button_Day[] = new JButton[42]; //7x6 24 | JLabel Label_Week[] = new JLabel[7]; //7days a week 25 | JButton Button_Current = new JButton("NOW"); //skip to now 26 | JButton Button_nextMonth = new JButton(">"); //skip to next month 27 | JButton Button_lastMonth = new JButton("<"); //skip to last month 28 | JButton Button_nextYear = new JButton(">>"); //skip to next year 29 | JButton Button_lastYear = new JButton("<<"); //skip to last year 30 | 31 | JLabel Label_Year = new JLabel("2019"); //defaykt year and month 32 | JLabel Label_Month = new JLabel("Jun."); 33 | JLabel Label_Calendar = new JLabel("Nice Calendar"); //title 34 | 35 | String Week[] = {"SUN", "MON", "TUE", "WED", "THR", "FRI", "SAT"}; 36 | 37 | 38 | NicePanel(){ 39 | setLayout(new BorderLayout()); //border layout 40 | 41 | Label_Calendar.setFont(new Font("Arove", 1, 30)); 42 | Label_Calendar.setForeground(Color.RED); 43 | 44 | Panel_Center.setLayout(new GridLayout(7, 7)); //Layout : 7X7 gird 45 | 46 | for(int i = 0; i < 7; i++){ //add week[] to panel 47 | Label_Week[i] = new JLabel(Week[i], JLabel.CENTER); 48 | Label_Week[i].setFont(new Font("Arvo", 1, 20)); 49 | Label_Week[i].setForeground(Color.GREEN); 50 | Label_Week[i].setBackground(NL.C); 51 | Panel_Center.add(Label_Week[i]); 52 | } 53 | for(int i = 0; i < 42; i++){ //add day[] to panel 54 | Button_Day[i] = new JButton("None"); 55 | Button_Day[i].setBorder(BorderFactory.createLineBorder(Color.WHITE)); 56 | Panel_Center.add(Button_Day[i]); 57 | } 58 | 59 | Label_Year.setFont(new Font("Arove", 1, 22)); 60 | Label_Year.setForeground(Color.CYAN); 61 | Label_Month.setFont(new Font("Arove", 1, 22)); 62 | Label_Month.setForeground(Color.CYAN); 63 | 64 | Panel_North.add(Label_Calendar); 65 | 66 | /*add */ 67 | Panel_South.add(Button_lastYear); 68 | Panel_South.add(Label_Year); 69 | Panel_South.add(Button_nextYear); 70 | Panel_South.add(Button_Current); 71 | Panel_South.add(Button_lastMonth); 72 | Panel_South.add(Label_Month); 73 | Panel_South.add(Button_nextMonth); 74 | 75 | /*set layout */ 76 | add(Panel_North, BorderLayout.NORTH); 77 | add(Panel_Center, BorderLayout.CENTER); 78 | add(Panel_South, BorderLayout.SOUTH); 79 | 80 | /*add action listener */ 81 | for(int i = 0; i < 42; i++){ 82 | Button_Day[i].addActionListener(this); 83 | } 84 | 85 | Button_lastYear.addActionListener(this); 86 | Button_nextYear.addActionListener(this); 87 | Button_Current.addActionListener(this); 88 | Button_lastMonth.addActionListener(this); 89 | Button_nextMonth.addActionListener(this); 90 | 91 | Button_Current.setFont(new Font("Arove", 1, 18)); 92 | Button_lastYear.setFont(new Font("Arove", 1, 18)); 93 | Button_nextYear.setFont(new Font("Arove", 1, 18)); 94 | Button_lastMonth.setFont(new Font("Arove", 1, 18)); 95 | Button_nextMonth.setFont(new Font("Arove", 1, 18)); 96 | } 97 | 98 | void refresh(){ 99 | String day[] = NB.getCalendar(); 100 | String month; 101 | for(int i = 0; i<42; i++){ 102 | Button_Day[i].setForeground(Color.CYAN); 103 | Button_Day[i].setFont(new Font("Arove", 1, 22)); 104 | Button_Day[i].setText(day[i]); 105 | 106 | } 107 | switch(NB.getMonth()){ 108 | case 1:month = " Jan. ";break; 109 | case 2:month = " Feb. ";break; 110 | case 3:month = " Mar. ";break; 111 | case 4:month = " Apr. ";break; 112 | case 5:month = " May ";break; 113 | case 6:month = " Jun. ";break; 114 | case 7:month = " Jul. ";break; 115 | case 8:month = " Aug. ";break; 116 | case 9:month = " Sept.";break; 117 | case 10:month = " Oct. ";break; 118 | case 11:month = " Nov. ";break; 119 | case 12:month = " Dec. ";break; 120 | default:month = " NULL "; 121 | } 122 | Label_Year.setText(" "+ NB.getYear() +" "); 123 | Label_Month.setText(month); 124 | } 125 | @Override 126 | public void actionPerformed(ActionEvent e) { 127 | 128 | if(e.getSource() == Button_Day[0]){ 129 | int number = Integer.valueOf(NB.getMonth() + Button_Day[0].getText()); 130 | NL.getRemind(number); 131 | NL.Label_Tips.setText(NL.getTips()); 132 | 133 | } 134 | else if(e.getSource() == Button_Day[1]){ 135 | int number = Integer.valueOf(NB.getMonth() + Button_Day[1].getText()); 136 | NL.getRemind(number); 137 | NL.Label_Tips.setText(NL.getTips()); 138 | } 139 | else if(e.getSource() == Button_Day[2]){ 140 | int number = Integer.valueOf(NB.getMonth() + Button_Day[2].getText()); 141 | NL.getRemind(number); 142 | NL.Label_Tips.setText(NL.getTips()); 143 | } 144 | else if(e.getSource() == Button_Day[3]){ 145 | int number = Integer.valueOf(NB.getMonth() + Button_Day[3].getText()); 146 | NL.getRemind(number); 147 | NL.Label_Tips.setText(NL.getTips()); 148 | } 149 | else if(e.getSource() == Button_Day[4]){ 150 | int number = Integer.valueOf(NB.getMonth() + Button_Day[4].getText()); 151 | NL.getRemind(number); 152 | NL.Label_Tips.setText(NL.getTips()); 153 | } 154 | else if(e.getSource() == Button_Day[5]){ 155 | int number = Integer.valueOf(NB.getMonth() + Button_Day[5].getText()); 156 | NL.getRemind(number); 157 | NL.Label_Tips.setText(NL.getTips()); 158 | } 159 | else if(e.getSource() == Button_Day[6]){ 160 | int number = Integer.valueOf(NB.getMonth() + Button_Day[6].getText()); 161 | NL.getRemind(number); 162 | NL.Label_Tips.setText(NL.getTips()); 163 | } 164 | else if(e.getSource() == Button_Day[7]){ 165 | int number = Integer.valueOf(NB.getMonth() + Button_Day[7].getText()); 166 | NL.getRemind(number); 167 | NL.Label_Tips.setText(NL.getTips()); 168 | } 169 | else if(e.getSource() == Button_Day[8]){ 170 | int number = Integer.valueOf(NB.getMonth() + Button_Day[6].getText()); 171 | NL.getRemind(number); 172 | NL.Label_Tips.setText(NL.getTips()); 173 | } 174 | else if(e.getSource() == Button_Day[9]){ 175 | int number = Integer.valueOf(NB.getMonth() + Button_Day[6].getText()); 176 | NL.getRemind(number); 177 | NL.Label_Tips.setText(NL.getTips()); 178 | } 179 | else if(e.getSource() == Button_Day[10]){ 180 | int number = Integer.valueOf(NB.getMonth() + Button_Day[10].getText()); 181 | NL.getRemind(number); 182 | NL.Label_Tips.setText(NL.getTips()); 183 | } 184 | else if(e.getSource() == Button_Day[11]){ 185 | int number = Integer.valueOf(NB.getMonth() + Button_Day[11].getText()); 186 | NL.getRemind(number); 187 | NL.Label_Tips.setText(NL.getTips()); 188 | } 189 | else if(e.getSource() == Button_Day[12]){ 190 | int number = Integer.valueOf(NB.getMonth() + Button_Day[12].getText()); 191 | NL.getRemind(number); 192 | NL.Label_Tips.setText(NL.getTips()); 193 | } 194 | else if(e.getSource() == Button_Day[13]){ 195 | int number = Integer.valueOf(NB.getMonth() + Button_Day[13].getText()); 196 | NL.getRemind(number); 197 | NL.Label_Tips.setText(NL.getTips()); 198 | } 199 | else if(e.getSource() == Button_Day[14]){ 200 | int number = Integer.valueOf(NB.getMonth() + Button_Day[14].getText()); 201 | NL.getRemind(number); 202 | NL.Label_Tips.setText(NL.getTips()); 203 | } 204 | else if(e.getSource() == Button_Day[15]){ 205 | int number = Integer.valueOf(NB.getMonth() + Button_Day[15].getText()); 206 | NL.getRemind(number); 207 | NL.Label_Tips.setText(NL.getTips()); 208 | } 209 | else if(e.getSource() == Button_Day[16]){ 210 | int number = Integer.valueOf(NB.getMonth() + Button_Day[16].getText()); 211 | NL.getRemind(number); 212 | NL.Label_Tips.setText(NL.getTips()); 213 | } 214 | else if(e.getSource() == Button_Day[17]){ 215 | int number = Integer.valueOf(NB.getMonth() + Button_Day[17].getText()); 216 | NL.getRemind(number); 217 | NL.Label_Tips.setText(NL.getTips()); 218 | } 219 | else if(e.getSource() == Button_Day[18]){ 220 | int number = Integer.valueOf(NB.getMonth() + Button_Day[18].getText()); 221 | NL.getRemind(number); 222 | NL.Label_Tips.setText(NL.getTips()); 223 | } 224 | else if(e.getSource() == Button_Day[19]){ 225 | int number = Integer.valueOf(NB.getMonth() + Button_Day[19].getText()); 226 | NL.getRemind(number); 227 | NL.Label_Tips.setText(NL.getTips()); 228 | } 229 | else if(e.getSource() == Button_Day[21]){ 230 | int number = Integer.valueOf(NB.getMonth() + Button_Day[20].getText()); 231 | NL.getRemind(number); 232 | NL.Label_Tips.setText(NL.getTips()); 233 | 234 | } 235 | else if(e.getSource() == Button_Day[22]){ 236 | int number = Integer.valueOf(NB.getMonth() + Button_Day[22].getText()); 237 | NL.getRemind(number); 238 | NL.Label_Tips.setText(NL.getTips()); 239 | 240 | } 241 | else if(e.getSource() == Button_Day[23]){ 242 | int number = Integer.valueOf(NB.getMonth() + Button_Day[23].getText()); 243 | NL.getRemind(number); 244 | NL.Label_Tips.setText(NL.getTips()); 245 | 246 | } 247 | else if(e.getSource() == Button_Day[24]){ 248 | int number = Integer.valueOf(NB.getMonth() + Button_Day[24].getText()); 249 | NL.getRemind(number); 250 | NL.Label_Tips.setText(NL.getTips()); 251 | 252 | } 253 | else if(e.getSource() == Button_Day[25]){ 254 | int number = Integer.valueOf(NB.getMonth() + Button_Day[25].getText()); 255 | NL.getRemind(number); 256 | NL.Label_Tips.setText(NL.getTips()); 257 | 258 | } 259 | else if(e.getSource() == Button_Day[26]){ 260 | int number = Integer.valueOf(NB.getMonth() + Button_Day[26].getText()); 261 | NL.getRemind(number); 262 | NL.Label_Tips.setText(NL.getTips()); 263 | 264 | } 265 | else if(e.getSource() == Button_Day[27]){ 266 | int number = Integer.valueOf(NB.getMonth() + Button_Day[27].getText()); 267 | NL.getRemind(number); 268 | NL.Label_Tips.setText(NL.getTips()); 269 | 270 | } 271 | else if(e.getSource() == Button_Day[28]){ 272 | int number = Integer.valueOf(NB.getMonth() + Button_Day[28].getText()); 273 | NL.getRemind(number); 274 | NL.Label_Tips.setText(NL.getTips()); 275 | 276 | } 277 | else if(e.getSource() == Button_Day[29]){ 278 | int number = Integer.valueOf(NB.getMonth() + Button_Day[29].getText()); 279 | NL.getRemind(number); 280 | NL.Label_Tips.setText(NL.getTips()); 281 | 282 | } 283 | else if(e.getSource() == Button_Day[30]){ 284 | int number = Integer.valueOf(NB.getMonth() + Button_Day[30].getText()); 285 | NL.getRemind(number); 286 | NL.Label_Tips.setText(NL.getTips()); 287 | 288 | } 289 | else if(e.getSource() == Button_Day[31]){ 290 | int number = Integer.valueOf(NB.getMonth() + Button_Day[31].getText()); 291 | NL.getRemind(number); 292 | NL.Label_Tips.setText(NL.getTips()); 293 | } 294 | else if(e.getSource() == Button_Day[32]){ 295 | int number = Integer.valueOf(NB.getMonth() + Button_Day[32].getText()); 296 | NL.getRemind(number); 297 | NL.Label_Tips.setText(NL.getTips()); 298 | } 299 | else if(e.getSource() == Button_Day[33]){ 300 | int number = Integer.valueOf(NB.getMonth() + Button_Day[33].getText()); 301 | NL.getRemind(number); 302 | NL.Label_Tips.setText(NL.getTips()); 303 | } 304 | else if(e.getSource() == Button_Day[34]){ 305 | int number = Integer.valueOf(NB.getMonth() + Button_Day[34].getText()); 306 | NL.getRemind(number); 307 | NL.Label_Tips.setText(NL.getTips()); 308 | } 309 | else if(e.getSource() == Button_Day[35]){ 310 | int number = Integer.valueOf(NB.getMonth() + Button_Day[35].getText()); 311 | NL.getRemind(number); 312 | NL.Label_Tips.setText(NL.getTips()); 313 | } 314 | else if(e.getSource() == Button_Day[36]){ 315 | int number = Integer.valueOf(NB.getMonth() + Button_Day[36].getText()); 316 | NL.getRemind(number); 317 | NL.Label_Tips.setText(NL.getTips()); 318 | } 319 | else if(e.getSource() == Button_Day[37]){ 320 | int number = Integer.valueOf(NB.getMonth() + Button_Day[37].getText()); 321 | NL.getRemind(number); 322 | NL.Label_Tips.setText(NL.getTips()); 323 | } 324 | else if(e.getSource() == Button_Day[38]){ 325 | int number = Integer.valueOf(NB.getMonth() + Button_Day[38].getText()); 326 | NL.getRemind(number); 327 | NL.Label_Tips.setText(NL.getTips()); 328 | } 329 | else if(e.getSource() == Button_Day[39]){ 330 | int number = Integer.valueOf(NB.getMonth() + Button_Day[39].getText()); 331 | NL.getRemind(number); 332 | NL.Label_Tips.setText(NL.getTips()); 333 | } 334 | else if(e.getSource() == Button_Day[40]){ 335 | int number = Integer.valueOf(NB.getMonth() + Button_Day[40].getText()); 336 | NL.getRemind(number); 337 | NL.Label_Tips.setText(NL.getTips()); 338 | } 339 | else if(e.getSource() == Button_Day[41]){ 340 | int number = Integer.valueOf(NB.getMonth() + Button_Day[41].getText()); 341 | NL.getRemind(number); 342 | NL.Label_Tips.setText(NL.getTips()); 343 | } 344 | 345 | 346 | if(e.getSource() == Button_lastYear){ 347 | NB.setYear(NB.getYear()-1); 348 | refresh(); 349 | } 350 | 351 | else if(e.getSource() == Button_nextYear){ 352 | NB.setYear(NB.getYear()+1); 353 | refresh(); 354 | } 355 | 356 | else if(e.getSource() == Button_Current){ 357 | Calendar C = Calendar.getInstance(); 358 | int year = C.get(Calendar.YEAR); 359 | int month = C.get(Calendar.MONTH)+1; 360 | NB.setYear(year); 361 | NB.setMonth(month); 362 | refresh(); 363 | } 364 | else if(e.getSource() == Button_lastMonth){ 365 | 366 | NB.setMonth(NB.getMonth() - 1); 367 | refresh(); 368 | 369 | } 370 | else if(e.getSource() == Button_nextMonth){ 371 | NB.setMonth(NB.getMonth() + 1); 372 | refresh(); 373 | } 374 | 375 | } 376 | 377 | } --------------------------------------------------------------------------------