public class GraghView extends JPanel
{
public static GraghView getInstance()
{
if(instance == null)
{
instance = new GraghView();
}
return instance;
}
GraghView在一个面板上,
在另一个类 MainFrame.this.buildContentPane();//初始化该面板,不能显示GraghView里的内容.现在加了 GraghView.getInstance();仍然显示不了,请教高手了现在没分了,先给这些,有了分再补给助人为乐的高手了.

解决方案 »

  1.   

    ////////////////////////
        /**
         * Creates and returns a <code>JButton</code> 
         * configured for use in a JToolBar.<p>
         * 
         * This is a simplified method that is overriden by the Looks Demo.
         * The full code uses the JGoodies UI framework's ToolBarButton
         * that better handles platform differences.
         */
        protected AbstractButton createToolBarButton(String iconName) {
            JButton button = new JButton(readImageIcon(iconName));
            button.setFocusable(false);
            return button;
        }     /**
         * Creates and returns a <code>JToggleButton</code> 
         * configured for use in a JToolBar.<p>
         * 
         * This is a simplified method that is overriden by the Looks Demo.
         * The full code uses the JGoodies UI framework's ToolBarButton
         * that better handles platform differences.
         */
        protected AbstractButton createToolBarRadioButton(String iconName) {
            JToggleButton button = new JToggleButton(readImageIcon(iconName));
            button.setFocusable(false);
            return button;
        }     // Tabbed Pane **********************************************************
     
        protected String getWindowTitle() {
            return "WSCModeler";
        }
             // Helper Code **********************************************************************     /*
         * Looks up and answers an icon for the specified filename suffix.<p>
         */
        protected static ImageIcon readImageIcon(String filename) {
            URL url =
             MainFrame.class.getClassLoader().getResource("images/" + filename);
            return new ImageIcon(url);
        }     /**
         * Locates the given component on the screen's center.
         */
        protected void locateOnScreen(Component component) {
            Dimension paneSize = component.getSize();
            Dimension screenSize = component.getToolkit().getScreenSize();
            component.setLocation(
                (screenSize.width  - paneSize.width)  / 2,
                0);//
                //(screenSize.height - paneSize.height) / 2);
       }
        private ActionListener createNewFileActionListener() {
    //      加触发程序
         return new ActionListener() {
             public void actionPerformed(ActionEvent e) {
           
         MainFrame.this.buildContentPane();
             
        
             }
     
           
       };
        }
     
