-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyQuestions.java
More file actions
133 lines (98 loc) · 3.88 KB
/
MyQuestions.java
File metadata and controls
133 lines (98 loc) · 3.88 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
package com.amma;
import java.awt.Cursor;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
public class MyQuestions extends JFrame {
String message;
int uid;
public MyQuestions(String message, int uid) {
this.uid = uid;
this.message = message;
//NormalUser user = new NormalUser(userID);
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(600, 800));
setMinimumSize(new java.awt.Dimension(600, 800));
setPreferredSize(new java.awt.Dimension(600, 800));
getContentPane().setLayout(null);
getContentPane().add(new Util(uid).getHeadingPanel(message));
getContentPane().add(getQuestionsTable());
pack();
}
public JPanel getQuestionsTable() {
JPanel panel = new JPanel();
panel.setBounds(0, 100, 600, 700);
JTable questionsTable;
if(message == "View All Questions")
questionsTable = viewAllQuestions();
else
questionsTable = viewAllMyQuestions();
setColumnWidth(questionsTable);
questionsTable.setBounds(10, 50, 580, 650);
panel.add(questionsTable);
return panel;
}
private void setColumnWidth(JTable qTable) {
TableColumn col = qTable.getColumn("Question");
col.setMaxWidth(400);
col.setMinWidth(400);
col = qTable.getColumn("No of Answers");
col.setMaxWidth(100);
col.setMinWidth(100);
col = qTable.getColumn("id");
col.setMaxWidth(100);
col.setMinWidth(100);
}
private void questionsTableMouseClicked(java.awt.event.MouseEvent evt, JTable questionsTable) {
// get the selected row
if (evt.getClickCount() == 2) {
int index = questionsTable.getSelectedRow();
int qid = Integer.parseInt((String)questionsTable.getModel().getValueAt(index, 2));
new AllAnswers(qid, uid).setVisible(true);
}
}
public JTable viewAllQuestions() {
String[][] res = new AmmaDAO().getAllQuestions();
String[] colNames = {"Question", "No of Answers", "id", "createdBy"};
JTable questionsTable = new JTable(res, colNames) {
public boolean isCellEditable(int row, int column) {
return false;
}
};
questionsTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
questionsTableMouseClicked(evt, questionsTable);
}
});
return questionsTable;
}
public JTable viewAllMyQuestions() {
String[][] res = new AmmaDAO().getAllMyQuestions(uid);
String[] colNames = {"Question", "No of Answers", "id"};
JTable questionsTable = new JTable(res, colNames) {
public boolean isCellEditable(int row, int column) {
return false;
}
};
questionsTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
questionsTableMouseClicked(evt, questionsTable);
}
});
return questionsTable;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new MyQuestions("View All Questions", 1).setVisible(true);
}
});
}
}