如何在一个类中使用此函数调整jpanel的大小?

5anewei6  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(127)

在程序中,我使用了两个类(一个扩展了jframe,另一个扩展了jpanel)。我需要在某个动作发生后调整面板的大小。我只能直接调整它的大小,因为我不得不使用这个。面板组件的一些东西。

SNpanel(){
    this.setPreferredSize(new Dimension(SIDE, SIDE));
    this.setBackground(Color.black);
    this.setFocusable(true);
    this.setLayout(null);
    this.addKeyListener(this);
    f1= new Font("Courier", Font.BOLD, 20);
    labels();
    timer = new Timer();
    tasks();
    // resize would be here but i dont know how to do it after a certain command
} 
// alot of random code
public void resize() {
    if (locx == SIDE) { // the command
    }

//more random code
else if (key == KeyEvent.VK_RIGHT && ghostnod) {
        i1.setVisible(false);
        i2.setVisible(false);
        i3.setVisible(false);
        i4.setVisible(true);
        locx += 7;
        i4.setLocation(locx, locy);
        resize(); // where the command is made
    }

基本上,我不知道在经过一组计时器之后(在随机代码部分),以及当用户通过按右箭头激活else if语句直到resize()方法被激活时,如何调整面板的大小。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题