-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCARuleDescription.java
More file actions
144 lines (113 loc) · 4.55 KB
/
Copy pathCARuleDescription.java
File metadata and controls
144 lines (113 loc) · 4.55 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package edu.neu.csye6200.ca;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/*
* @author: Dileep Reddy
* NUID: 001063317
* Class Description: CARuleDescription creates a new frame to disploay the rule descriptions on the frame.
* Since it is needed to be created only once I have used singleton pattern
*/
//Singleton Pattern
public class CARuleDescription implements WindowListener {
protected static JFrame ruleFrame = null;
protected JPanel mainPanel = null;
protected JTextArea textArea = null;
private static CARuleDescription instance = null;
private CARuleDescription() {
ruleFrame = new JFrame();
initGUI();
writeDescription();
}
public static CARuleDescription getInstance() {
if(instance == null)
instance = new CARuleDescription();
CARuleDescription.ruleFrame.setVisible(true);
return instance;
}
/**
* Initialize the Graphical User Interface
*/
public void initGUI() {
System.out.println("View Rules");
ruleFrame.setSize(500, 400);
ruleFrame.setTitle("Rules");
ruleFrame.setResizable(true);
// Permit the app to hear about the window opening
ruleFrame.addWindowListener(this);
ruleFrame.setLayout(new BorderLayout());
ruleFrame.add(getMainPanel(),BorderLayout.CENTER);
ruleFrame.setVisible(true);
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
/**
* @return the main panel that holds the details of rules
*/
public JPanel getMainPanel() {
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.setBackground(Color.BLACK);
textArea = new JTextArea();
textArea.setPreferredSize(new Dimension(100,100));
textArea.setBackground(Color.BLACK);
textArea.setForeground(Color.white);
mainPanel.add(BorderLayout.CENTER, textArea);
return mainPanel;
}
private void writeDescription() {
textArea.setForeground(Color.white);
textArea.append("Rule 1 : Single Crystal");
textArea.append("\nDescription: ");
textArea.append("In this rule, initially only once cell in the center will be Frozen \r\n" +
" and in the next iteration if only one cell around the cell in the previous crystal is Frozen \r \n" +
" the state of the cell be transitioned to Frozen in the next iteration");
textArea.append("\n\nRule 2 : Random Crystal Growth");
textArea.append("\nDescription: ");
textArea.append("Cells in the nature are not always uniform. \r \n Through this rule I would like to simulate random crystal like in nature\r\n"+
" and do the simulation. In this rule, initially 15 random liquid state cells \r \n and 10 random Frozen cell states are created in the grid.");
textArea.append("\n\nRule 3 : Butterfly");
textArea.append("\nDescription: Crystal growth is very fascinating. So I have decided to check how the crystal grows \r\n" +
" if there are small cells of frozen and liquid cells in the shape of a star. \r\n" +
" Turns out it takes the shape of the butterfly");
textArea.append("\n\nRule 4 : Highway");
textArea.append("\nDescription: Crystal growth is very fascinating. So I have decided to check how the crystal grows \r\n" +
" if there are small cells of frozen and liquid cells in the shape of a big cross. \r\n" +
" Turns out it takes the shape of the highway");
textArea.append("\n\nRule 5 : Garden");
textArea.append("\nDescription: Crystal growth is very fascinating. So I have decided to check how the crystal grows \r\n" +
" if there are small cells of frozen and liquid cells in the equal gaps. \r\n" +
" Turns out it takes the shape of the garden with the help of following logic which is self-explanatory");
}
}