按钮中的活动

时间:2014-02-11 12:50:53

标签: java swing applet

我可以在我的代码中插入调用此类的类吗?

我想要发生的是,当我点击按钮时,maze.java(我想要调用的类)会运行吗? ,谢谢!

public class Main extends Applet {

    Button mazebutton;
    Button hexbutton;

    public void init() {

    mazebutton = new Button("Create a maxe");
    hexbutton = new Button ("Create a hexagonal Maze");

    mazebutton.setBounds(20,20,100,30);
    hexbutton.setBounds(20,70,100,40); 

    add(mazebutton);
    add(hexbutton);
    }

}

1 个答案:

答案 0 :(得分:0)

你需要像

这样的代码
button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        //here you need to call a function that you need to make
        //on "maze.java"  that returns the values of each variable
        //or starts by launching other function in the same class
        //(maze.java) that activates the game
    }
});