通过方法ActionPerformed处理构造函数方法中的接收向量

时间:2014-01-20 17:09:48

标签: java vector jbutton

我有这个构造函数方法,它作为参数向量:

public EditaTorcedor(Vector vetor){        
        content = new JFrame();
        content.setLayout(null);       
        content.setSize(660, 550);
        content.setBounds(20, 70, 660, 540);
        content.setVisible(true);        
        content.setLocationRelativeTo(null);        

        encontraTorcedor = new JLabel("Digite o nome do Torcedor:");
        encontraTorcedor.setBounds(new Rectangle(10,0,160,25));
        content.add(encontraTorcedor);

        buscaTorcedor = new JTextField();
        buscaTorcedor.setBounds(new Rectangle(180,0,100,25));
        content.add(buscaTorcedor);

        procuraTorcedor = new JButton("Procurar");
        procuraTorcedor.setBounds(new Rectangle(285,0,100,25));
        procuraTorcedor.setActionCommand("Buscar");
        procuraTorcedor.addActionListener(this);
        content.add(procuraTorcedor);

        nomeTorcedor = new JLabel("Nome:");
        nomeTorcedor.setBounds(new Rectangle(10,40,100,25));
        content.add(nomeTorcedor);
        nome = new JTextField();
        nome.setBounds(new Rectangle(60,40,130,25));
        content.add(nome);       

        labelData = new JLabel("Data de Nascimento:");
        labelData.setBounds(new Rectangle(195,40,180,25));
        //labelData.setForeground(Color.yellow);
        content.add(labelData);       
        String[] listaDias = {"01", "02", "03", "04", "05", "06", "07", "08" , "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
        comboDia = new JComboBox(listaDias);
        comboDia.setBounds(new Rectangle(320,40,50,25));
        content.add(comboDia);       
        String[] listaMes = {"JAN", "FEV", "MAR", "ABR", "MAI", "JUN", "JUL", "AGO" , "SET", "OUT", "NOV", "DEZ",};
        comboMes = new JComboBox(listaMes);
        comboMes.setBounds(new Rectangle(370,40,120,25));
        content.add(comboMes);       
        String[] listaAno = {"1945", "1946", "1947", "1948", "1949", "1950", "1951" , "1952", "1953", "1954", "1955","1956", "1957", "1958", "1959", "1960","1961" , "1962", "1963", "1964", "1965","1966", "1967", "1968", "1969", "1970", "1971" , "1972", "1973", "1974", "1975","1976", "1977", "1978", "1979", "1980","1981" , "1982", "1983", "1984", "1985","1986", "1987", "1988", "1989", "1990", "1991" , "1992", "1993", "1994", "1995","1996"};
        comboAno = new JComboBox(listaAno);
        comboAno.setBounds(new Rectangle(490,70,100,25));
        content.add(comboAno);        

        labelSexo = new JLabel("Sexo:");
        labelSexo.setBounds(new Rectangle(10,70,100,25));
        content.add(labelSexo);
        String[] listaSexo = {"Masculino", "Feminino"};
        comboSexo = new JComboBox(listaSexo);
        comboSexo.setBounds(new Rectangle(40,70,100,25));
        content.add(comboSexo);

        labelCivil = new JLabel("Estado Civil:");
        labelCivil.setBounds(new Rectangle(195,70,150,25));
        content.add(labelCivil);
        String[] listaCivil = {"Solteiro", "Casado", "Divorciado"};
        comboCivil = new JComboBox(listaCivil);
        comboCivil.setBounds(new Rectangle(320,70,100,25));
        content.add(comboCivil);

        labelTelefone = new JLabel("DDD+ Telefone");
        labelTelefone.setBounds(new Rectangle(10,100,100,25));
        content.add(labelTelefone);        
        textFieldTelefone = new JTextField();
        textFieldTelefone.setBounds(new Rectangle(120,100,150,25));
        content.add(textFieldTelefone);        

        cpfTorcedor = new JLabel("CPF:");
        cpfTorcedor.setBounds(new Rectangle(275,100,200,25));
        content.add(cpfTorcedor);
        cpf = new JTextField();
        cpf.setBounds(new Rectangle(320,100,200,25));
        content.add(cpf);        

        cepTorcedor = new JLabel("CEP:");
        cepTorcedor.setBounds(new Rectangle(10,130,100,25));
        content.add(cepTorcedor);
        cep = new JTextField();
        cep.setBounds(new Rectangle(120,130,120,25));
        content.add(cep);        

        estadoTorcedor = new JLabel("Estado:");
        estadoTorcedor.setBounds(new Rectangle(275,130,200,25));
        content.add(estadoTorcedor);
        estado = new JTextField();
        estado.setBounds(new Rectangle(320,130,200,25));
        content.add(estado);        

        cidadeTorcedor = new JLabel("Cidade:");
        cidadeTorcedor.setBounds(new Rectangle(10,160,100,25));
        content.add(cidadeTorcedor);
        cidade = new JTextField();
        cidade.setBounds(new Rectangle(120,160,120,25));
        content.add(cidade);        

        labelBairro = new JLabel("Bairro:");
        labelBairro.setBounds(new Rectangle(275,160,200,25));
        content.add(labelBairro);
        textFieldBairro = new JTextField();
        textFieldBairro.setBounds(new Rectangle(320,160,200,25));
        content.add(textFieldBairro);        

        labelEndereco = new JLabel("Endereço:");
        labelEndereco.setBounds(new Rectangle(10,190,100,25));
        content.add(labelEndereco);
        textFieldEndereco = new JTextField();
        textFieldEndereco.setBounds(new Rectangle(120,190,120,25));
        content.add(textFieldEndereco);        

        labelComplemento = new JLabel("Complemento:");
        labelComplemento.setBounds(new Rectangle(275,190,200,25));
        content.add(labelComplemento);
        textFieldComplemento = new JTextField();
        textFieldComplemento.setBounds(new Rectangle(370,190,150,25));
        content.add(textFieldComplemento);        

        labelNumero = new JLabel("Número:");
        labelNumero.setBounds(new Rectangle(10,220,100,25));
        content.add(labelNumero);
        textFieldNumero = new JTextField();
        textFieldNumero.setBounds(new Rectangle(120,220,120,25));
        content.add(textFieldNumero);        


        tatuTorcedor = new JLabel("Tatuagem:");
        tatuTorcedor.setBounds(new Rectangle(10,250,200,25));
        content.add(tatuTorcedor);
        tatu = new JTextField();
        tatu.setBounds(new Rectangle(120,250,200,25));
        content.add(tatu);        

        marcaTorcedor = new JLabel("Marca:");
        marcaTorcedor.setBounds(new Rectangle(325,250,200,25));
        content.add(marcaTorcedor);
        marca = new JTextField();
        marca.setBounds(new Rectangle(370,250,200,25));
        content.add(marca);        

        labelAltura = new JLabel("Altura");
        labelAltura.setBounds(new Rectangle(10,280,200,25));
        content.add(labelAltura);
        textFieldAltura = new JTextField();
        textFieldAltura.setBounds(new Rectangle(120,280,200,25));
        content.add(textFieldAltura);        

        labelCorCabelo = new JLabel("Cor do Cabelo:");
        labelCorCabelo.setBounds(new Rectangle(325,280,200,25));
        content.add(labelCorCabelo);
        textFieldCorCabelo = new JTextField();
        textFieldCorCabelo.setBounds(new Rectangle(410,280,160,25));
        content.add(textFieldCorCabelo);        

        labelAcessorio = new JLabel("Acessório");
        labelAcessorio.setBounds(new Rectangle(10,310,200,25));
        content.add(labelAcessorio);
        textFieldAcessorio = new JTextField();
        textFieldAcessorio.setBounds(new Rectangle(120,310,200,25));
        content.add(textFieldAcessorio);        

        labelEmail = new JLabel("E-mail:");
        labelEmail.setBounds(new Rectangle(325,310,200,25));
        content.add(labelEmail);
        textFieldEmail = new JTextField();
        textFieldEmail.setBounds(new Rectangle(410,310,160,25));
        content.add(textFieldEmail);        

        labelRg = new JLabel("RG");
        labelRg.setBounds(new Rectangle(10,340,200,25));
        content.add(labelRg);
        textFieldRg = new JTextField();
        textFieldRg.setBounds(new Rectangle(120,340,200,25));
        content.add(textFieldRg);        

        cadastrar = new JButton("Editar");
        cadastrar.setBounds(new Rectangle(10,370,200,25));
        cadastrar.setSize(110,30);
        cadastrar.setActionCommand("editar");
        cadastrar.addActionListener(this);
        content.add(cadastrar);        

        limparDados = new JButton("Restaurar");
        limparDados.setBounds(new Rectangle(120,370,200,25));
        limparDados.setSize(200,30);
        limparDados.setActionCommand("LIMPAR");
        limparDados.addActionListener(this);
        content.add(limparDados);                        
    }

这里我有actionPerformed方法,它将根据命令处理事件。 当单击procuraTorcedor时,我希望文本字段填充此数组中的值。

public void actionPerformed(ActionEvent ae) {
        String comando = ae.getActionCommand();
        if ("buscar".equals(comando)) {
            String procuraUuario = buscaTorcedor.getText();
            for(int i=0; i<this.vetor.size(); i++){               
                if(this.vetor.elementAt(i).getNome.equals(procuraUsuario)){
                    this.posicaoUsuario = i;
                    this.nome.seText(this.vetor.elementAt(i).getNome);
                    this.estado.setText(this.vetor.elementAt(i).getEstado);
                    this.cidade.setText(this.vetor.elementAt(i).getCidade);
                    this.textFieldEmail.setText(this.vetor.elementAt(i).getEmail);
                    this.cpf.setText(this.vetor.elementAt(i).getCPF);
                    this.textFieldAltura.setText(this.vetor.elementAt(i).getAltura);            
                    this.textFieldAcessorio.setText(this.vetor.elementAt(i).getAcessorio);
                    this.textFieldCorCabelo.setText(this.vetor.elementAt(i).getCorCabelo);
                    this.tatu.setText(this.vetor.elementAt(i).getTatu);
                    this.marca.setText(this.vetor.elementAt(i).getMancha);
                    this.textFieldRg.setText(this.vetor.elementAt(i).getRg);
                    this.textFieldTelefone.setText(this.vetor.elementAt(i).getTelefone);
                    this.cep.setText(this.vetor.elementAt(i).getCep);
                    this.textFieldNumero.setText(this.vetor.elementAt(i).getNumero);
                    this.textFieldComplemento.setText(this.vetor.elementAt(i).getComplemento);
                    this.textFieldBairro.setText(this.vetor.elementAt(i).getBairro);
                }                
            }
        }

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

我想指出的一些事情:
1.请勿使用null布局 2.不要在泛型类中使用原始类型。您的Vector未参数化 3.请稍微清楚一下你想要达到的目标。 =)

此时不清楚按下按钮时您想要做什么。