1 import org.swixml.SwingEngine; 2 3 import javax.swing.*; 4 import java.awt.event.ActionEvent ; 5 import java.awt.event.ActionListener ; 6 import java.awt.event.WindowAdapter ; 7 import java.awt.event.WindowEvent ; 8 9 17 public class Actions extends WindowAdapter implements ActionListener { 18 private SwingEngine swix; 19 20 public JMenuItem mi_exit, mi_save; 21 public JPanel pnl_North; 22 27 28 public Action newAction = new AbstractAction() { 29 30 public void actionPerformed(ActionEvent e) { 31 System.out.println( "New" ); this.setEnabled( false ); } 34 }; 35 36 37 public Action openAction = new AbstractAction() { 38 39 public void actionPerformed(ActionEvent e) { 40 System.out.println( "Open" ); 41 } 42 }; 43 44 45 public Action petAction = new AbstractAction() { 46 public void actionPerformed(ActionEvent e) { 47 System.out.println( ((JComboBox) e.getSource()).getSelectedItem().toString() ); 48 } 49 }; 50 51 52 55 private Actions() { 56 try { 57 swix = new SwingEngine( this ); 58 swix.render( "xml/actions.xml" ); 59 60 63 swix.setActionListener( pnl_North, this ); 65 mi_exit.addActionListener( this ); 67 mi_save.addActionListener( this ); 69 swix.getRootComponent().setVisible(true); 77 } catch (Exception e) { 78 e.printStackTrace(); 79 } 80 } 81 82 86 89 public void actionPerformed(ActionEvent e) { 90 String command = e.getActionCommand(); 91 if ("AC_EXIT".equals( command )) { 92 this.windowClosing( null ); 93 } else if ("AC_SAVE".equals( command )) { 94 System.out.println( "Save" ); 95 } else { 96 System.out.println( "Click" ); 97 } 98 } 99 100 104 110 public void windowClosing(WindowEvent e) { 111 System.out.println( "Good Bye!" ); 112 super.windowClosing(e); 113 System.exit( 0 ); 114 } 115 116 120 public static void main(String [] args) { 121 new Actions(); 122 } 123 } 124 | Popular Tags |