⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screen11.java

📁 railway managemet project used for railway system
💻 JAVA
字号:
/*
 * SCREEN11.java
 *
 * Created on 7 May 2007, 22:33
 */
import java.sql.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
 *
 * @author  Harris Firdaus
 */
public class SCREEN11 extends javax.swing.JFrame {
    
    /** Creates new form SCREEN11 */
    public SCREEN11() {
        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();
        departure_time = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jTextField1.setText("ENTER THE DEPARTURE TIME");

        jButton1.setText("SUBMIT");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("EXIT");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton3.setText("BACK");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(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(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(351, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(213, 213, 213))
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(departure_time, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 373, Short.MAX_VALUE)
                        .addComponent(jButton2)
                        .addGap(97, 97, 97))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(2, 2, 2)
                .addComponent(departure_time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
this.dispose();// TODO add your handling code here:
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  int find=0;
String name= departure_time.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 train where departure_time='"+name+"'");
while (r.next())
{
if(name.equals(r.getString("departure_time")))
find=1;

}

if(find!=1)
JOptionPane.showMessageDialog(this , " Details not found", "Error!!!", 0);
else
{
r = s.executeQuery("select * from train where departure_time ='"+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( "TRAIN 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 jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
            SCREEN9 H = new SCREEN9();
            H.setVisible(true);
            this.setVisible(false);
            // TODO add your handling code here:
    }//GEN-LAST:event_jButton3MouseClicked
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SCREEN11().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField departure_time;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    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 + -