-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorldPanel.java
More file actions
48 lines (41 loc) · 1.39 KB
/
Copy pathWorldPanel.java
File metadata and controls
48 lines (41 loc) · 1.39 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
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.util.ArrayList;
import java.awt.event.*;
import java.util.Comparator;
public class WorldPanel extends JPanel implements ActionListener {
World world = new World();
private JButton play;
public WorldPanel() {
this.setPreferredSize(new Dimension(700, 500));
this.setBackground(Color.WHITE);
play = new JButton("Play");
play.addActionListener(this);
this.add(play);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
world.draw(g);
repaint();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().getClass().getName().equals("javax.swing.JButton")) {
if (((JButton) e.getSource()).getText().equals("Play")) {
for(Cell cell: DataSource.getInstance().getCellArrayInstance()){
cell.setColor(Color.BLACK);
}
world.play();
Boolean res = world.compare();
if (res){
showSuccessPopup();
}
}
}
}
public void showSuccessPopup() {
JOptionPane.showMessageDialog(this, "Congratulations! You may now move onto the next level!", "Success", JOptionPane.INFORMATION_MESSAGE);
}
}