summaryrefslogtreecommitdiffstats
path: root/src/jeopardy/View.java
blob: a2f50c2635f647dccb966155acb651efe0cf0775 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package jeopardy;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;

public class View {

	private Controller controller;
	
	private JFrame show;
	private JFrame host;
	
	private JPanel labelPanel;
	private JPanel questionPanel;
	
	
	public void createGameDialog(final GameDescription description) {
		
		final JPanel pmPanel = new JPanel();
		final BoxLayout pmLayout = new BoxLayout(pmPanel, BoxLayout.LINE_AXIS);
		pmPanel.setLayout(pmLayout);
		
		final JPanel usersPanel = new JPanel();
		final BoxLayout usersLayout = new BoxLayout(usersPanel, BoxLayout.PAGE_AXIS);
		usersPanel.setLayout(usersLayout);
						
		final JPanel nameAreaPanel = new JPanel();
		final BoxLayout nameAreaLayout = new BoxLayout(nameAreaPanel, BoxLayout.PAGE_AXIS);
		nameAreaPanel.setLayout(nameAreaLayout);
		
		final ArrayList<JTextField> nameArea = new ArrayList<JTextField>();
		JTextField firstName = new JTextField();
		nameArea.add(new JTextField());
		firstName.setMaximumSize(new Dimension(Short.MAX_VALUE, 1));
		nameAreaPanel.add(Box.createGlue());
		nameAreaPanel.add(firstName);
		
		nameAreaPanel.setMaximumSize(new Dimension(150, 1));
		
		JLabel descriptionLabel = new JLabel("Bitte Spielernamen angeben!");
				
		JButton plus = new JButton("+");
		plus.addActionListener(new ActionListener() { 
			  public void actionPerformed(ActionEvent e) {
				  nameArea.add(new JTextField());
				  nameArea.get(nameArea.size()-1).setMaximumSize(new Dimension(Short.MAX_VALUE, 1));
				  nameAreaPanel.add(nameArea.get(nameArea.size()-1));
				  host.validate();
			  }
		});

		JButton minus = new JButton("-");
		minus.addActionListener(new ActionListener() { 
			  public void actionPerformed(ActionEvent e) {
				  nameAreaPanel.remove(nameArea.get(nameArea.size()-1));
				  nameArea.remove(nameArea.size()-1);
				  host.validate();
			  }
		});
		
		JButton finish = new JButton("Ok");
		
		pmPanel.add(plus);
		pmPanel.add(minus);
		
		descriptionLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
		nameAreaPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
		pmPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
		finish.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		usersPanel.add(descriptionLabel);
		usersPanel.add(nameAreaPanel);
		usersPanel.add(Box.createGlue());
		usersPanel.add(pmPanel);
		usersPanel.add(finish);
		
		host.add(usersPanel);
		host.validate();
		
		
		//----------------------
		
		final JPanel pmPanel2 = new JPanel();
		final BoxLayout pmLayout2 = new BoxLayout(pmPanel2, BoxLayout.LINE_AXIS);
		pmPanel2.setLayout(pmLayout2);
		
		final JPanel categoriesPanel = new JPanel();
		final BoxLayout categoriesLayout = new BoxLayout(categoriesPanel, BoxLayout.PAGE_AXIS);
		categoriesPanel.setLayout(categoriesLayout);
		
		categoriesPanel.setSize(new Dimension(5, Short.MAX_VALUE));
		
		final JPanel categoriesAreaPanel = new JPanel();
		final BoxLayout categoriesAreaLayout = new BoxLayout(categoriesAreaPanel, BoxLayout.PAGE_AXIS);
		categoriesAreaPanel.setLayout(categoriesAreaLayout);
		
		categoriesAreaPanel.setMaximumSize(new Dimension(150, 1));
		
		final ArrayList<Choice> categoriesArea = new ArrayList<Choice>();
		Choice firstCategory = new Choice();
		categoriesArea.add(firstCategory);
		
		firstCategory.setMaximumSize(new Dimension(Short.MAX_VALUE, 1));
		categoriesAreaPanel.add(Box.createGlue());
		
		categoriesAreaPanel.add(firstCategory);
		
		JLabel descriptionLabel2 = new JLabel("Bitte Kategorien auswählen!");
		
		JButton plus2 = new JButton("+");

		plus2.addActionListener(new ActionListener() { 
			  public void actionPerformed(ActionEvent e) { 
				  categoriesArea.add(new Choice());
				  categoriesArea.get(categoriesArea.size()-1).setMaximumSize(new Dimension(Short.MAX_VALUE, 1));
				  categoriesAreaPanel.add(categoriesArea.get(categoriesArea.size()-1));
				  host.validate();
			  }
		});

		JButton minus2 = new JButton("-");
		  
		minus2.addActionListener(new ActionListener() { 
			  public void actionPerformed(ActionEvent e) {
				  categoriesAreaPanel.remove(categoriesArea.get(nameArea.size()-1));
				  categoriesArea.remove(nameArea.size()-1);
				  host.validate();
			  }
		});
		
		JButton finish2 = new JButton("Ok");
		
		descriptionLabel2.setAlignmentX(Component.CENTER_ALIGNMENT);
		categoriesAreaPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
		pmPanel2.setAlignmentX(Component.CENTER_ALIGNMENT);
		finish2.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		pmPanel2.add(plus2);
		pmPanel2.add(minus2);
		
		categoriesPanel.add(descriptionLabel2);
		categoriesPanel.add(categoriesAreaPanel);
		categoriesPanel.add(Box.createGlue());
		categoriesPanel.add(pmPanel2);
		categoriesPanel.add(finish2);
		
		finish.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) { 
				for(JTextField bla : nameArea) {
					description.addUser(bla.getText());
				}
				host.remove(usersPanel);
				host.add(categoriesPanel);
				host.validate();
			  }
		});
		
		finish2.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) { 
				for(Choice bla : categoriesArea) {
					description.addCategory(bla.getSelectedItem());
				}
				host.remove(categoriesPanel);
				host.validate();
				host.repaint();
			}
		});
	}
	
	
	//----------------------
	
	
	public void showQuestion(String q) {
		show.removeAll();
		
		questionPanel = new JPanel();
		JLabel question = new JLabel(q);
		
		show.add(question);
		show.validate();
		
	}
	
	public void showLabelPanel() {
		
	}
	
	public View(Controller c) {
		controller = c;
		
		show = new JFrame("Show");
		show.setSize(800, 600);
		show.setVisible(true);
		
		host = new JFrame("Host");
		host.setSize(800, 600);
		host.setVisible(true);
	
		labelPanel = new JPanel();
	}
	
}