这几句代码看不出问题
把窗体放到屏幕中央
this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);

解决方案 »

  1.   

    //这是一段简化后的完整代码,刚才运行试过了也是相同的毛病import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;////////////////////////////////////////////////////SerbiApp Class
    public class SerbinApp extends JFrame
        implements ActionListener
    {
      JPanel contentPanel=new JPanel();  JMenuBar menuBar=new JMenuBar();
      JMenu fileMenu=new JMenu("文件");        
      JMenuItem startMenuItem=new JMenuItem("开始"); 
      
      Canvas cans;  public static void main(String[] args)
      {
        new SerbinApp();
      }
      public SerbinApp()
      {
        super("SerbinApp --W.J.W--");
        addWindowListener(new WindowAdapter()
                          {public void windowCloseing(WindowEvent e){System.exit(0);}}
                          );
        //////////////////////////////////////////////////
        setJMenuBar(menuBar);
        setContentPane(contentPanel);
        contentPanel.setLayout(new BorderLayout());
        menuBar.add(fileMenu);
        fileMenu.add(startMenuItem);
        startMenuItem.addActionListener(this);     
        
        ////////////////////////////////////////////////    
        cans=new Canvas();
        cans.setSize(400,300);
        contentPanel.add(cans,BorderLayout.SOUTH);  
       
        pack();
        setResizable(false);
        setLocation(400,600);
        show();
      }
      public void actionPerformed(ActionEvent e)
      {
        if (e.getSource()==startMenuItem)
        {
          cans.repaint();
          System.out.println("startMenuItem clicked.") ;
        }
      }
    }
      

  2.   

    主要是
    cans.setSize(400,300);和pack();
    这两句
    把它们去掉,然后加上this.setSize(400,300);
    效果就出来了
    很明显的
    那两句使得JFrame被Canvas覆盖了
      

  3.   

    该了以后可以。
    但若是那样的话,canvas大小就变了,我想让它固定在(400,300)上,因为要在上面精确作图啊
      

  4.   

    哦,去掉cans.setSize(400,300);和pack();这两句,还是不行,那样的话,canvas没有设定大小,就在屏幕上不显示,菜单当然就出来了。