如果创建新的JPanel并将其添加到原始帧,是否可以重置inputmap和actionmap?在我看来,inputmap和actionmap是静态的,这意味着每个都只有一个并且由所有JPanel共享,我是对的吗?
例如:
(这不起作用)
game_compos(main_frame frame_)
{
frame=frame_;
refresh=1000;
restart();
if_restart=false;
}
public void restart()
{
if(jp!=null)
frame.remove(jp);
jp=new JPanel();
jp.getInputMap().put(KeyStroke.getKeyStroke("N"),"restart");
jp.getActionMap().put("restart",new AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if_restart=true;
}
});
map=new map_utilities();
roles=new roles_manager(refresh,frame,map,jp);
frame.add(jp);
}
public void paintComponent(Graphics g)
{
if(if_restart)
{
if_restart=false;
restart();
}
map.draw(g);
roles.draw(g);
try
{
TimeUnit.MICROSECONDS.sleep(refresh);
}
catch(InterruptedException e)
{
Thread.currentThread().interrupt();
}
repaint();
}
某些KeyStroke在roles_manager类型的变量中设置,以更改变量的特定值。我需要为新的roles_manager变量重置它