📄 subdomain.java~21~
字号:
package Statistics;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.*;public class SubDomain extends JFrame { BufferedReader br; Vector v1,v2,v3; JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JComboBox jComboBox2 = new JComboBox(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JLabel jLabel7 = new JLabel(); JLabel jLabel8 = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); JScrollPane jScrollPane2 = new JScrollPane(); JScrollPane jScrollPane3 = new JScrollPane(); JList jList1 = new JList(); JList jList2 = new JList(); JList jList3 = new JList(); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); public SubDomain() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setHorizontalTextPosition(SwingConstants.TRAILING); jLabel1.setText("Access Statistics for Web Pages"); jLabel1.setBounds(new Rectangle(121, 27, 293, 24)); this.getContentPane().setLayout(null); jLabel2.setFont(new java.awt.Font("Dialog", 2, 12)); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); jLabel2.setText("Total Transfers by Reserved Subdomain"); jLabel2.setBounds(new Rectangle(145, 69, 240, 23)); jComboBox1.setBounds(new Rectangle(21, 143, 134, 20)); jComboBox1.addItem("Hongkong"); jComboBox1.addItem("Malaysia"); jComboBox1.addItem("Mexico"); // jComboBox1.addActionListener(new java.awt.event.ActionListener() { // public void actionPerformed(ActionEvent e) { // jComboBox1_actionPerformed(e); // } // }); jComboBox2.setBounds(new Rectangle(171, 142, 67, 20)); jComboBox2.addItem("my"); jComboBox2.addItem("hk"); jComboBox2.addItem("mx"); jComboBox2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jComboBox2_actionPerformed(e); } }); jLabel3.setText("Country"); jLabel3.setBounds(new Rectangle(24, 122, 64, 16)); jLabel4.setText("Code"); jLabel4.setBounds(new Rectangle(171, 125, 43, 12)); jLabel5.setPreferredSize(new Dimension(34, 15)); jLabel5.setText("IP Name"); jLabel5.setBounds(new Rectangle(251, 126, 80, 15)); jLabel6.setText("Requests"); jLabel6.setBounds(new Rectangle(418, 121, 69, 20)); jLabel7.setRequestFocusEnabled(true); jLabel7.setText("Bytes Sent"); jLabel7.setBounds(new Rectangle(495, 121, 69, 19)); jLabel8.setText("Total"); jLabel8.setBounds(new Rectangle(373, 441, 76, 18)); jScrollPane1.setBounds(new Rectangle(253, 143, 161, 289)); jScrollPane2.setBounds(new Rectangle(419, 143, 59, 290)); jScrollPane3.setBounds(new Rectangle(497, 143, 92, 289)); jTextField1.setText(""); jTextField1.setBounds(new Rectangle(418, 441, 64, 18)); jTextField2.setText(""); jTextField2.setBounds(new Rectangle(497, 440, 93, 19)); this.getContentPane().add(jComboBox1, null); this.getContentPane().add(jLabel3, null); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jLabel7, null); this.getContentPane().add(jScrollPane3, null); this.getContentPane().add(jScrollPane2, null); this.getContentPane().add(jLabel6, null); this.getContentPane().add(jScrollPane1, null); //jScrollPane1.getViewport().add(jList1, null); this.getContentPane().add(jLabel5, null); this.getContentPane().add(jLabel4, null); this.getContentPane().add(jComboBox2, null); this.getContentPane().add(jTextField2, null); this.getContentPane().add(jTextField1, null); this.getContentPane().add(jLabel8, null); //jScrollPane2.getViewport().add(jList2, null); //jScrollPane3.getViewport().add(jList3, null); this.setBounds(0,0,600,600); this.setVisible(true); this.setDefaultCloseOperation(1); } public static void main(String[] args) { SubDomain subDomain = new SubDomain(); } //void jComboBox1_actionPerformed(ActionEvent e) { // String selectedItem = (String)jComboBox1.getSelectedItem(); //} void jComboBox2_actionPerformed(ActionEvent e) { String selectedItem = (String)jComboBox2.getSelectedItem(); String ip, requests, bytesSent; v1 = new Vector(); v2 = new Vector(); v3 = new Vector(); int SumbyteSent=0, SumReq=0; try{ br = new BufferedReader(new FileReader("Z:\\accessstatistics.htm")); String line=""; while((line=br.readLine())!=null){ if (line.equals("<H2><A name=Subdomain>Total Transfers by Reversed Subdomain</A></H2><PRE>***********************************************************************")) { for (int i = 0; i < 2; i++) br.readLine(); while (! (line = br.readLine()).equals("</PRE>")) { if ( (line.substring(36)).startsWith(selectedItem)) { ip = line.substring(36); v1.addElement(ip); StringTokenizer st = new StringTokenizer(line, "\t| "); st.nextToken(); st.nextToken(); bytesSent = st.nextToken(); SumbyteSent += Integer.parseInt(bytesSent); requests = st.nextToken(); SumReq += Integer.parseInt(requests); v2.addElement(requests); v3.addElement(bytesSent); } } } } } catch(IOException e1){System.out.println("file not found");} jScrollPane1.getViewport().add(new JList(v1), null); jScrollPane2.getViewport().add(new JList(v2), null); jScrollPane3.getViewport().add(new JList(v3), null); jTextField1.setText(Integer.toString(SumReq)); jTextField2.setText(Integer.toString(SumbyteSent)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -