跪求哪位java大神帮我解释下下面一段代码是什么意思啊~~ 最好是每一句都有解释。。 谢谢啦~~!!!!
//Fig.12.25:BorderLayoutDemo.java布局管理器//DemonstratingBorderLayout.importjava.awt.*;导入...
// Fig. 12.25: BorderLayoutDemo.java 布局管理器
// Demonstrating BorderLayout.
import java.awt.*;导入java子包awt包中所有的类
import java.awt.event.*;
import javax.swing.*;
public class BorderLayoutDemo extends JFrame
implements ActionListener {
private JButton b[];
private String names[] =
{ "Hide North", "Hide South", "Hide East",
"Hide West", "Hide Center" };
private BorderLayout layout;
public BorderLayoutDemo()
{
super( "BorderLayout Demo" );
layout = new BorderLayout( 5, 5 );
Container c = getContentPane();
c.setLayout( layout );
// instantiate button objects
b = new JButton[ names.length ];
for ( int i = 0; i < names.length; i++ ) {
b[ i ] = new JButton( names[ i ] );
b[ i ].addActionListener( this );
}
// order not important
c.add( b[ 0 ], BorderLayout.NORTH ); // North position
c.add( b[ 1 ], BorderLayout.SOUTH ); // South position
c.add( b[ 2 ], BorderLayout.EAST ); // East position
c.add( b[ 3 ], BorderLayout.WEST ); // West position
c.add( b[ 4 ], BorderLayout.CENTER ); // Center position
setSize( 300, 200 );
show();
}
public void actionPerformed( ActionEvent e )
{
for ( int i = 0; i < b.length; i++ )
if ( e.getSource() == b[ i ] )
b[ i ].setVisible( false );
else
b[ i ].setVisible( true );
// re-layout the content pane
layout.layoutContainer( getContentPane() );
}
public static void main( String args[] )
{
BorderLayoutDemo app = new BorderLayoutDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
/**************************************************************************
* (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall. *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/ 展开
// Demonstrating BorderLayout.
import java.awt.*;导入java子包awt包中所有的类
import java.awt.event.*;
import javax.swing.*;
public class BorderLayoutDemo extends JFrame
implements ActionListener {
private JButton b[];
private String names[] =
{ "Hide North", "Hide South", "Hide East",
"Hide West", "Hide Center" };
private BorderLayout layout;
public BorderLayoutDemo()
{
super( "BorderLayout Demo" );
layout = new BorderLayout( 5, 5 );
Container c = getContentPane();
c.setLayout( layout );
// instantiate button objects
b = new JButton[ names.length ];
for ( int i = 0; i < names.length; i++ ) {
b[ i ] = new JButton( names[ i ] );
b[ i ].addActionListener( this );
}
// order not important
c.add( b[ 0 ], BorderLayout.NORTH ); // North position
c.add( b[ 1 ], BorderLayout.SOUTH ); // South position
c.add( b[ 2 ], BorderLayout.EAST ); // East position
c.add( b[ 3 ], BorderLayout.WEST ); // West position
c.add( b[ 4 ], BorderLayout.CENTER ); // Center position
setSize( 300, 200 );
show();
}
public void actionPerformed( ActionEvent e )
{
for ( int i = 0; i < b.length; i++ )
if ( e.getSource() == b[ i ] )
b[ i ].setVisible( false );
else
b[ i ].setVisible( true );
// re-layout the content pane
layout.layoutContainer( getContentPane() );
}
public static void main( String args[] )
{
BorderLayoutDemo app = new BorderLayoutDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
/**************************************************************************
* (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall. *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/ 展开
展开全部
import java.awt.*;//导入java子包awt包中所有的类
import java.awt.event.*;
import javax.swing.*;
public class BorderLayoutDemo extends JFrame
implements ActionListener {
private JButton b[];
private String names[] =
{ "Hide North", "Hide South", "Hide East",
"Hide West", "Hide Center" };
private BorderLayout layout;
public BorderLayoutDemo()
{
super( "BorderLayout Demo" );//窗口名称设置为"BorderLayout Demo"
layout = new BorderLayout( 5, 5 );//BoderLayout是一个东西南北中的布局模式 5,5是 组件之间的间距
Container c = getContentPane();//获取JFrame默认的布局容器panel
c.setLayout( layout );//设置容器布局模式为BorderLayout布局
// instantiate button objects
b = new JButton[ names.length ];//根据数组names长度开辟按键数组
for ( int i = 0; i < names.length; i++ ) {//实例化每个按键
b[ i ] = new JButton( names[ i ] );
b[ i ].addActionListener( this );//为按键加入监听
}
// order not important
c.add( b[ 0 ], BorderLayout.NORTH ); // North position 将b[0]放在北边
c.add( b[ 1 ], BorderLayout.SOUTH ); // South position 将b[1]放在南边
c.add( b[ 2 ], BorderLayout.EAST ); // East position 将b[2]放在东边
c.add( b[ 3 ], BorderLayout.WEST ); // West position 将b[3]放在西边
c.add( b[ 4 ], BorderLayout.CENTER ); // Center position将 b[4]放在中部
setSize( 300, 200 ); //设置窗口大小
show();//显示窗口 已过时 建议使用 setVisible(true);//设置可见
}
public void actionPerformed( ActionEvent e )//监听
{
for ( int i = 0; i < b.length; i++ )
if ( e.getSource() == b[ i ] )
b[ i ].setVisible( false ); //按键设置为不可见
else
b[ i ].setVisible( true );//按键设置为可见
// re-layout the content pane
layout.layoutContainer( getContentPane() );//重新布局
}
public static void main( String args[] )
{
BorderLayoutDemo app = new BorderLayoutDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )//窗口关闭 退出
{
System.exit( 0 );
}
}
);
}
}
import java.awt.event.*;
import javax.swing.*;
public class BorderLayoutDemo extends JFrame
implements ActionListener {
private JButton b[];
private String names[] =
{ "Hide North", "Hide South", "Hide East",
"Hide West", "Hide Center" };
private BorderLayout layout;
public BorderLayoutDemo()
{
super( "BorderLayout Demo" );//窗口名称设置为"BorderLayout Demo"
layout = new BorderLayout( 5, 5 );//BoderLayout是一个东西南北中的布局模式 5,5是 组件之间的间距
Container c = getContentPane();//获取JFrame默认的布局容器panel
c.setLayout( layout );//设置容器布局模式为BorderLayout布局
// instantiate button objects
b = new JButton[ names.length ];//根据数组names长度开辟按键数组
for ( int i = 0; i < names.length; i++ ) {//实例化每个按键
b[ i ] = new JButton( names[ i ] );
b[ i ].addActionListener( this );//为按键加入监听
}
// order not important
c.add( b[ 0 ], BorderLayout.NORTH ); // North position 将b[0]放在北边
c.add( b[ 1 ], BorderLayout.SOUTH ); // South position 将b[1]放在南边
c.add( b[ 2 ], BorderLayout.EAST ); // East position 将b[2]放在东边
c.add( b[ 3 ], BorderLayout.WEST ); // West position 将b[3]放在西边
c.add( b[ 4 ], BorderLayout.CENTER ); // Center position将 b[4]放在中部
setSize( 300, 200 ); //设置窗口大小
show();//显示窗口 已过时 建议使用 setVisible(true);//设置可见
}
public void actionPerformed( ActionEvent e )//监听
{
for ( int i = 0; i < b.length; i++ )
if ( e.getSource() == b[ i ] )
b[ i ].setVisible( false ); //按键设置为不可见
else
b[ i ].setVisible( true );//按键设置为可见
// re-layout the content pane
layout.layoutContainer( getContentPane() );//重新布局
}
public static void main( String args[] )
{
BorderLayoutDemo app = new BorderLayoutDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )//窗口关闭 退出
{
System.exit( 0 );
}
}
);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询