关于JAVA按钮的小程序
//目的想点击BUTTON1出现BUTTON2,点击BUTTON2出现BUTTON3//以此类推。。。。//问题是,点击BUTTON后并不能马上出现下一个BUTTON//...
//目的想点击BUTTON1出现BUTTON2,点击BUTTON2出现BUTTON3
//以此类推。。。。
//问题是,点击BUTTON后并不能马上出现下一个BUTTON
//而是要拖动一下窗口才能出现0.0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDefaultJFrameLayout extends JFrame {
private int buttonNum = 1;
public JDefaultJFrameLayout() {
super( "JFrame Layout Demo" );
setLayout( new FlowLayout(FlowLayout.LEFT,5,5 ) );
JButton button = new JButton("Button" + buttonNum++);
button.addActionListener(new ActionListener( ) {
public void actionPerformed( ActionEvent event ) {
JButton btn = new JButton("Button" + buttonNum++);
btn.addActionListener( this );
JDefaultJFrameLayout.this.add( btn );
JDefaultJFrameLayout.this.doLayout();
}
} );
add( button );
}
public static void main(String[] args) {
JDefaultJFrameLayout layout = new JDefaultJFrameLayout();
layout.setSize(200 , 200);
layout.setTitle("DefaultJFrameLayout");
layout.setLocationRelativeTo(null);
layout.setDefaultCloseOperation(EXIT_ON_CLOSE);
layout.setVisible(true);
}
} 展开
//以此类推。。。。
//问题是,点击BUTTON后并不能马上出现下一个BUTTON
//而是要拖动一下窗口才能出现0.0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDefaultJFrameLayout extends JFrame {
private int buttonNum = 1;
public JDefaultJFrameLayout() {
super( "JFrame Layout Demo" );
setLayout( new FlowLayout(FlowLayout.LEFT,5,5 ) );
JButton button = new JButton("Button" + buttonNum++);
button.addActionListener(new ActionListener( ) {
public void actionPerformed( ActionEvent event ) {
JButton btn = new JButton("Button" + buttonNum++);
btn.addActionListener( this );
JDefaultJFrameLayout.this.add( btn );
JDefaultJFrameLayout.this.doLayout();
}
} );
add( button );
}
public static void main(String[] args) {
JDefaultJFrameLayout layout = new JDefaultJFrameLayout();
layout.setSize(200 , 200);
layout.setTitle("DefaultJFrameLayout");
layout.setLocationRelativeTo(null);
layout.setDefaultCloseOperation(EXIT_ON_CLOSE);
layout.setVisible(true);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询