JAVA 存放jlabel数组,Java的 - 改变一个JLabel随着文本在一个阵列存储

Hello World, Am kinda new to java and i am trying to create a method that changes a JLabel's text to some text stored in an array when an action happens, somthing like this :

JLabel one = new JLabel("Hello World");

JButton b1 = new JButton("Next");

JButton b2 = new JButton("Prev");

String[] main = ["LoveLace","Dynamics","Creed","Main"];

b1.addActionListsner(new ActionListener() {

actionPerformed(ActionEvent e) {

//In here it will load the first indexed string which is "Lovelace"

//This is where i need help

//Think of it like a jQuery slider

//When the next button is clicked, it loads a new word to the element

//When the prev button is clicked it load the last indexed string of the array

Please This is actually a manual word slider that is changes the text when the next button is clicked and loads the last indexed string of the array when the prev button is clicked, Please i dont hava any idea on how to do this, please help

解决方案

I think this should work...

private void yourMethodName(final String newLabelText) {

one.setText(newLabelText);

}

if you want to use this method universal...

private void yourMethodName(final JLabel label, final String newLabelText) {

label.setText(newLabelText);

}

now you just need call this method(s) with the parameter(s) you want to change. If the changes are not diesplayed, you need to repaint the container where your stuff is in. If you don't use a container I would advice you to create one and add all your stuff into this container. The aswer of this thread might be helpful.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值