OOP2

MainWindow.java

1
import javax.swing.*;
2
3
/**
4
 * MainWindow represents the main window of this program. It serves as a container for the other panels.
5
 * @author Maarten Vangeneugden - 1438256
6
 */
7
8
class MainWindow {
9
		private JFrame m_frame;
10
		public JFrame frame() {
11
				return m_frame;
12
		}
13
		public void setFrame(JFrame frame) {
14
				m_frame = frame;
15
		}
16
		
17
		public MainWindow() {
18
				setFrame(new JFrame());
19
				frame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20
				frame().pack();
21
				frame().setVisible(true);
22
		}
23
		public MainWindow(String title, JPanel contentPanel) {
24
				setFrame(new JFrame(title)); // Giving the frame a name.
25
				frame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // If the user closes the window, trigger the closing operation.
26
27
				frame().setContentPane(contentPanel);
28
29
				frame().pack();
30
				frame().setVisible(true);
31
				}
32
		}
33