首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

小弟我不懂

2012-11-09 
我不懂Java codeimport java.util.regex.*import java.awt.*import java.awt.event.*import javax.swin

我不懂

Java code
import java.util.regex.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;class denglu extends Frame// implements ActionListener {//    String s1[]=new String[5];    private Box baseBox,boxv1,boxv2;    private Panel p1,p2,p3;    private TextField text1,text2;    private Label l1,l2,l3;    private Button submit,reset;//    denglu(TextField t1,TextField t2){//        this.t1 = t1;//        this.t2 = t2;//    }    denglu(){                l1 = new Label("请登录到杨海主页!");        l2 = new Label("账号:");        l3 = new Label("密码:");                submit =new Button("提交");        reset = new Button("重置");        text1 = new TextField(16);        text2 = new TextField(16);        p1 = new Panel();        p2 = new Panel();        p3 = new Panel();        p1.add(l1);        p3.add(submit);p3.add(reset);        //p2.setLayout(new GridLayout(2,1));//        p2.add(l2);p2.add(text1);    //    p2.add(l3);p2.add(text2);//        add(p2,"Center");        boxv1 = Box.createVerticalBox();        boxv1.add(new JLabel("账号:"));        boxv1.add(Box.createVerticalStrut(8));        boxv1.add(new JLabel("密码:"));//        boxv1.add(Box.createVerticalStrut(8));        boxv2 = Box.createVerticalBox();        boxv2.add(text1);        boxv2.add(Box.createVerticalStrut(8));        boxv2.add(text2);        baseBox = Box.createHorizontalBox();        baseBox.add(boxv1);//        baseBox.add(Box.createHorizontalStrut(10));        baseBox.add(boxv2);        p2.setLayout(new FlowLayout());        p2.add(baseBox);        add(p2,"Center");add(p1,"North");add(p3,"South");//        setLayout(new FlowLayout());    //    addWindowListener(this);        myevent();        setSize(400,500);        setVisible(true);    }    public void text(){        String s = null;        try{            FileReader fr = new FileReader("1.txt");            int b=0;                        char[]buf = new char[1024];            while((b=fr.read())!=-1)                 s = new String(buf,0,b);                    //    System.out.println(new String(buf,0,b));        }        catch(IOException e1){}         String a = " ";         String sa[] = s.split(a);                        String s1 = text1.getText();        String s2 = text2.getText();    //    String a1 ="[a-z]{6,10}";        String a2 ="\\w{6,10}";    //    boolean flag1 = s1.matches(a1);        boolean flag2 = s2.matches(a2);//        if(!flag1)//            JOptionPane.showMessageDialog(this,"您输入了非法字符","警告提示框",    //        JOptionPane.WARNING_MESSAGE);        if(!flag2)            JOptionPane.showMessageDialog(this,"密码输入错误!","警告提示框",            JOptionPane.WARNING_MESSAGE);        else if(!(s1.equals(sa[0])||!(s2.equals(sa[4]))))            JOptionPane.showMessageDialog(this,"密码或账号输入错误!","警告提示框",            JOptionPane.WARNING_MESSAGE);        else            new hello();    }    public void myevent(){        submit.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e){                text();            //    String s1 = text1.getText();            //    String s2 = text2.getText();            }            });        reset.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e){                if(e.getSource()==reset){                    text1.setText(null);                    text2.setText(null);                }            }        });        addWindowListener(new WindowAdapter(){            public void windowClosing(WindowEvent e){                //System.exit(0);                setVisible(false);            }        });    }/*    public static void main(String[] args)     {        new denglu();        System.out.println("Hello World!");    }*/} 


Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException
: String index out of range: 26472
  at java.lang.String.<init>(String.java:229)
  at denglu.text(denglu.java:67)
  at denglu$1.actionPerformed(denglu.java:97)
  at java.awt.Button.processActionEvent(Button.java:409)
  at java.awt.Button.processEvent(Button.java:377)
  at java.awt.Component.dispatchEventImpl(Component.java:4578)
  at java.awt.Component.dispatchEvent(Component.java:4404)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:286)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:201)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:191)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)

  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
设么问题啊

[解决办法]
没测试,程序报这段代码有问题:
Java code
        char[]buf = new char[1024];            while((b=fr.read())!=-1)                 s = new String(buf,0,b);//这有问题 

热点排行