borderlayoutdemo2.java
来自「精通Java核心技术源代码」· Java 代码 · 共 53 行
JAVA
53 行
import java.awt.*;
import javax.swing.*;
public class BorderLayoutDemo2 extends JFrame
{
private JPanel buttonPanel;
private String microsoft = "Microsoft ";
private String word = "Word ";
private String excel = "Excel ";
private String powerPoint = "PowerPoint ";
private String frontPage = "FrontPage ";
private JButton microsoftButton,wordButton,excelButton,powerPointButton,
frontPageButton;
public BorderLayoutDemo2()
{
super( "BorderLayoutDemo2" );
Container container = getContentPane();
// 创建buttonPanel
buttonPanel = new JPanel();
buttonPanel.setLayout( new FlowLayout( FlowLayout.CENTER,6,10 ) );
// 创建按钮
microsoftButton = new JButton( microsoft );
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 );
// 将microsoftButton 和 buttonPanel 加入 container
container.add( microsoftButton,BorderLayout.CENTER );
container.add( buttonPanel,BorderLayout.SOUTH );
setSize( 400,240 );
setVisible( true );
}
public static void main(String[] args)
{
BorderLayoutDemo2 borderLayoutDemo2 = new BorderLayoutDemo2();
borderLayoutDemo2.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?