package lesson5;
import javax.swing.*;
import java.awt.*;
public class JPanelDemo extends JFrame {
public JPanelDemo() throws HeadlessException {
Container container=this.getContentPane();
container.setLayout(new GridLayout(2,1,10,10));
JPanel panel1 =new JPanel(new GridLayout(1,3));
panel1.add(new JButton("1"));
panel1.add(new JButton("1"));
panel1.add(new JButton("1"));
container.add(panel1);
this.setVisible(true);
this.setSize(500,500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JPanelDemo();
}
}

package lesson5;
import javax.swing.*;
import java.awt.*;
public class JScrollDemo extends JFrame {
public JScrollDemo() throws HeadlessException {
Container container=this.getContentPane();
//文本域
JTextArea textArea = new JTextArea(20, 50);
textArea.setText("我要提高自己的能力");
//Scroll面板
JScrollPane scrollPane=new JScrollPane(textArea);
container.add(scrollPane);
this.setVisible(true);
this.setBounds(100,100,300,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JScrollDemo();
}
}
