import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
//ver 2023.01.04
class Time extends Thread {
LocalDateTime clock;
ZoneId map = ZoneId.of("Asia/Seoul");
JLabel shower;
public Time(JLabel lbl) {
clock = LocalDateTime.now(map);
this.shower = lbl;
}
@Override
public void run() {
while(true) {
clock = LocalDateTime.now(map);
shower.setText(
clock.getYear() + "/ " +(Integer.toString(clock.getMonthValue()).length() == 1 ? "0" : "") + clock.getMonthValue() + "/ " + (Integer.toString(clock.getDayOfYear()).length() == 1 ? "0" : "") + clock.getDayOfYear()
+ " |:| " + (Integer.toString(clock.getHour()).length() == 1 ? "0" : "") + clock.getHour() + ": " + (Integer.toString(clock.getMinute()).length() == 1 ? "0" : "") + clock.getMinute() + ": " + (Integer.toString(clock.getSecond()).length() == 1 ? "0" : "") + clock.getSecond()
+" ");
try {
Thread.sleep(125);
}
catch (InterruptedException e) {
return;
}
}
}
}
public class Main extends JFrame {
Container cnt = getContentPane();
public Main() {
setTitle("Main");
setSize(500,700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
cnt.add(new Bar(), BorderLayout.NORTH);
cnt.add(new TabPane(), BorderLayout.CENTER);
}
class Bar extends JMenuBar {
JMenu [] Menu = new JMenu[4];
HashMap<JMenu, Vector<JMenuItem>> Item = new HashMap<JMenu, Vector<JMenuItem>>();
JLabel timeshower = new JLabel();
Time th = new Time(timeshower);
public Bar() {
this.add(timeshower);
for(int i = 0; i < Menu.length; i++) {
Menu[i] = new JMenu();
Item.put(Menu[i], new Vector<JMenuItem>());
this.add(Menu[i]);
}
Menu[0].setText("Setting");
th.start();
}
}
class TabPane extends JTabbedPane {
JButton AddTab = new JButton();
Vector<JPanel> tab = new Vector<JPanel>();
public TabPane() {
tab.add(new JPanel());
//this.addTab("New Tab",tab.get(0));
AddTab.setOpaque(false);
AddTab.setBorder(null);
AddTab.setContentAreaFilled(false);
AddTab.setFocusPainted(false);
this.add("+",AddTab);
change();
this.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
change();
}
});
this.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) { }
@Override
public void mousePressed(MouseEvent e) { }
@Override
public void mouseExited(MouseEvent e) { }
@Override
public void mouseEntered(MouseEvent e) { }
@Override
public void mouseClicked(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON3) {
}
}
});
}
public void change() {
if(this.getSelectedComponent().equals(AddTab)) {
tab.add(new JPanel());
this.remove(AddTab);
this.addTab("New Tab", tab.get(tab.size()-1));
this.add("+",AddTab);
}
}
}
public static void main(String[] args) {
new Main();
}
}