import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.event.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.util.*;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.DayOfWeek;
class Clock extends Thread {
String location = "Asia/Seoul";
LocalDate LocalDate;
LocalTime LocalTime;
DateTimeFormatter DateForm,TimeForm;
String NowDate,NowTime;
@Override
public void run() {
DateForm = DateTimeFormatter.ofPattern("yyyy/MM/dd");
GetDate();
while(true) {
LocalTime = LocalTime.now(ZoneId.of(location));
TimeForm = DateTimeFormatter.ofPattern("HH: mm: ss");
NowTime = LocalTime.format(TimeForm);
try {
if(LocalTime.getHour() == 0) {
GetDate();
}
Thread.sleep(125);
}
catch(InterruptedException e) {
return;
}
}
}
public void GetDate() {
LocalDate = LocalDate.now(ZoneId.of(location));
NowDate = LocalDate.format(DateForm);
}
}
class Calendar extends JFrame {
int [] CommonYear = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
LeapYear = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
JPanel DatePanel,YMPanel;
Container cnt;
public Calendar() {
setTitle("캘린더");
setSize(600,400);
setVisible(true);
cnt = getContentPane();
cnt.setLayout(new BorderLayout());
YMPanel = new JPanel();
YMPanel.setBackground(Color.gray);
cnt.add(YMPanel, BorderLayout.NORTH);
DatePanel = CreateDatePanel(1, 5);
cnt.add(DatePanel, BorderLayout.CENTER);
}
public JPanel CreateDatePanel(int year, int month) {
JPanel TemporaryPanel;
TemporaryPanel = new JPanel();
TemporaryPanel.setBackground(Color.DARK_GRAY);
TemporaryPanel.setLayout(new GridLayout(0, 7, 5, 5));
for(int i = 1; i <=7; i++) {
//JPanel
}
for(int i = 1; i <= CommonYear[month-1]; i++) {
JButton TemButton = new JButton();
TemporaryPanel.add(TemButton);
TemButton.setForeground(Color.black);
TemButton.setHorizontalAlignment(SwingConstants.CENTER);
TemButton.setText(i + "일");
TemButton.setOpaque(false);
TemButton.setFont(new Font("Gothic", Font.BOLD , 15));
//int DayOfWeekNumber = (new LocalDate(this.year, this.month, i).getDayOfWeek()).getValue();
TemButton.setContentAreaFilled(false);
TemButton.setBorder(new LineBorder(Color.white));
}
return TemporaryPanel;
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
class SouPnl extends Panel {
JTabbedPane tab;
JMenuBar bar;
public SouPnl() {
//이 클래스로 만들어지는 Panel 설정
this.setBackground(Color.DARK_GRAY);
this.setLayout(new BorderLayout());
//JMenuBar 생성
bar = JMenBar();
this.add(bar,BorderLayout.NORTH);
//JTabbedPane 생성
tab = JTabPane();
this.add(tab,BorderLayout.CENTER);
this.repaint();
this.revalidate();
}
private JTabbedPane JTabPane() {
JTabbedPane TemPane;
TemPane = new JTabbedPane();
return TemPane;
}
private JMenuBar JMenBar() {
JMenuBar TemBar;
JMenu menus;
JMenuItem items;
TemBar = new JMenuBar();
menus = new JMenu();
items = new JMenuItem();
//menus - Setting 생성
menus = new JMenu("Setting");
TemBar.add(menus);
//menus의 JMenuItem 생성
items = new JMenuItem("add");
items.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DialogPanel d = new DialogPanel();
d.show();
}
});
menus.add(items);
return TemBar;
}
class DialogPanel extends JDialog {
JToolBar TLBar;
String TabImg = "", Name = "";
JTextField NameFld;
public DialogPanel() {
setTitle("탭 생성 다이얼로그(Tab Adding Dialog)");
this.setSize(400,500);
this.setVisible(true);
this.setLayout(new BorderLayout());
TLBar = TBarCreate();
this.add(TLBar,BorderLayout.NORTH);
}
private JToolBar TBarCreate() {
JToolBar TTB;
JButton LoadBtn,CmpBtn;
TTB = new JToolBar();
CmpBtn = new JButton();
CmpBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Name = NameFld.getText();
TabPanel pnl = new TabPanel(new ImageIcon(TabImg));
tab.addTab(Name, pnl);
}
});
CmpBtn.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\Daily Notes Images\\check.png"));
TTB.add(CmpBtn);
LoadBtn = new JButton();
LoadBtn.addActionListener(new ActionListener() {
JFileChooser chser = new JFileChooser();;
FileNameExtensionFilter FNEF = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
@Override
public void actionPerformed(ActionEvent e) {
chser.setFileFilter(FNEF);
int ret = chser.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION) {
TabImg = chser.getSelectedFile().getPath();
}
System.out.println(ret);
}
});
LoadBtn.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\Daily Notes Images\\Input Floppy Disk.png"));
TTB.add(LoadBtn);
NameFld = new JTextField(2);
TTB.add(NameFld);
return TTB;
}
}
}
class TabPanel extends JPanel {
ImageIcon imgs;
Image img;
public TabPanel(ImageIcon i) {
imgs = i;
img = imgs.getImage();
}
public void paintComponent(Graphics g) {
super.paintComponents(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
public class Main extends JFrame {
Container cnt;
SouPnl SouthPanel;
//Vector<Tab> records = new Vector<Tab>();
public Main() {
setTitle("하루 일과 정리");
setSize(500,715);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
cnt = getContentPane();
cnt.setLayout(new BorderLayout());
SouthPanel = new SouPnl();
cnt.add(SouthPanel);
cnt.add(SouthPanel,BorderLayout.CENTER);
//new Calendar();
}
public static void main(String[] args) {
new Main();
}
}