forked from ahmetoguzazik2005/No-Limit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFrame.java
More file actions
116 lines (93 loc) · 3.7 KB
/
Copy pathMyFrame.java
File metadata and controls
116 lines (93 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class MyFrame extends JFrame implements ActionListener {
// For global scope inside class
JButton button1;
JButton button2;
JButton button3;
JButton button4;
CardLayout cardLayout;
JPanel right;
MyFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1000, 600);
setLocationRelativeTo(null);
// Change to GridBagLayout
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
// Left panel (sidebar) - 2 parts
JPanel left = new JPanel();
left.setPreferredSize(new Dimension(200, 0));
left.setBackground(new Color(173, 216, 230)); // soft blue
left.setLayout(new GridLayout(0, 1, 0, 10));
left.setBorder(new EmptyBorder(16, 12, 16, 12));
// GridBag constraints for left panel
gbc.gridx = 0; // First column
gbc.gridy = 0; // First row
gbc.weightx = 1.0; // 4 parts of horizontal space
gbc.weighty = 1.0; // Full vertical space
gbc.fill = GridBagConstraints.BOTH; // Fill both directions
add(left, gbc);
button1 = createSidebarButton("Stopwatch");
left.add(button1);
button2 = createSidebarButton("Today");
left.add(button2);
button3 = createSidebarButton("Track");
left.add(button3);
button4 = createSidebarButton("Settings");
left.add(button4);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
// Right panel (main content) - 3 parts
right = new JPanel();
cardLayout = new CardLayout();
right.setLayout(cardLayout);
// GridBag constraints for right panel
gbc.gridx = 1; // Second column
gbc.gridy = 0; // First row
gbc.weightx = 4.0; // 1 part of horizontal space
gbc.weighty = 1.0; // Full vertical space
gbc.fill = GridBagConstraints.BOTH; // Fill both directions
add(right, gbc);
// Other sub panels initialization
StopWatchPanel stopwatchPanel = new StopWatchPanel();
TodayPanel todayPanel = new TodayPanel();
TrackPanel trackPanel = new TrackPanel();
SettingsPanel settingsPanel = new SettingsPanel();
right.add(stopwatchPanel, "StopwatchPanel");
right.add(todayPanel, "TodayPanel");
right.add(trackPanel, "TrackPanel");
right.add(settingsPanel, "SettingsPanel");
cardLayout.show(right, "StopwatchPanel");
setVisible(true);
}
private JButton createSidebarButton(String text) {
JButton btn = new AnimatedPressButton(text);
btn.setFocusPainted(false);
btn.setFont(btn.getFont().deriveFont(Font.PLAIN, 32f));
btn.setMargin(new Insets(10, 12, 10, 12)); // internal padding
btn.setHorizontalAlignment(SwingConstants.CENTER); // align labels nicely
return btn;
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
cardLayout.show(right, "StopwatchPanel");
} else if (e.getSource() == button2) {
cardLayout.show(right, "TodayPanel");
} else if (e.getSource() == button3) {
cardLayout.show(right, "TrackPanel");
} else if (e.getSource() == button4) {
cardLayout.show(right, "SettingsPanel");
}
}
}