📄 cm.java
字号:
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随机性分析");
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("查询结果"+'\n');
try{PipeiId();}
catch(SQLException ee) {}
}
else if(e.getSource()==button2){
text.setText("查询结果"+'\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个数为"+count+'\n');
}
}
if((text.getText().trim()).equals("查询结果")){
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总数为"+count+'\n');
}
}
}
class cm{
public static void main(String args[]){
Window window=new Window();
window.pack();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -