【发布时间】:2012-03-17 05:08:18
【问题描述】:
我完全卡住了.. 我的目标是实现一个..简单的“听众”之类的动作 但我不知道如何.. 这是我的代码
// normaly i create an action like this
// this is JUST an example how i do this in swing
//
class la extends JFrame implements ..<someAciton>..{
JButton b = new JButton("");
add(b);
b.setAction( new Action(){
void click(){
// bla
}
});
}
我的问题是,我想在 java 中创建这个功能 目前我有 3 个类和 1 个接口
// the interface, it holds my action, wich should be performed
//
//
public interface GameActionInterface extends EventListener {
public void onTouched( MotionEvent event );
}
// this is the class whichs runs the action
//
//
public class GameActionListener {
ArrayList<GameLayoutBase>touchedListener = new ArrayList();
public void addTouchListener(GameLayoutBase obj){
touchedListener.add(obj);
}
public void onTouched( MotionEvent event){
for( GameLayoutBase elem : touchedListener ){
elem.onTouched(event);
}
}
}
// this class should to the action later
//
//
public class GameLayoutElement extends GameLayoutBase {
public GameLayoutElement(String ID) {
super(ID);
}
}
// my main class
//
//
gameEventListener = new GameActionListener();
// creating the obj
layout_Element_Player[0] = new GameLayoutElement("Builder_countA");
//
// and here is the PROBLEM - i want to overwrite the current function with my "own" code
gameEventListener.addTouchListener(layout_Element_Player[0]);
// adding the element to the listener
//
//
layout_Element_Player[0].onTouched( new GameActionInterface(){
} );
我不知道如何解决这个问题:(
【问题讨论】:
-
你们为什么给我负面评价? ..我不知道如何解决它..一些提示会很有用..
-
您在 Android 中使用 Swing(?) 组件。这显示了对 Android 工作原理的基本理解。我建议你学习一些Android开发的基础课程/教程/文章。更不用说你的问题非常模糊。
-
没有剪断的第一个代码显示我如何在 swing 中执行此操作,但我不知道如何在 andrpid / 或一般情况下在 swing 上执行此操作
标签: java android android-widget