-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
79 lines (65 loc) · 2.42 KB
/
Copy pathTask.java
File metadata and controls
79 lines (65 loc) · 2.42 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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Task extends JPanel {
private JLabel index;
private JTextField name;
private JButton done;
private boolean checked;
public Task(String taskName) {
this.setPreferredSize(new Dimension(400, 50)); // a bit taller for padding
this.setBackground(new Color(0, 102, 204)); // lighter blue
this.setLayout(new BorderLayout());
// Add a compound border: gray line + padding inside
this.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.GRAY, 1),
BorderFactory.createEmptyBorder(5, 10, 5, 10)
));
checked = false;
index = new JLabel("");
index.setPreferredSize(new Dimension(30, 30));
index.setHorizontalAlignment(JLabel.CENTER);
index.setForeground(Color.WHITE);
index.setFont(new Font("Arial", Font.BOLD, 16));
this.add(index, BorderLayout.WEST);
name = new JTextField(taskName);
name.setEditable(true);
name.setForeground(Color.WHITE);
name.setBackground(new Color(0, 102, 204));
name.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
name.setFont(new Font("Arial", Font.PLAIN, 14));
this.add(name, BorderLayout.CENTER);
done = new JButton("Done");
done.setPreferredSize(new Dimension(80, 30));
done.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
done.setBackground(Color.GREEN);
done.setForeground(Color.BLACK);
done.setFocusPainted(false);
done.setMargin(new Insets(5, 10, 5, 10));
this.add(done, BorderLayout.EAST);
}
public JButton getDone() {
return done;
}
public void changeIndex(int num) {
this.index.setText(num + "");
this.revalidate();
this.repaint();
}
public void changeState() {
this.setBackground(Color.GREEN.darker());
this.name.setBackground(Color.GREEN.darker());
this.name.setEditable(false);
checked = true;
}
public boolean isChecked() {
return checked;
}
}