?? cm.java
字號(hào):
import java.awt.*;
import java.net.*;
import java.math.*;
import java.sql.*;
import java.awt.event.*;
import sun.jdbc .odbc .*;
class Window extends Frame implements ActionListener
{TextArea text; Panel panel;
TextField IDent;
Button button1,button2;
Window(){
super("ID隨機(jī)性分析");
setLayout(new BorderLayout());setBackground(Color.cyan);
setBounds(150,150,300,120); setVisible(true);
text=new TextArea();
button1=new Button("確定");
button2=new Button("查詢所有ID");
IDent=new TextField(16); panel=new Panel();
panel.add(new Label("輸入抽樣掩碼匹配位串:"));
panel.add(IDent); panel.add(button1);
add("North",panel); add(text,"Center"); add(button2,"South");
text.setEditable(false); text.setBackground(Color.white);
button1.addActionListener(this); button2.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false); System.exit(0);}});
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1){
text.setText("查詢結(jié)果"+'\n');
try{PipeiId();}
catch(SQLException ee) {}
}
else if(e.getSource()==button2){
text.setText("查詢結(jié)果"+'\n');
try{ AllId();}
catch(SQLException ee) {}
}
}
public void PipeiId() throws SQLException{
String id;
String PipeiChar;
long count=0;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
Connection con=DriverManager.getConnection("jdbc:odbc:bao","bao","123");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT * FROM bao");
while(rs.next()){
id=rs.getString(5);
PipeiChar=IDent.getText();
if(id.startsWith(PipeiChar))
// if(id.startsWith(IDent.toString()))
//if((id.trim()).equals(IDent.getText().trim()))
{
count++;
text.setText("相匹配的ID個(gè)數(shù)為"+count+'\n');
}
}
if((text.getText().trim()).equals("查詢結(jié)果")){
text.setText("沒有相匹配的ID"); }
}
public void AllId() throws SQLException{
String id;
long count=0;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e) {}
Connection con=DriverManager.getConnection("jdbc:odbc:bao","bao","123");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT * FROM bao");
while(rs.next()){
id=rs.getString(5);
//ID=ippacket.ident;
// System.out.println(ID+" in binary: "+Long.toBinaryString(ID))
text.setText('\n'+id+'\n');
count++;
text.setText("ID總數(shù)為"+count+'\n');
}
}
}
class cm{
public static void main(String args[]){
Window window=new Window();
window.pack();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -