📄 studentsearch.java
字号:
/*
* studentfee.java
*
* Created on May 5, 2007, 6:58 PM
*/
package GUI;
import java.sql.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
*
* @author Saurabh
*/
public class studentSearch extends javax.swing.JFrame {
/** Creates new form studentfee */
public studentSearch() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
rollno = new javax.swing.JEditorPane();
jLabel2 = new javax.swing.JLabel();
go = new javax.swing.JButton();
back = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jDesktopPane1 = new javax.swing.JDesktopPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SEARCH");
jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setForeground(new java.awt.Color(255, 0, 51));
jLabel1.setText("Enter Enrollment");
jScrollPane1.setViewportView(rollno);
jLabel2.setText("Search");
go.setText("GO");
go.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
goActionPerformed(evt);
}
});
go.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
goMouseClicked(evt);
}
});
back.setText("Back");
back.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
backMouseClicked(evt);
}
});
jLabel3.setFont(new java.awt.Font("Papyrus", 3, 18));
jLabel3.setForeground(new java.awt.Color(255, 51, 255));
jLabel3.setText("Student Details");
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(74, 74, 74)
.add(go))
.add(back)))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(25, 25, 25)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel1Layout.createSequentialGroup()
.add(89, 89, 89)
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 184, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(296, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jDesktopPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(41, 41, 41)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(33, 33, 33)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(go)
.add(jLabel2))
.add(39, 39, 39)
.add(jDesktopPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 330, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 37, Short.MAX_VALUE)
.add(back)
.addContainerGap())
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public Object getRowsValueAt(int aRow, int aColumn, Vector rows) {
Vector row = (Vector)rows.elementAt(aRow);
return row.elementAt(aColumn);
}
public String getColumnNamez(ResultSetMetaData rm, int column) {
String temp="";
try {
temp = rm.getColumnLabel(column);
} catch(Exception e) {
}
return temp;
}
private void goActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goActionPerformed
int find=0;
String name= rollno.getText();
Statement s;
ResultSet r;
final JTable table= new JTable();
final ResultSetMetaData rm;
final Vector rows = new Vector();
boolean wasOk=true;
JScrollPane scrollpane= new JScrollPane();
try {
// NewJFrame ob =new NewJFrame();
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:manoj1","system","manoj");
s = conn.createStatement();
r = s.executeQuery("select * from student1 where rollno='"+name+"'");
while (r.next())
{
if(name.equals(r.getString("rollno")))
find=1;
}
if(find!=1)
JOptionPane.showMessageDialog(this , "student Details not found", "Error!!!", 0);
else
{
r = s.executeQuery("select * from student1 where rollno ='"+name+"'");
rm= r.getMetaData();
while (r.next()) {
Vector newRow = new Vector();
for (int i = 1; i <= rm.getColumnCount(); i++) {
newRow.addElement(r.getObject(i));
}
rows.addElement(newRow);
}
final int col= rm.getColumnCount();
final int row= rows.size();
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return col; }
public int getRowCount() { return row;}
public Object getValueAt(int row, int col) {return getRowsValueAt(row, col, rows).toString();};
public String getColumnName(int column) {return getColumnNamez(rm, column+1);}
public boolean isCellEditable(int row, int col) {return (row==-0);}
};
table.setModel(dataModel);
scrollpane = new JScrollPane(table);
}
}
catch(Exception e) {
wasOk= false;
JOptionPane.showMessageDialog(this , e.getMessage(), "Error!!!", 0);
}
if ((wasOk == true)&&(find==1)) {
final JInternalFrame f= new JInternalFrame( "Student Search Result", true, true, true, true);
int nrWin= jDesktopPane1.getAllFrames().length % 7 + 1;
f.setBounds(nrWin *30 -10 , nrWin*20 -10 , 525, 325 );
jDesktopPane1.add(f);
f.setVisible(true);
try {
//f.setSelected(true);
}
catch ( Exception e) {
}
f.add(scrollpane);
}
}//GEN-LAST:event_goActionPerformed
private void goMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goMouseClicked
}//GEN-LAST:event_goMouseClicked
private void backMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_backMouseClicked
this.dispose();// TODO add your handling code here:
}//GEN-LAST:event_backMouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new studentSearch().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton back;
private javax.swing.JButton go;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JEditorPane rollno;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -