📄 petstoreadminclient.java
字号:
toolBar.add(salesToggleButton); toolBar.addSeparator(); ButtonGroup group = new ButtonGroup(); group.add(ordersToggleButton); group.add(salesToggleButton); ordersToggleButton.setSelected(true); JButton button = toolBar.add(refreshAction); button.setToolTipText( (String)refreshAction.getValue(Action.SHORT_DESCRIPTION)); button.addMouseListener(mouseHandler); button = toolBar.add(aboutAction); button.setToolTipText( (String)aboutAction.getValue(Action.SHORT_DESCRIPTION)); button.addMouseListener(mouseHandler); return toolBar; } private static ResourceBundle getResourceBundle() { if (bundle == null) { bundle = ResourceBundle.getBundle("resources.petstore"); } return bundle; } /** * Retrieve a localized string from our resource bundle. * * @param key Key for the string we want to retrieve. * @return Localized string. */ public static String getString(String key) { String result = null; try { result = getResourceBundle().getString(key); } catch (MissingResourceException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return result; } /** * Retrieve a localized mnemonic character from our resource bundle. * * @param key Key for the mnemonic character we want to retrieve. * @return Localized mnemonic character. */ public static char getMnemonic(String key) { return (getString(key)).charAt(0); } /** * Retrieve an integer from our resource bundle. * * @param key Key for the integer we want to retrieve. * @return Integer value. */ public static int getInteger(String key) { int result = -1; try { result = Integer.parseInt(getString(key)); } catch (NumberFormatException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return result; } public void propertyChange(PropertyChangeEvent e) { String property = e.getPropertyName(); if (DataSource.DISABLE_ACTIONS.equals(property)) { refreshAction.setEnabled(false); aboutAction.setEnabled(false); exitAction.setEnabled(false); } else if (DataSource.ENABLE_ACTIONS.equals(property)) { refreshAction.setEnabled(true); aboutAction.setEnabled(true); exitAction.setEnabled(true); } } private class MouseHandler extends MouseAdapter { public MouseHandler() { } public void mouseEntered(MouseEvent evt) { if (evt.getSource() instanceof AbstractButton) { AbstractButton button = (AbstractButton)evt.getSource(); Action action = button.getAction(); if (action != null) { // Set the status bar message. StatusBar.getInstance().setMessage( (String)action.getValue(Action.LONG_DESCRIPTION)); } } } public void mouseExited(MouseEvent e) { StatusBar.getInstance().setMessage(null); } } protected class ExitAction extends AbstractAction { public ExitAction() { super(getString("ExitAction.name")); putValue(SHORT_DESCRIPTION, getString("ExitAction.tooltip")); putValue(LONG_DESCRIPTION, getString("ExitAction.description")); } public void actionPerformed(ActionEvent e) { System.exit(0); } } protected class OrdersAction extends AbstractItemAction { public OrdersAction() { super(getString("OrdersAction.name")); putValue(SHORT_DESCRIPTION, getString("OrdersAction.tooltip")); putValue(LONG_DESCRIPTION, getString("OrdersAction.description")); putValue(SMALL_ICON, new ImageIcon( getClass().getResource("/resources/orders.gif"))); } public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Remove sales panel. if (salesTabbedPane.isShowing()) { getContentPane().remove(salesTabbedPane); } // Add tabbed pane. if (!ordersTabbedPane.isShowing()) { getContentPane().add(ordersTabbedPane, BorderLayout.CENTER); } validate(); repaint(); } }); } public void itemStateChanged(ItemEvent evt) { boolean show; if (evt.getStateChange() == ItemEvent.SELECTED) { show = true; } else { show = false; } // Update all objects that share this item setSelected(show); } } protected class SalesAction extends AbstractItemAction { public SalesAction() { super(getString("SalesAction.name")); putValue(SHORT_DESCRIPTION, getString("SalesAction.tooltip")); putValue(LONG_DESCRIPTION, getString("SalesAction.description")); putValue(SMALL_ICON, new ImageIcon( getClass().getResource("/resources/sales.gif"))); } public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { //Remove tabbed pane. if (ordersTabbedPane.isShowing()) { getContentPane().remove(ordersTabbedPane); } // Add sales panel. if (!salesTabbedPane.isShowing()) { getContentPane().add(salesTabbedPane, BorderLayout.CENTER); } validate(); repaint(); } }); } public void itemStateChanged(ItemEvent evt) { boolean show; if (evt.getStateChange() == ItemEvent.SELECTED) { show = true; } else { show = false; } // Update all objects that share this item setSelected(show); } } protected class AboutAction extends AbstractAction { public AboutAction() { super(getString("AboutAction.name")); putValue(SHORT_DESCRIPTION, getString("AboutAction.tooltip")); putValue(LONG_DESCRIPTION, getString("AboutAction.description")); putValue(SMALL_ICON, new ImageIcon( getClass().getResource("/resources/About24.gif"))); } public void actionPerformed(ActionEvent e) { about(); } } public static void main(String args[]) { if (args.length != 4) { System.err.println("Usage: java PetStoreAdminClient <class name for petstore proxy> <hostname> " + "<port> <session id>"); System.exit(1); } new PetStoreAdminClient(args[0], args[1], args[2], args[3]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -