- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodePanel.java
More file actions
Latest commit
82 lines (67 loc) · 1.96 KB
/
Copy pathNodePanel.java
File metadata and controls
82 lines (67 loc) · 1.96 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
importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.Graphics;
importjava.awt.event.MouseEvent;
importjava.awt.event.MouseListener;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
publicclassNodePanelextendsJPanelimplementsMouseListener{
publicstaticString[] abc = {"A","B","C","D","E","F","G","H","I","J","K","L"};
privateintindex;
privateCircuitGraphicPanelcp;
publicNodePanel(intindex, CircuitGraphicPanelcp) {
super();
this.cp=cp;
this.index=index;
this.setPreferredSize(newDimension(30,30));
this.setBackground(Color.WHITE);
this.addMouseListener(this);
this.add(newJLabel(NodePanel.abc[index-1]));
}
publicvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
g.setColor(newColor(34,139,34));
g.fillOval(0, 0, 30, 30);
g.setColor(Color.GREEN);
g.fillOval(5, 5, 20, 20);
}
publicintgetIndex() {
returnthis.index;
}
@Override
publicvoidmouseClicked(MouseEvente) {
if(this.cp.getCN()==null) {
this.cp.setCN(this);
}
elseif(this.cp.getNN()!=null){
this.cp.setCN(this);
this.cp.setNN(null);
}
elseif(Math.abs(this.getIndex()-this.cp.getCN().getIndex())==1||(this.getIndex()*this.cp.getCN().getIndex()<40&&this.getIndex()+this.cp.getCN().getIndex()==13)){
this.cp.setNN(this);
}
else {
JOptionPane.showMessageDialog(null, "These nodes can't be connected. Please try again");
this.cp.setCN(null);
this.cp.setNN(null);
}
this.cp.drawNodeLabel();
}
@Override
publicvoidmouseEntered(MouseEventarg0) {
// TODO Auto-generated method stub
}
@Override
publicvoidmouseExited(MouseEventarg0) {
// TODO Auto-generated method stub
}
@Override
publicvoidmousePressed(MouseEventarg0) {
// TODO Auto-generated method stub
}
@Override
publicvoidmouseReleased(MouseEventarg0) {
// TODO Auto-generated method stub
}
}