改变一个JLabel随着文本在一个阵列存储

改变一个JLabel随着文本在一个阵列存储

本文介绍了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

请这实际上是一个手动字滑块是改变了下一个按钮被点击时,文本以及单击$ P $光伏按钮时加载数组的最后一个索引的字符串,请我不哈瓦如何任何想法这样做,请帮助

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);
}

现在,你只需要调用这个方法(S)你想改变的参数(S)。如果所做的更改不会diesplayed,则需要重新绘制容器,其中你的东西是,如果你不使用的容器我会建议你创建一个并添加你所有的东西到这个容器中。的aswer this跟帖可能会有所帮助。

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.

这篇关于Java的 - 改变一个JLabel随着文本在一个阵列存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:14