        protected ActionListener createHelpActionListener() {
            return null;
        }     /**
         * Creates and answers an ActionListener that opens the about dialog.
         */
        protected ActionListener createAboutActionListener() {
            return new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(
                     MainFrame.this,
                        "The simple Looks Demo Application\n"
                            + "\n\u00a9 2001-2004 JGoodies Karsten Lentzsch. All Rights Reserved.\n\n");
                    
             BPELDocument  m2c = new BPELDocument();
             try 
             {
             m2c.write(m2c.createDocument());
             }
             catch (IOException e333) 
             {
             // TODO Auto-generated catch block
             e333.printStackTrace();
             }
                }
            };
        }     private static class RolloverCheckButton extends JButton {         private boolean checked = false;         public void paint(Graphics g) {
                if (!checked) {
                    checkAndSetResult();
                }
                super.paint(g);
            }         private void checkAndSetResult() {
                Icon passedIcon = readImageIcon("passed.gif");
                Icon failedIcon = readImageIcon("failed.gif");             boolean passed = allButtonBordersAreUIResources();
                setIcon(passed ? passedIcon : failedIcon);
                setText(passed ? "Can Swap L&F" : "Can't Swap L&F");             checked = true;
            }         /**
             * Checks and answers whether all button borders implement UIResource.
             */
            private boolean allButtonBordersAreUIResources() {
                JToolBar bar = (JToolBar) getParent();
                for (int i = bar.getComponentCount() - 1; i >= 0; i--) {
                    Component child = bar.getComponent(i);
                    if (child instanceof JButton) {
                        Border b = ((JButton) child).getBorder();
                        if (!(b instanceof UIResource))
                            return false;
                    }
                }
                return true;
            }     } public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub



    }
      

  2.   

    package com.zwb.wsc.frames;import java.awt.*;
    ///////////////////////////////
    import com.zwb.wsc.gragh.GraghView;public class MainFrame  extends JApplet implements ActionListener
    {
       protected static final Dimension PREFERRED_SIZE =
            LookUtils.IS_LOW_RESOLUTION ? new Dimension(1024, 748) : new Dimension(1024, 748);     /** Describes optional settings of the JGoodies Looks */
        private final Settings settings;     /**
         * Constructs a <code>DemoFrame</code>, configures the UI, 
         * and builds the content.
         */
        public MainFrame(Settings settings) {
            this.settings = settings;
            configureUI();
            build();
            //setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        }
        
        public MainFrame ()
        {
        
         this.settings = createSettings();
         this.configureUI();
            this.build();
         this.setSize(PREFERRED_SIZE);
         this.locateOnScreen(this);
            this.setVisible(true);
            this.setSize(800,600);
        }
        
        public static void main(String[] args) {
         MainFrame instance = new MainFrame(createSettings());
            instance.setSize(PREFERRED_SIZE);
            
            instance.locateOnScreen(instance);
            instance.setVisible(true);
        }
        
        private static Settings createSettings() {
            Settings settings = Settings.createDefault();
            //settings.setUseSystemFonts(Boolean.TRUE);
            //PlasticTheme dd;
            //settings.setse.setSelectedTheme();
            // Configure the settings here.
            
            return settings;
        }
             /**
         * Configures the user interface; requests Swing settings and 
         * jGoodies Looks options from the launcher.
         */
        private void configureUI() {
            Options.setDefaultIconSize(new Dimension(18, 18));         // Set font options
            UIManager.put(
                Options.USE_SYSTEM_FONTS_APP_KEY,
                settings.isUseSystemFonts());
            Options.setGlobalFontSizeHints(settings.getFontSizeHints());
            Options.setUseNarrowButtons(settings.isUseNarrowButtons());
            
            // Global options
            Options.setTabIconsEnabled(settings.isTabIconsEnabled());
            UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, 
                    settings.isPopupDropShadowEnabled());         // Swing Settings
            LookAndFeel selectedLaf = settings.getSelectedLookAndFeel();
            if (selectedLaf instanceof PlasticLookAndFeel) {
                PlasticLookAndFeel.setMyCurrentTheme(settings.getSelectedTheme());
                PlasticLookAndFeel.setTabStyle(settings.getPlasticTabStyle());
                PlasticLookAndFeel.setHighContrastFocusColorsEnabled(
                    settings.isPlasticHighContrastFocusEnabled());
            } else if (selectedLaf.getClass() == MetalLookAndFeel.class) {
                MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
            }
            
            // Work around caching in MetalRadioButtonUI
            JRadioButton radio = new JRadioButton();
            radio.getUI().uninstallUI(radio);
            JCheckBox checkBox = new JCheckBox();
            checkBox.getUI().uninstallUI(checkBox);         try {
                UIManager.setLookAndFeel(selectedLaf);
            } catch (Exception e) {
                System.out.println("Can't change L&F: " + e);
            }     }     /**
         * Builds the <code>DemoFrame</code> using Options from the Launcher.
         */      private void build() {
      ////////////////
        
            setContentPane(buildContentPane());
           // setTitle(getWindowTitle());
            setJMenuBar(
                createMenuBuilder().buildMenuBar(
                    settings,
       /////////////////////////////////////
                    createNewFileActionListener(),
                    createsaveActionListener(),
      //////////////////////////////////////////
                    createHelpActionListener(),
                    createsaveActionListener())
                    );
          //  setIconImage(readImageIcon("eye_16x16.gif").getImage());
        }
        
        
       

    /** 
         * Creates and returns a builder that builds the menu.
         * This method is overriden by the full JGoodies Looks Demo to use
         * a more sophisticated menu builder that uses the JGoodies
         * UI Framework.
         * 
         * @return the builder that builds the menu bar
         */
        protected MenuBuilder createMenuBuilder() {
            return new MenuBuilder();
        }     /**
         * Builds and answers the content.
         */
        protected JComponent buildContentPane() {
          JPanel panel = new JPanel(new BorderLayout());
        
         panel.add(buildToolBar(), BorderLayout.NORTH);
          
            ContentPanel a= new ContentPanel();
            panel.add(a.build());       
         
            return panel;
        }
    // Tool Bar *************************************************************     /**
         * Builds, configures and returns the toolbar. Requests
         * HeaderStyle, look-specific BorderStyles, and Plastic 3D Hint 
         * from Launcher.
         */
        private Component buildToolBar() {
            JToolBar toolBar = new JToolBar();
            toolBar.setFloatable(false);
            toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
            // Swing
            toolBar.putClientProperty(
                Options.HEADER_STYLE_KEY,
                settings.getToolBarHeaderStyle());
            toolBar.putClientProperty(
                PlasticLookAndFeel.BORDER_STYLE_KEY,
                settings.getToolBarPlasticBorderStyle());
            toolBar.putClientProperty(
                WindowsLookAndFeel.BORDER_STYLE_KEY,
                settings.getToolBarWindowsBorderStyle());
            toolBar.putClientProperty(
                PlasticLookAndFeel.IS_3D_KEY,
                settings.getToolBar3DHint());
      

  3.   

    AbstractButton button;         toolBar.add(createToolBarButton("backward.gif"));
            button = createToolBarButton("forward.gif");
            button.setEnabled(false);
            toolBar.add(button);
            toolBar.add(createToolBarButton("home.gif"));
            toolBar.addSeparator();
            toolBar.add(createOpenButton());
            toolBar.add(createToolBarButton("print.gif"));
            toolBar.add(createToolBarButton("refresh.gif"));
            toolBar.addSeparator();         ButtonGroup group = new ButtonGroup();
            button = createToolBarRadioButton("pie_mode.png");
            button.setSelectedIcon(readImageIcon("pie_mode_selected.gif"));
            group.add(button);
            button.setSelected(true);
            toolBar.add(button);         button = createToolBarRadioButton("bar_mode.png");
            button.setSelectedIcon(readImageIcon("bar_mode_selected.gif"));
            group.add(button);
            toolBar.add(button);         button = createToolBarRadioButton("table_mode.png");
            button.setSelectedIcon(readImageIcon("table_mode_selected.gif"));
            group.add(button);
            toolBar.add(button);
            toolBar.addSeparator();         button = createToolBarButton("help.gif");
            button.addActionListener(createHelpActionListener());
        
            toolBar.add(button);         toolBar.add(Box.createGlue());         button = new RolloverCheckButton();
            button.setToolTipText("Shall show border when mouse is over");
            button.setMargin(new Insets(0, 0, 0, 0));
            toolBar.add(button);
            return toolBar;
        }
                
    ////////////////////////
        /**
         * Creates and returns a <code>JButton</code> 
         * configured for use in a JToolBar.<p>
         * 
         * This is a simplified method that is overriden by the Looks Demo.
         * The full code uses the JGoodies UI framework's ToolBarButton
         * that better handles platform differences.
         */
        protected AbstractButton createToolBarButton(String iconName) {
            JButton button = new JButton(readImageIcon(iconName));
            button.setFocusable(false);
            return button;
        }     /**
         * Creates and returns a <code>JToggleButton</code> 
         * configured for use in a JToolBar.<p>
         * 
         * This is a simplified method that is overriden by the Looks Demo.
         * The full code uses the JGoodies UI framework's ToolBarButton
         * that better handles platform differences.
         */
        protected AbstractButton createToolBarRadioButton(String iconName) {
            JToggleButton button = new JToggleButton(readImageIcon(iconName));
            button.setFocusable(false);
            return button;
        }     // Tabbed Pane **********************************************************
     
        protected String getWindowTitle() {
            return "WSCModeler";
        }
             // Helper Code **********************************************************************     /*
         * Looks up and answers an icon for the specified filename suffix.<p>
         */
        protected static ImageIcon readImageIcon(String filename) {
            URL url =
             MainFrame.class.getClassLoader().getResource("images/" + filename);
            return new ImageIcon(url);
        }     /**
         * Locates the given component on the screen's center.
         */
        protected void locateOnScreen(Component component) {
            Dimension paneSize = component.getSize();
            Dimension screenSize = component.getToolkit().getScreenSize();
            component.setLocation(
                (screenSize.width  - paneSize.width)  / 2,
                0);//
                //(screenSize.height - paneSize.height) / 2);
       }
        private ActionListener createNewFileActionListener() {
    //      加触发程序
         return new ActionListener() {
             public void actionPerformed(ActionEvent e) {
           
         MainFrame.this.buildContentPane();
             
        
             }
     
           
       };
        }
     
        protected ActionListener createHelpActionListener() {
            return null;
        }     /**
         * Creates and answers an ActionListener that opens the about dialog.
         */
        protected ActionListener createAboutActionListener() {
            return new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(
                     MainFrame.this,
                        "The simple Looks Demo Application\n"
                            + "\n\u00a9 2001-2004 JGoodies Karsten Lentzsch. All Rights Reserved.\n\n");
                    
             BPELDocument  m2c = new BPELDocument();
             try 
             {
             m2c.write(m2c.createDocument());
             }
             catch (IOException e333) 
             {
             // TODO Auto-generated catch block
             e333.printStackTrace();
             }
                }
            };
        }     private static class RolloverCheckButton extends JButton {         private boolean checked = false;         public void paint(Graphics g) {
                if (!checked) {
                    checkAndSetResult();
                }
                super.paint(g);
            }         private void checkAndSetResult() {
                Icon passedIcon = readImageIcon("passed.gif");
                Icon failedIcon = readImageIcon("failed.gif");             boolean passed = allButtonBordersAreUIResources();
                setIcon(passed ? passedIcon : failedIcon);
                setText(passed ? "Can Swap L&F" : "Can't Swap L&F");             checked = true;
            }         /**
             * Checks and answers whether all button borders implement UIResource.
             */
            private boolean allButtonBordersAreUIResources() {
                JToolBar bar = (JToolBar) getParent();
                for (int i = bar.getComponentCount() - 1; i >= 0; i--) {
                    Component child = bar.getComponent(i);
                    if (child instanceof JButton) {
                        Border b = ((JButton) child).getBorder();
                        if (!(b instanceof UIResource))
                            return false;
                    }
                }
                return true;
            }     } public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub



    }
    以上两个是整个mainFrame类