complete15_1.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 35 行

JAVA
35
字号
package questions.c15;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Complete15_1 extends JPanel {
   private JLabel msg = new JLabel( "Default message" );
   public Complete15_1() {
      setLayout( new BorderLayout() );
      add( msg, BorderLayout.NORTH );
      JButton okay = new JButton( "OK" );
      okay.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
               // disappear when the button is clicked
               Complete15_1.this.setVisible( false );
            }
         }
      );
      JPanel p = new JPanel();
      p.setLayout( new FlowLayout( FlowLayout.CENTER ) );
      p.add( okay );
      add( p, BorderLayout.SOUTH );
   }
   public void displayMessage() {
      setVisible( true );
   }
   public void setMessage( String message ) {
      msg.setText( message );
   }
   public String getMessage() {
      return msg.getText();
   }
   public Dimension getPreferredSize() {
      return new Dimension( 200, 75 );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?