📄 screen16.java
字号:
/*
* SCREEN16.java
*
* Created on 7 May 2007, 23:34
*/
import java.sql.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
*
* @author Harris Firdaus
*/
public class SCREEN16 extends javax.swing.JFrame {
/** Creates new form SCREEN16 */
public SCREEN16() {
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();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
shop_no = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jDesktopPane1 = new javax.swing.JDesktopPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.setText("Enter shop no.");
jButton4.setText("BACK ");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});
jButton5.setText("EXIT");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton5MouseClicked(evt);
}
});
jButton1.setText("SUBMIT");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));
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(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 338, Short.MAX_VALUE)
.addComponent(jButton5)
.addGap(107, 107, 107))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(shop_no, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
.addGap(149, 149, 149)
.addComponent(jButton1)
.addGap(239, 239, 239))))
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 503, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(75, 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()
.addGap(39, 39, 39)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(25, 25, 25)
.addComponent(shop_no, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jButton1)))
.addGap(21, 21, 21)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5))
.addGap(33, 33, 33))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
int find=0;
String name= shop_no.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 shops where shop_no='"+name+"'");
while (r.next())
{
if(name.equals(r.getString("shop_no")))
find=1;
}
if(find!=1)
JOptionPane.showMessageDialog(this , " Details not found", "Error!!!", 0);
else
{
r = s.executeQuery("select * from shops where shop_no ='"+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( "Shop 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_jButton1ActionPerformed
private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
this.dispose();// TODO add your handling code here:
}//GEN-LAST:event_jButton5MouseClicked
private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
SCREEN15 H = new SCREEN15();
H.setVisible(true);
this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_jButton4MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SCREEN16().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField shop_no;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -