⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securitypanel.java

📁 电话号码薄应用程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Exercise 28.13: SecurityPanel.java// Enable user to enter security codes specifying access privileges.import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.text.DateFormat;import java.util.*;public class SecurityPanel extends JFrame{   // JLabel and JPasswordField for user to input security code   private JLabel securityCodeJLabel;   private JPasswordField securityCodeJPasswordField;   // JButtons to represent security keypad   private JButton oneJButton;   private JButton twoJButton;   private JButton threeJButton;   private JButton fourJButton;   private JButton fiveJButton;   private JButton sixJButton;   private JButton sevenJButton;   private JButton eightJButton;   private JButton nineJButton;   private JButton clearJButton;   private JButton zeroJButton;   private JButton enterJButton;   // JLabel, JTextArea and JScrollPane to display access log   private JLabel accessLogJLabel;   private JTextArea accessLogJTextArea;   private JScrollPane accessLogJScrollPane;   // no-argument constructor   public SecurityPanel()   {      createUserInterface(); // set up GUI   }   // create and position GUI components; register event handlers   private void createUserInterface()   {      // get content pane for attaching GUI components      Container contentPane = getContentPane();            // enable explicit positioning of GUI components      contentPane.setLayout( null );      // set up securityCodeJLabel      securityCodeJLabel = new JLabel();      securityCodeJLabel.setBounds( 16, 16, 90, 21 );      securityCodeJLabel.setText( "Security code:" );      contentPane.add( securityCodeJLabel );      // set up securityCodeJPasswordField      securityCodeJPasswordField = new JPasswordField();      securityCodeJPasswordField.setBounds( 114, 16, 172, 26 );      securityCodeJPasswordField.setEditable( false );      contentPane.add( securityCodeJPasswordField );      // set up oneJButton      oneJButton = new JButton();      oneJButton.setBounds( 80, 64, 50, 50 );      oneJButton.setText( "1" );      contentPane.add( oneJButton );      oneJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when oneJButton is pressed            public void actionPerformed( ActionEvent event )            {               oneJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up twoJButton      twoJButton = new JButton();      twoJButton.setBounds( 130, 64, 50, 50 );      twoJButton.setText( "2" );      contentPane.add( twoJButton );      twoJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when twoJButton is pressed            public void actionPerformed( ActionEvent event )            {               twoJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up threeJButton      threeJButton = new JButton();      threeJButton.setBounds( 180, 64, 50, 50 );      threeJButton.setText( "3" );      contentPane.add( threeJButton );      threeJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when threeJButton is pressed            public void actionPerformed( ActionEvent event )            {               threeJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up fourJButton      fourJButton = new JButton();      fourJButton.setBounds( 80, 114, 50, 50 );      fourJButton.setText( "4" );      contentPane.add( fourJButton );      fourJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when fourJButton is pressed            public void actionPerformed( ActionEvent event )            {               fourJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up fiveJButton      fiveJButton = new JButton();      fiveJButton.setBounds( 130, 114, 50, 50 );      fiveJButton.setText( "5" );      contentPane.add( fiveJButton );      fiveJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when fiveJButton is pressed            public void actionPerformed( ActionEvent event )            {               fiveJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up sixJButton      sixJButton = new JButton();      sixJButton.setBounds( 180, 114, 50, 50 );      sixJButton.setText( "6" );      contentPane.add( sixJButton );      sixJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when sixJButton is pressed            public void actionPerformed( ActionEvent event )            {               sixJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up sevenJButton      sevenJButton = new JButton();      sevenJButton.setBounds( 80, 164, 50, 50 );      sevenJButton.setText( "7" );      contentPane.add( sevenJButton );      sevenJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when sevenJButton is pressed            public void actionPerformed( ActionEvent event )            {               sevenJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up eightJButton      eightJButton = new JButton();      eightJButton.setBounds( 130, 164, 50, 50 );      eightJButton.setText( "8" );      contentPane.add( eightJButton );      eightJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when eightJButton is pressed            public void actionPerformed( ActionEvent event )            {               eightJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up nineJButton      nineJButton = new JButton();      nineJButton.setBounds( 180, 164, 50, 50 );      nineJButton.setText( "9" );      contentPane.add( nineJButton );      nineJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when nineJButton is pressed            public void actionPerformed( ActionEvent event )            {               nineJButtonActionPerformed( event );            }         } // end anonymous inner class      ); // end call to addActionListener      // set up clearJButton      clearJButton = new JButton();      clearJButton.setBounds( 80, 214, 50, 50 );      clearJButton.setText( "C" );      contentPane.add( clearJButton );      clearJButton.addActionListener(         new ActionListener() // anonymous inner class         {            // event handler called when clearJButton is pressed            public void actionPerformed( ActionEvent event )            {               clearJButtonActionPerformed( event );            }

⌨️ 快捷键说明

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