Reinilton Posted April 7, 2015 at 02:02 AM Report Share #580878 Posted April 7, 2015 at 02:02 AM Preciso acessar as propriedades de um componente a partir de uma string igual do nome do componente. Usando a linguagem ActionScript criei um componente e coloquei o nome de meuComponente, criei uma variável tipo string com o valor "meuComponente", depois usando a string acessei uma propriedade do objeto. ------------------------------------------------------- var meuComponente:tring = "estrela"; this[meuComponente].alpha = 0.30; -------------------------------------------------------- É possível fazer isso em Java? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 7, 2015 at 06:20 AM Report Share #580881 Posted April 7, 2015 at 06:20 AM void setFloat(String componente, Float value) Class<?> class = this.getClass(); Field field = class.getDeclaredField(componente); field.setFloat(this, value); } claro que falta tratar das excepções ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
alexandre1985 Posted April 7, 2015 at 02:22 PM Report Share #580888 Posted April 7, 2015 at 02:22 PM Podes criar um objecto com um determinado nome numa arraylist e depois procuras o objecto pelo nome do genero: for(Object obj : arraylist) { if(obj.getNome().equals([i]nome[/i])) obj.setFloat(0.3); } http://alexandre1985.github.io Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now