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);
}
} 展开
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);
}
} 展开
1个回答
展开全部
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);}
}
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);}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询