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

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

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

  1. SNpanel(){
  2. this.setPreferredSize(new Dimension(SIDE, SIDE));
  3. this.setBackground(Color.black);
  4. this.setFocusable(true);
  5. this.setLayout(null);
  6. this.addKeyListener(this);
  7. f1= new Font("Courier", Font.BOLD, 20);
  8. labels();
  9. timer = new Timer();
  10. tasks();
  11. // resize would be here but i dont know how to do it after a certain command
  12. }
  13. // alot of random code
  14. public void resize() {
  15. if (locx == SIDE) { // the command
  16. }
  17. //more random code
  18. else if (key == KeyEvent.VK_RIGHT && ghostnod) {
  19. i1.setVisible(false);
  20. i2.setVisible(false);
  21. i3.setVisible(false);
  22. i4.setVisible(true);
  23. locx += 7;
  24. i4.setLocation(locx, locy);
  25. resize(); // where the command is made
  26. }

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

暂无答案!

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

相关问题