2011-09-07 3 views
0

형태 파라미터를 취합니다클래스 JComboBox에 내가 내 청취자에 JComboBox의 인스턴스의 값을 얻으려면

object NoteListener extends ActionListener { 
    def actionPerformed(e:ActionEvent):Unit = { 
    println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue) 
    } 
} 

을 그리고 난이 오류를 얻을 : 내가 어떤 매개 변수를 전달하려고 할 때

[error] .../test.scala:30: class JComboBox takes type parameters 
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue) 

을 :

[error] .../test.scala:30: ']' expected but '(' found. 
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox(Array)].getValue) 

버그입니까, 아니면 내 무지입니까?

+0

저는 scala에 대해서는 모르지만 Java 7의 'JComboBox'(및 다른 Swing 클래스)에 대한 변경과 관련이 있습니다. 이는 일반적인 매개 변수 (예 : 유형 매개 변수)로 변경되었습니다. –

+0

나는 바보입니다. "[]"대신 "()"을 사용했습니다. asInstanceOf가 아니면 안된다 [JComboBox [Array [java.lang.Object]]] – ciembor

답변

3

당신에게 인스턴스를 제공해야하지 귀하의 유형 매개 변수가 올바르지 않습니다 :

e.getSource.asInstanceOf[JComboBox(Array)].getValue) 

e.getSource.asInstanceOf[JComboBox[Array]].getValue) 

참고 [배열]이어야한다. 이것은 스칼라에서 타입 매개 변수를 지정하는 방법입니다.

0

확실하지만이 JComboBox에

e.getSource.peer 
관련 문제