MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / clone

Method clone

Programs/Games/peg-solitaire/PegSolitaire.java:134–180  ·  view source on GitHub ↗

Properly overridden clone method @return A copy of PegSolitaire object.

()

Source from the content-addressed store, hash-verified

132 * @return A copy of PegSolitaire object.
133 */
134 public PegSolitaire clone(){
135 try{
136 //CLONING DATA FIELDS
137 PegSolitaire copy = (PegSolitaire) super.clone();
138 copy.grid = new GridLayout(grid.getRows(), grid.getColumns(), grid.getHgap(), grid.getVgap());
139
140 copy.board = new JButton[board.length][board.length];
141 for (int i = 0; i < board.length; ++i){
142 for (int j = 0; j < board.length; ++j){
143 copy.board[i][j] = new JButton();
144 copy.board[i][j].setBackground(board[i][j].getBackground());
145 }
146 }
147
148 copy.moves = new ArrayList<Integer>(moves);
149
150 copy.reset = new JButton(reset.getText());
151 copy.load = new JButton(load.getText());
152 copy.save = new JButton(save.getText());
153 copy.undo = new JButton(undo.getText());
154 copy.auto = new JButton(auto.getText());
155 copy.autoAll = new JButton(autoAll.getText());
156 copy.pegNumber = new JButton(pegNumber.getText());
157 copy.emptyCells = new JButton(emptyCells.getText());
158 copy.pegsOut = new JButton(pegsOut.getText());
159
160 copy.type1 = new JRadioButton(type1.getText());
161 copy.type2 = new JRadioButton(type2.getText());
162 copy.type3 = new JRadioButton(type3.getText());
163 copy.type4 = new JRadioButton(type4.getText());
164 copy.type5 = new JRadioButton(type5.getText());
165 copy.type6 = new JRadioButton(type6.getText());
166
167 copy.radios = new ButtonGroup();
168 radios.add(copy.type1);
169 radios.add(copy.type2);
170 radios.add(copy.type3);
171 radios.add(copy.type4);
172 radios.add(copy.type5);
173 radios.add(copy.type6);
174
175 return copy;
176 }
177 catch (CloneNotSupportedException e){
178 return null; //never happen
179 }
180 }
181
182 /**
183 * Overridden equals method comparing PegSolitaire objects.

Callers

nothing calls this directly

Calls 1

addMethod · 0.65

Tested by

no test coverage detected