java组件及事件处理(5)---加入滚动面板
package First;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Five extends JFrame
{
JButton jb1;
JButton jb2;
JButton jb3;
JButton jb4;
JPanel jp1;
JPanel jp2;
JTextArea jta;
JScrollPane jsp;
public Five(String s)
{
super(s);
setLayout(new FlowLayout());
setBounds(400, 400, 400, 400);
Container conn = getContentPane();
conn.setBackground(Color.cyan);
jb1 = new JButton("PINK");
jb2 = new JButton("YELLOW");
jb3 = new JButton("BLUE");
jb4 = new JButton("RED");
jp1 = new JPanel();
jp2 = new JPanel();
jp1.setBackground(Color.blue);
jp2.setBackground(Color.black);
jp1.add(jb1);
jp1.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
add(jp1);
add(jp2);
jta = new JTextArea(5,10);
jsp = new JScrollPane(jta,jsp.VERTICAL_SCROLLBAR_ALWAYS,
jsp.HORIZONTAL_SCROLLBAR_ALWAYS);
add(jsp);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
Five a = new Five("滚动面板");
}
}