如何通过单击(在本例中为按钮)来调整Java中窗口的大小? [英] How to resize window in Java from a click (in this case, a button)?
本文介绍了如何通过单击(在本例中为按钮)来调整Java中窗口的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道如何(以及是否)可行.我在某处阅读了有关带调整窗口大小(int,int)的ActionEvent的内容,但不确定是否是处理该事件的适当方法.
I was just wondering how (and if) this is possible. I read somewhere about an ActionEvent with resize window(int, int) but I wasn't sure if that was an appropriate way to handle it.
抱歉,这是在JPanel设置的GUI界面中
sorry this is in an GUI interface set up by JPanel
推荐答案
public static void main(String[] args) {
final JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton("Click Me");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setSize(200, 200);
}
});
frame.add(panel);
panel.add(button);
frame.pack();
frame.setVisible(true);
}
这篇关于如何通过单击(在本例中为按钮)来调整Java中窗口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文