2013-03-17 22 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