日期:2014-05-20  浏览次数:20840 次

谁能帮我把这个程序中的滚动条加进去??
[code=Java][/code]
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Administrator
 */
public class WordAnalsys extends JFrame{
  private JLabel lab1=new JLabel();
  private JButton btnOpen=new JButton("打开");
  private JButton btnSave=new JButton("另存为");
  private JTextArea ja1=new JTextArea(20,40);
  private JTextArea ja2=new JTextArea(20,40);
  private JButton btnClean=new JButton("重置");
  private JButton btnAnalysis=new JButton("重置");

  public WordAnalsys(){
  super("Test");
  Container c=this.getContentPane();
   
  JPanel pan1=new JPanel();//放按钮
  pan1.setLayout(new FlowLayout(FlowLayout.LEFT));
  pan1.add(btnOpen);
  pan1.add(btnSave);
   
  ImageIcon img1= new ImageIcon("java.png");
  lab1.setIcon(img1);
  JPanel pan2=new JPanel();//放标签
  pan2.setLayout(new FlowLayout(FlowLayout.RIGHT));
  pan2.add(lab1);
   
  JPanel pan4=new JPanel();//放面板1和面板2
  pan4.setLayout(new BorderLayout());
  pan4.add(pan1,"West");
  pan4.add(pan2,"East");
  c.add(pan4,"North");

  JPanel pan5=new JPanel();//放置JTextArea
  pan5.setLayout(null);
  ja1.setBounds(8, 16, 402, 276);
  ja2.setBounds(416, 16, 202, 276);
  JScrollPane sp1=new JScrollPane(ja1);
  JScrollPane sp2=new JScrollPane(ja2);

  ja1.setBorder(BorderFactory.createTitledBorder("源代码框"));//createRaisedBevelBorder()); // 凸边框
  pan5.add(sp1);
  ja2.setBorder(BorderFactory.createTitledBorder("分析结果框"));
  pan5.add(sp2);
  c.add(pan5,"Center");
   
  JPanel pan6=new JPanel();
  pan6.setLayout(new FlowLayout());
  pan6.add(btnClean);
  pan6.add(btnAnalysis);
  c.add(pan6,"South");  
   
  }
  public static void main(String[] args) {
  WordAnalsys wa=new WordAnalsys();
  wa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  wa.setSize(630, 387);
  wa.setVisible(true);
  wa.setLocation(300, 100);
  }

}


本人想这样写,其他的不改,把滚动条加进去就给20分。。。

------解决方案--------------------
Java code

package test;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Administrator
 */
public class Test extends JFrame{
      private JLabel lab1=new JLabel();
      private JButton btnOpen=new JButton("打开");
      private JButton btnSave=new JButton("另存为");
      private JTextArea ja1=new JTextArea(20,40);
      private JTextArea ja2=new JTextArea(20,40);
      private JButton btnClean=new JButton("重置");
      private JButton btnAnalysis=new JButton("重置");

      public Test(){
          super("Test");
          Container c=this.getContentPane();
        
          JPanel pan1=new JPanel();//放按钮
          pan1.setLayout(new FlowLayout(FlowLayout.LEFT));
          pan1.add(btnOpen);
          pan1.add(btnSave);
        
          ImageIcon img1= new ImageIcon("java.png");
          lab1.setIcon(img1);
          JPanel pan2=new JPanel();//放标签
          pan2.setLayout(new FlowLayout(FlowLayout.RIGHT));
          pan2.add(lab1);
        
          JPanel pan4=new JPanel();//放面板1和面板2
          pan4.setLayout(new BorderLayout());
          pan4.add(pan1,"West");
          pan4.add(pan2,"East");
          c.add(pan4,"North");
    
          JPanel pan5=new JPanel();//放置JTextArea
          pan5.setLayout(null);
//          ja1.setBounds(8, 16, 402, 276);
//          ja2.setBounds(416, 16, 202, 276);
          
    
          ja1.setBorder(BorderFactory.createTitledBorder("源代码框"));//createRaisedBevelBorder()); // 凸边框
          
          ja2.setBorder(BorderFactory.createTitledBorder("分析结果框"));
          JScrollPane sp1=new JScrollPane(ja1);
          JScrollPane sp2=new JScrollPane(ja2);

          sp1.setBounds(8, 16, 402, 276);
          sp2.setBounds(416, 16, 202, 276);
          
          pan5.add(sp1);
          pan5.add(sp2);
          c.add(pan5,BorderLayout.CENTER);
        
          JPanel pan6=new JPanel();
          pan6.setLayout(new FlowLayout());
          pan6.add(btnClean);
          pan6.add(btnAnalysis);
          c.add(pan6,"South");   
    
      }
      public static void main(String[] args) {
          Test wa=new Test();
          wa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          wa.setSize(630, 387);
          wa.setVisible(true);
          wa.setLocation(300, 100);
      }

}