【问题标题】:Calling method from a component by its name in a string [duplicate]通过字符串中的名称从组件调用方法[重复]
【发布时间】:2013-01-23 11:04:11
【问题描述】:

我只是想知道是否有任何方法可以通过字符串中的名称从对象上调用方法。

类似的东西

setLocation(int,int) 这是来自jLabel1 的方法,我如何通过在字符串中使用其名称来调用它
method(setLocation())

String component = jLabel1.getName();
component.setLocation(x,y);

【问题讨论】:

  • 您需要使用反射。但是有什么要求,你需要在哪里做这样的事情?

标签: java string methods


【解决方案1】:

当然,您可以使用Java reflection API

This SO question 可以帮到你。

【讨论】:

  • 嗯,我会阅读反射 API,谢谢
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 2017-10-10
  • 2017-07-16
  • 2015-07-31
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多