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/Qatar";
LocalDate LocalDate;
LocalTime LocalTime;
DateTimeFormatter DateForm, TimeForm;
String NowDate, NowTime;
JLabel obj;
public Clock(JLabel lbl) {
this.obj = lbl;
}
@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);
obj.setText(NowDate + " " + NowTime + "|:|");
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 JDialog {
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;
JLabel lbl;
TemBar = new JMenuBar();
menus = new JMenu();
items = new JMenuItem();
lbl = new JLabel();
TemBar.add(lbl);
Thread th = new Clock(lbl);
th.start();
// menus - Setting 생성
menus = new JMenu("Setting");
TemBar.add(menus);
// menus의 JMenuItem 생성 - 탭 추가
items = new JMenuItem("탭 추가");
items.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DialogPanel d = new DialogPanel();
d.show();
}
});
menus.add(items);
//menus의 JMenuItem 생성 - 날짜 설정
items = new JMenuItem("날짜 설정");
items.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Dialog d = new Calendar();
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 line
CmpBtn = new JButton();
CmpBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int rult = JOptionPane.showConfirmDialog(null, "이 설정의 탭을 제작하시겠습니까?", "Check request", JOptionPane.YES_NO_OPTION);
if(rult == JOptionPane.YES_OPTION) {
Name = NameFld.getText().equals("") ? "새 탭"
: NameFld.getText();
TabPanel pnl = TabImg.equals("") ? new TabPanel(new ImageIcon("C:\\Users\\user\\Desktop\\Daily Notes Images\\Default Tab.jpg"))
: new TabPanel(new ImageIcon(TabImg));
tab.addTab(Name, pnl);
Name = "";
TabImg = "";
NameFld.setText("");
}
}
});
CmpBtn.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\Daily Notes Images\\check.png"));
CmpBtn.setToolTipText("설정한 배경화면과 이름으로 새로운 탭을 생성합니다.");
TTB.add(CmpBtn);
//----------------------------------------------------------------------
//LoadBtn line
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"));
LoadBtn.setToolTipText("새로운 탭의 배경화면을 설정합니다.");
TTB.add(LoadBtn);
//----------------------------------------------------------------------
//NameFld line
NameFld = new JTextField(2);
NameFld.setToolTipText("새로운 탭의 이름을 설정합니다.");
TTB.add(NameFld);
//----------------------------------------------------------------------
return TTB;
}
}
class WorldTimeChecker extends JDialog {
private String [] ZoneId = {"Asia/Seoul\\(대한민국, 서울\\)",
"Asia/Chongqing\\(중화인민공화국, 충칭\\)",
"Asia/Harbin\\(중화인민공화국, 하얼빈\\)",
"Asia/Kashgar\\(중화인민공화국, 카슈가르\\)",
"Asia/Shanghai\\(중화인민공화국, 상하이\\)",
"Asia/Urumqi\\(중화인민공화국, 우루무치\\)",
"Asia/Tokyo\\(일본, 도쿄\\)"
};
}
}
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(715, 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);
repaint();
revalidate();
Filter k = new Filter();
k.Filtering("hello");
}
public static void main(String[] args) {
new Main();
}
}
class Filter{
void encryption(String n) {
char [] str = n.toCharArray();
StringBuilder TemStr = new StringBuilder("");
for(int i = 0; i < str.length; i++) {
int k = str[i];
String s = Integer.toString(k);
TemStr.append(s.length() + s);
}
str = TemStr.toString().toCharArray();
TemStr = new StringBuilder("");
System.out.println(str);
for(int i = 0; i < str.length; i++) {
int k = str[i];
k = Integer.parseInt(Integer.toString((127 - k), 2));
TemStr.append(k + "9");
}
str = TemStr.toString().toCharArray();
TemStr = new StringBuilder("");
System.out.println(str);
}
}