容器分两类:
panel
默认布局是FlowLayoutwindow
默认布局是BorderLayout而applet继承的是panel,所以默认布局是FlowLayout,如果要用BorderLayout需要使用
container.setLayout(new BorderLayout(5, 10));Frame继承的是window,所以默认布局是BorderLayout,可以不用显示指定这和apllet或者application是无关的,看你用什么容器了。

解决方案 »

  1.   

    好像不是这样,书上说apllet默认是BorderLayout,也就是说applet的程序是不用new Borderlayout()
    ,而application的需要定义new BorderLayout(),我这段代码就是想说application的程序书上是要
    定义的!跟你说的正好相反!
      

  2.   

    你查一下你所用jdk版本带的帮助文档吧上面说的肯定是权威了
      

  3.   

    public void init()
      {
        // Set properties on the text fields
        jtfMonthlyPayment.setEditable(false);
        jtfTotalPayment.setEditable(false);    // Right align text fields
        jtfAnnualInterestRate.setHorizontalAlignment(JTextField.RIGHT);
        jtfNumOfYears.setHorizontalAlignment(JTextField.RIGHT);
        jtfLoanAmount.setHorizontalAlignment(JTextField.RIGHT);
        jtfMonthlyPayment.setHorizontalAlignment(JTextField.RIGHT);
        jtfTotalPayment.setHorizontalAlignment(JTextField.RIGHT);    // Panel p1 to hold labels and text fields
        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(5, 2));
        p1.add(new Label("Annual Interest Rate"));
        p1.add(jtfAnnualInterestRate);
        p1.add(new Label("Number of Years"));
        p1.add(jtfNumOfYears);
        p1.add(new Label("Loan Amount"));
        p1.add(jtfLoanAmount);
        p1.add(new Label("Monthly Payment"));
        p1.add(jtfMonthlyPayment);
        p1.add(new Label("Total Payment"));
        p1.add(jtfTotalPayment);
        p1.setBorder(new
          TitledBorder("Enter interest rate, year and loan amount"));    // Panel p2 to hold the button
        JPanel p2 = new JPanel();
        p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
        p2.add(jbtComputeMortgage);    // Add the components to the applet
        getContentPane().add(p1, BorderLayout.CENTER);
        getContentPane().add(p2, BorderLayout.SOUTH);    // Register listener
        jbtComputeMortgage.addActionListener(this);
      }
    这是书上的init()里的全部代码,你可以看看,它也没有getContentPane().setLayout(new BorderLayout()),我运行过是可以的!
    那它的也应该不会错!
      

  4.   

    The default contentPane() will have a BorderLayout manager set on it也就是说getContentPane()得到的容器默认采用borderlayout
    这是swing的东东,和awt不一样