flowlayoutdemo.java
来自「精通Java核心技术源代码」· Java 代码 · 共 50 行
JAVA
50 行
import java.awt.*;
import javax.swing.*;
public class FlowLayoutDemo extends JFrame
{
private JPanel buttonPanel;
private String word = "Word ";
private String excel = "Excel ";
private String powerPoint = "PowerPoint ";
private String frontPage = "FrontPage ";
private JButton wordButton,excelButton,powerPointButton,frontPageButton;
public FlowLayoutDemo()
{
super( "FlowLayoutDemo" );
Container container = getContentPane();
// 创建一个用于摆放按钮的Panel
buttonPanel = new JPanel();
buttonPanel.setLayout( new FlowLayout( FlowLayout.CENTER,4,4 ) );
// 创建按钮
wordButton = new JButton( word );
excelButton = new JButton( excel );
powerPointButton = new JButton( powerPoint );
frontPageButton = new JButton( frontPage );
// 将按钮加入buttonPanel中
buttonPanel.add( wordButton );
buttonPanel.add( excelButton );
buttonPanel.add( powerPointButton );
buttonPanel.add( frontPageButton );
// 将buttonPanel 加入 container中
container.add( buttonPanel );
setSize( 260,120 );
setVisible( true );
}
public static void main(String[] args)
{
FlowLayoutDemo flowLayoutDemo = new FlowLayoutDemo();
flowLayoutDemo.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?