swing界面刷新问题

请问我重置之后怎么没有设置Layout成功importjava.awt.GridLayout;importjava.awt.event.ActionEvent;impor... 请问我重置之后怎么没有设置Layout成功

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;

public class AutoFlash extends JFrame{

JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu("Menu");
JMenuItem jmi = new JMenuItem("jmi");

AutoFlash(){

this.setSize(400, 300);
this.setJMenuBar(jmb);
jmb.add(jm);
jm.add(jmi);
this.add(new JLabel("JLabel",JLabel.CENTER));
JButton jb = new JButton("button");
this.add(jb);
jb.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
createNew();
}

});

this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}

private void createNew() {
this.getContentPane().removeAll();
this.repaint();

this.setLayout(new GridLayout(3,2));
this.add(new JButton("1"));
this.add(new JButton("2"));
this.add(new JButton("3"));
this.add(new JButton("4"));
this.add(new JButton("5"));
this.add(new JButton("6"));

}

public static void main(String[] args) {
(new AutoFlash()).setVisible(true);
}

}
展开
 我来答
hardneedl
2010-04-02 · TA获得超过921个赞
知道小有建树答主
回答量:1353
采纳率:57%
帮助的人:598万
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AutoFlash extends JFrame {
JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu("Menu");
JMenuItem jmi = new JMenuItem("jmi");
AutoFlash() {
setSize(400, 300);
setJMenuBar(jmb);
jmb.add(jm);
jm.add(jmi);
add(new JLabel("JLabel", JLabel.CENTER));
JButton jb = new JButton("button");
add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createNew();
}
});

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void createNew() {
Container container = getContentPane();
container.removeAll();
setLayout(new GridLayout(3, 2));
container.add(new JButton("1"));
container.add(new JButton("2"));
container.add(new JButton("3"));
container.add(new JButton("4"));
container.add(new JButton("5"));
container.add(new JButton("6"));
pack();
}
public static void main(String[] args) {(new AutoFlash()).setVisible(true);}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式