【问题标题】:Array to JLabel数组到 JLabel
【发布时间】:2013-03-17 04:50:53
【问题描述】:

我有两个带有 java 类的包

  • PKStrings
  • PkJforms

public class classWork {
    public String[] titleMenu={
        "A","B","C","D"
    };

    public int intOption;
}

我有 JFrame 和菜单

  • 一个点击去jframe A,

    B点击去jframe B,

    C click go jframe C,

    D click go jframe D

和同一个包中的其他框架 JFram01,包含JLabel

如果点击“A”并显示该位置标签,如何识别?

【问题讨论】:

  • "A 点击 go jframe A,B 点击 go jframe B,C 点击 go jframe C,D 点击 go jframe D" Arrrgh!请参阅The Use of Multiple JFrames, Good/Bad Practice? 对于“大量视图”,最好使用CardLayout 来完成。
  • 请参阅this answer,了解如何使用CardLayout(和JOptionPane 选择卡片)来实现此目的。

标签: java arrays string swing


【解决方案1】:
I dont understand your need. "A click A go jframe A" doesnot make sense.
if you want to go to another jFrame when clicking a label
Try this

    private void yourlabelMouseClicked(java.awt.event.MouseEvent evt) {
          //  either you can hide the current jFrame by setting 
            jFrame.setVisible(false);
            newjFrame.setVisible(True);
                    or
            make these jFrames in 2 different classes that make simple invocations
        }

【讨论】:

  • 检查我的练习 mediafire.com/?pjf7w6x9l6b62g8
【解决方案2】:

据我了解,您可以在包中使用公共变量并使用 A、B、C 上的点击事件在其中存储值.....

然后从您想要的 jfaram 访问该信息

例如

public String pos ="";

A onclick event(){
   pos="A";
}


finally

if(pos.compareto("A")==0){
   jlabel.settext("A");
}

【讨论】:

  • 如果我单击 jbutton“添加”标题集“添加”,请检查我在课堂作业中的练习 mediafire.com/?pjf7w6x9l6b62g8 包含标题页。
  • 在单击 Jbutton Sumas(menuFrame.java) 时从数组字符串 titleMenu 示例“Suma”中设置 opacionesframe.java 上的标题菜单。
  • 导入 pkWorking.classWork; String[] newMenu = new classWork().titleMenu;
猜你喜欢
  • 1970-01-01
  • 2012-07-18
  • 1970-01-01
  • 2018-04-18
  • 2011-07-07
  • 2021-11-08
  • 2012-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多