2013-03-17 38 views
0

我有两个包为Java类阵列来的JLabel

  • PKStrings
  • PkJforms

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

    public int intOption; 
} 

JFrame与菜单

  • 甲点击go JFrame的A,

    乙单击Go的JFrame B,

    c点击去的JFrame C,

    d点击go的JFrame d

而在同一包中的其他帧 JFram01,包含JLabel

如何识别您是否点击“A”并显示位置标签?

+1

*“的点击去JFrame的A, b。单击去的JFrame B, c。单击去JF rame C, D click go jframe D“* Arrrgh!请参阅[使用多个JFrames,好/坏实践?](http://stackoverflow.com/a/9554657/418556)对于'很多视图',这可能最好使用'CardLayout'完成。 – 2013-03-17 05:20:43

+1

请参阅[本答案](http://stackoverflow.com/a/15308365/418556)了解如何使用CardLayout(和“JOptionPane”选择卡片)来实现此目的。 – 2013-03-17 05:57:53

回答

0
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 
     } 
+0

检查我的练习mediawork.com/?pjf7w6x9l6b62g8 – NOne 2013-03-17 05:20:39

0

从我的理解u能上A,B,C点击事件中使用它使用一个公共变量在你的包和存储值.....

然后访问从信息在jfaram你想

public String pos =""; 

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


finally 

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

检查我的练习http://www.mediafire.com/?pjf7w6x9l6b62g8 在类Classwork Containts tittle pages如果我点击jbutton“添加”标题集“添加”。 – NOne 2013-03-17 05:16:30

+0

你的问题是什么? – LynAs 2013-03-17 05:23:58

+0

在数组字符串的operacionesframe.java上设置标题菜单titleMenu当点击Jbutton Sumas(menuFrame.java)时的例子“Suma”。 – NOne 2013-03-17 05:32:45