📄 screen14.java
字号:
/*
* SCREEN14.java
*
* Created on 7 May 2007, 23:12
*/
import java.sql.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
*
* @author Harris Firdaus
*/
public class SCREEN14 extends javax.swing.JFrame {
/** Creates new form SCREEN14 */
public SCREEN14() {
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;
}
/** 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() {
jTextField1 = new javax.swing.JTextField();
jButton5 = new javax.swing.JButton();
jDesktopPane1 = new javax.swing.JDesktopPane();
jButton8 = new javax.swing.JButton();
emp_id = new javax.swing.JTextField();
jButton7 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.setText("ENTER EMPLOYEE ID");
jButton5.setText("SUBMIT");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));
jButton8.setText("EXIT");
jButton8.setBounds(440, 580, 55, 23);
jDesktopPane1.add(jButton8, javax.swing.JLayeredPane.DEFAULT_LAYER);
jButton7.setText("BACK");
jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton7MouseClicked(evt);
}
});
jButton1.setText("EXIT");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(98, 98, 98)
.addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(262, 262, 262)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 688, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(emp_id, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(194, 194, 194)
.addComponent(jButton5)))))))
.addContainerGap(132, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(emp_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jButton5)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton1))
.addGap(28, 28, 28))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
this.dispose();// TODO add your handling code here:
}//GEN-LAST:event_jButton1MouseClicked
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
int find=0;
String name= emp_id.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:harris","scott","tiger");
s = conn.createStatement();
r = s.executeQuery("select * from employe where emp_id='"+name+"'");
while (r.next())
{
if(name.equals(r.getString("emp_id")))
find=1;
}
if(find!=1)
JOptionPane.showMessageDialog(this , " Details not found", "Error!!!", 0);
else
{
r = s.executeQuery("select * from employe where emp_id ='"+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( "Employee 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);
}
// TODO add your handling code here:
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
SCREEN3 H = new SCREEN3();
H.setVisible(true);
this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_jButton7MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SCREEN14().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField emp_id;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -