Page 168 - 4836
P. 168
setJMenuBar (menuBar) ;
JToolBar toolBar = new JToolBar («Панель
інструментів") ;
toolBar.add (exitAction) ;
toolBar.add (deactivateAction) ;
getContentPane ( ). add ( toolBar, BorderLayout.NORTH );
JPanel panel = new JPanel ();
panel.add ( new JButton ( exitAction ));
panel.add ( new JButton ( deactivateAction ));
getContentPane ( ). add (panel);
setSize (250,250);
}
Class ExitAction extends AbstractAction {
ExitAction () { putValue (Action.NAME, "Вийти");
putValue (Action.SHORT_DESCRIPTION, "Програма
перестане працювати, а вікно зникне з екрану. ");
putValue ( Action.SMALL_ICON, new
ImageIcon("2.gif")) ;
}
Public void actionPerformed ( ActionEvent event ) {
System.exit (0);
}}
Class DeactivateAction extends AbstractAction {
DeactivateAction () {
putValue ( Action.NAME , "Заборонити вихід") ;
putValue ( Action.SMALL_ICON, new ImageIcon
("1.gif" )) ;
}
Public void actionPerformed ( ActionEvent event ) {
if ( exitAction.isEnabled ( )) {
exitAction.setEnabled (false);
putValue ( Action.NAME , "Дозволити вихід");
}
Else { exitAction.setEnabled (true);
166