Subversion Repository Public Repository

FingerPrint_modifed_project

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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package test;

import java.sql.Connection;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class ModalStudentList extends javax.swing.JDialog {
	private javax.swing.JButton btnCancel;
	private javax.swing.JButton btnOk;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JLabel lblStudentname;
	private javax.swing.JTable tblStudents;
	private javax.swing.JTextField txtStudentname;

	String studentId = "";
	JFrame frame;
	JFormattedTextField txtStudentId;
	JFormattedTextField txtStudentName;

	public ModalStudentList(javax.swing.JFrame parent, boolean modal) {
		super(parent,true);
		initComponents();
	}

	public ModalStudentList(JFormattedTextField txtStudentId, JFormattedTextField txtStudentName, boolean modal) {
		super();
		this.txtStudentId=txtStudentId;
		this.txtStudentName=txtStudentName;
		initComponents();
	}

	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {
		jScrollPane1 = new javax.swing.JScrollPane();
		tblStudents = new javax.swing.JTable();
		txtStudentname = new javax.swing.JTextField();
		btnOk = new javax.swing.JButton();
		btnCancel = new javax.swing.JButton();
		lblStudentname = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(SFESampleApp.class).getContext().getResourceMap(ModalStudentList.class);
		setTitle("ModalStudentList"); // NOI18N
		setName("Form"); // NOI18N

		jScrollPane1.setName("jScrollPane1"); // NOI18N

		tblStudents.setModel(new javax.swing.table.DefaultTableModel(
				new Object [][] {},
				new String [] {}
				){
			public boolean isCellEditable(int row, int column){
				return false;//This causes all cells to be not editable
			}
		});
		tblStudents.setName("tblStudents"); // NOI18N
		tblStudents.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				tblStudentsMouseClicked(evt);
			}
		});
		jScrollPane1.setViewportView(tblStudents);

		txtStudentname.setText(resourceMap.getString("txtStudentname.text")); // NOI18N
		txtStudentname.setName("txtStudentname"); // NOI18N
		txtStudentname.addKeyListener(new java.awt.event.KeyAdapter() {
			public void keyTyped(java.awt.event.KeyEvent evt) {
				txtStudentnameKeyTyped(evt);
			}
			public void keyReleased(java.awt.event.KeyEvent evt) {
				txtStudentnameKeyReleased(evt);
			}
		});

		btnOk.setText("OK"); // NOI18N
		btnOk.setFont(new java.awt.Font("Tahoma", 1, 11));
		btnOk.setName("btnOk"); // NOI18N
		btnOk.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnOkActionPerformed(evt);
			}
		});

		btnCancel.setText("Cancel"); // NOI18N
		btnCancel.setFont(new java.awt.Font("Tahoma", 1, 11));
		btnCancel.setName("btnCancel"); // NOI18N
		btnCancel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnCancelActionPerformed(evt);
			}
		});

		lblStudentname.setText("Student Name"); // NOI18N
		lblStudentname.setFont(new java.awt.Font("Tahoma", 1, 11));
		lblStudentname.setName("lblStudentname"); // NOI18N

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addGap(107, 107, 107)
						.addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(btnCancel)
						.addContainerGap())
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap(87, Short.MAX_VALUE)
						.addComponent(lblStudentname)
						.addGap(29, 29, 29)
						.addComponent(txtStudentname, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(81, 81, 81))
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
						.addContainerGap())
				);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(txtStudentname, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(lblStudentname))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
								.addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(btnOk, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
						.addContainerGap())
				);
		postInitComponents();
		pack();
	}// </editor-fold>

	public void postInitComponents(){
		Utilities util = new Utilities();
		Connection con = util.getConnection();
		String query = "select id, concat(first_name,' ',last_name) name, gender, dob from students ";
		Vector values = util.selectQuery(query, 4, con);
		//System.out.println("@@@ select query : "+query);
		//System.out.println("@@@ values : "+values);

		DefaultTableModel model = (DefaultTableModel) tblStudents.getModel(); 
		model.addColumn("Student ID"); 
		model.addColumn("Student Name"); 
		model.addColumn("Gender"); 
		model.addColumn("DOB");
		populateTableData(values);
	}

	public void populateTableData(Vector values){
		DefaultTableModel model = (DefaultTableModel) tblStudents.getModel(); 
		while(model.getRowCount() > 0){
			model.removeRow(0);
		}
		for (int i = 0; i < values.size(); i++) {
			Vector temp = (Vector)values.elementAt(i);
			model.addRow(temp);
		}
	}

	private void txtStudentnameKeyTyped(java.awt.event.KeyEvent evt) {} 

	private void txtStudentnameKeyReleased(java.awt.event.KeyEvent evt) {
		Utilities util = new Utilities();
		Connection con = util.getConnection();
		String query = "";
		String sname = txtStudentname.getText();
		sname = (sname == null)?"":sname;
		if(sname == null || sname.length()<=0)
			query = "select id, concat(first_name,' ',last_name) name, gender, dob from students ";
		else
			query = "select id, concat(first_name,' ',last_name) name, gender, dob from students where first_name like '%"+sname+"%'";

		Vector values = util.selectQuery(query, 4, con);
		//System.out.println("@@@ select query : "+query);
		//System.out.println("@@@ values : "+values);
		populateTableData(values);
	}

	public void setSelectedValue(){
		int selrow = tblStudents.getSelectedRow();
		int selcol = 0;
		if(selrow >= 0){
			String sID = tblStudents.getValueAt(selrow, 0).toString();
			String sName = tblStudents.getValueAt(selrow, 1).toString();
			studentId = sID;
			txtStudentId.setText(sID);
			txtStudentName.setText(sName);
			this.dispose();
		}else{
			JOptionPane.showMessageDialog(null, "Please select a student.");
		}
	}
	
	private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {
		setSelectedValue();
	}

	private void tblStudentsMouseClicked(java.awt.event.MouseEvent evt) {
		if (evt.getClickCount() == 2) {
			setSelectedValue();
		}
	}


	private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
	}

	public static void main(String args[]) {
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(ModalStudentList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(ModalStudentList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(ModalStudentList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(ModalStudentList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				ModalStudentList dialog = new ModalStudentList(new JFrame(), true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}
}

Commits for FingerPrint_modifed_project/src/test/ModalStudentList.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 07:20:23 +0000