Introduction to the

Core technology of Gui: Swing AWT

Because the interface is not beautiful.

Jre environment required!

Why do we learn?

1. You can write some small tools you want in your heart. 2. 3. Understand the MVC architecture, understand listening!Copy the code

AWT

Components and containers

Frame

Class Newawttest {public static void main(String[] args) {// Create a Frame class Frame Frame = new Frame(" This is a test "); // Set window visible frame.setVisible(true); // Set window size frame.setSize(400,300); // Set the background Color frame.setBackground(new Color(203, 33, 33)); // set the initial location frame.setlocation (200,200); // the size is fixed frame.setrestage (false); }}Copy the code

import java.awt.*; public class MyawtText_2 { public static void main(String[] args) { Newawt newawt1 = new Newawt (100100200200, Color. BLUE); Newawt newawt2 = new Newawt (300100200200, Color. YELLOW); Newawt newawt3 = new Newawt (100300200200, Color. RED); Newawt newawt4 = new Newawt (300300200200, Color. PINK); } } class Newawt extends Frame { static int id = 0; Public Newawt(int x,int y,int w,int h,Color Color) {super(" window "+(++id)); setVisible(true); setBounds(x,y,w,h); setBackground(color); }}Copy the code

Panel is a Panel

import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class newawttest { public static void main(String[] args){ Frame frame=new Frame(); Panel panel=new Panel(); Panel panel2 = new Panel(); // Set the layout frame.setLayout(null); / / coordinate frame. The setBounds (300300500500); / / frame. SetBounds (0,0,0,0); Frame. SetBackground (new Color (40161, 35)); ,0,200,200 panel2. SetBounds (0); panel2.setBackground(new Color(255, 241, 190)); frame.add(panel2); //paneL sets the coordinates relative to frame panel.setbounds (0,0,300,300); The panel. SetBackground (new Color (193,15,60)); //frame.add(panel) ; frame.add(panel); // Window visualization frame.setVisible(true); // Adapter mode, Frame.addwindowlistener (new WindowAdapter() {@override public void windowClosing(WindowEvent e) { System.exit(0); }}); }}Copy the code

Layout manager

Fluid layout

import java.awt.*; public class newawttest { public static void main(String[] args) { Frame frame = new Frame(); // Button button1 = new Button("button1"); Button button2 = new Button("button2"); Button button3 = new Button("button3"); // Set the FlowLayout frame.setLayout(new FlowLayout()); // Center by default // frame.setLayout(new FlowLayout(flowLayout.left)); // frame.setLayout(new FlowLayout(FlowLayout.RIGHT)); // frame.setLayout(new FlowLayout(FlowLayout.LEADING)); // frame.setLayout(new FlowLayout(FlowLayout.TRAILING)); frame.add(button1); frame.add(button2); frame.add(button3); Frame. The setSize (400400); frame.setVisible(true); }}Copy the code

East, west, North, south

import java.awt.*; public class newawttest { public static void main(String[] args) { Frame frame = new Frame(); // Button west = new Button(" west "); Button East = new Button("East"); Button North = new Button("North"); Button South = new Button("South"); Button Center = new Button("Center"); frame.add(west,BorderLayout.WEST); frame.add(East,BorderLayout.EAST); frame.add(North,BorderLayout.NORTH); frame.add(South,BorderLayout.SOUTH); frame.add(Center,BorderLayout.CENTER); frame.setVisible(true); Frame. The setSize (400400); }}Copy the code

Table layout

import java.awt.*; public class newawttest { public static void main(String[] args) { Frame frame = new Frame(); // Button but1 = new Button("but1"); Button but2 = new Button("but2"); Button but3 = new Button("but3"); Button but4 = new Button("but4"); Button but5 = new Button("but5"); Button but6 = new Button("but6"); Frame. SetLayout (new GridLayout (2, 3)); frame.add(but1); frame.add(but2); frame.add(but3); frame.add(but4); frame.add(but5); frame.add(but6); frame.pack(); //Java syntax, automatically distribute size frame.setvisible (true); }}Copy the code

exercises

import java.awt.*; public class newawttest { public static void main(String[] args) { Frame frame = new Frame(); frame.setVisible(true); Frame. The setBounds (400300300300); // frame.pack(); frame.setBackground(Color.BLUE); frame.setLayout(new GridLayout(2, 1)); // Panel panel1 = new Panel(new GridLayout(2,1)); Panel panel2 = new Panel(new GridLayout(2,2)); Panel panel3 = new Panel(new BorderLayout()); Panel panel4 = new Panel(new BorderLayout()); / / panel3. Add (new Button (" East - 1 "), BorderLayout. East); panel3.add(new Button("West-1"),BorderLayout.WEST); panel1.add(new Button("top")); panel1.add(new Button("down")); panel3.add(panel1,BorderLayout.CENTER); / / the panel4. Add (new Button (" East - 2 "), BorderLayout. East); panel4.add(new Button("West-2"),BorderLayout.WEST); panel2.add(new Button("top-1")); panel2.add(new Button("top-1")); panel2.add(new Button("down-1")); panel2.add(new Button("down-2")); panel4.add(panel2,BorderLayout.CENTER); frame.add(panel3); frame.add(panel4); }}Copy the code

Event listeners

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.EventListener; Public Class NewawTtest {public static void main(String[] args) {// Press the button and trigger some events Frame Frame = new Frame(); Button button = new Button("button"); // Since addActionListener() requires an ActionListener, you need to construct an ActionListener. MyActionListener myActionListener = new MyActionListener(); button.addActionListener(myActionListener); frame.add(button,BorderLayout.CENTER); frame.pack(); frame.setVisible(true); ExitWindows(frame); } private static void ExitWindows(Frame frame){ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); } } class MyActionListener implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { System.out.println("Hello,World!" ); }}Copy the code

Multiple buttons share an event

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; Public Class NewawTtest {public static void main(String[] args) {// Press the button and trigger some events Frame Frame = new Frame(" start - Stop "); Button button1 = new Button("start"); Button button2 = new Button("stop"); // The definition that can be displayed triggers the command that will be returned. If the definition is not displayed, the default value will be used. / / can only write a multiple button. Listen in the class for the addActionListener (new MyAction ()); button2.addActionListener(new MyAction()); button2.setActionCommand("This is stop!" ); frame.add(button1,BorderLayout.NORTH); frame.add(button2,BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); ExitWindows(frame); } private static void ExitWindows(Frame frame){ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); Class MyAction implements ActionListener{@override public void actionPerformed(ActionEvent e) { System. The out. Println (" output: MSG = > "+ um participant etActionCommand ()); // Get button info}}Copy the code

Input TextField listens

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; Public class TextFieldaaa {public static void main(String[] args) {// Start new MyFrame(); new newawttest().ExitWindows(new MyFrame()); } } class MyFrame extends Frame{ public MyFrame(){ TextField textField = new TextField(); add(textField); MyAction2 MyAction2 = new MyAction2(); / / press Enter will trigger input box event textField. AddActionListener (myAction2); textField.setEchoChar('*'); // Set the replacement encoding pack(); setVisible(true); } } class MyAction2 implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { TextField field = (TextField) e.getSource(); // Get some resources and return an object system.out.println (field.gettext ()); // Get the input field text field.settext (""); }}Copy the code

Easy calculator, composition and inner classes

// Import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TextCalc { public static void main(String[] args) { new CalcLater(); }} class CalcLater extends Frame {public CalcLater(){TextField field1 = new TextField(10); TextField field2 = new TextField(10); TextField field3 = new TextField(20); Button Button = new Button("="); button.addActionListener(new MyCalcLaterListener(field1,field2,field3)); Label = new Label("+"); // Layout setLayout(new FlowLayout()); add(field1); add(label); add(field2); add(button); add(field3); setVisible(true); pack(); // ExitWindows(new CalcLater()); } public static void ExitWindows(Frame frame){ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); } } class MyCalcLaterListener implements ActionListener { private TextField num1,num2,num3; public MyCalcLaterListener(TextField num1, TextField num2, TextField num3) { this.num1 = num1; this.num2 = num2; this.num3 = num3; } @override public void actionPerformed(ActionEvent e) {int n1 = integer.parseInt (num1.gettext ()); int n2 = Integer.parseInt(num2.getText()); Num3. setText(""+(n1+n2)); // empty the first two numbers num1.settext (""); num2.setText(""); }}Copy the code
// Import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TextCalc { public static void main(String[] args) { new CalcLater().LoadFrame(); } } class CalcLater extends Frame { TextField num1,num2,num3; Button button; Label label; Public void LoadFrame(){num1 = new TextField(10); num2 = new TextField(10); num3 = new TextField(20); // A button = new button ("="); button.addActionListener(new MyCalcLaterListener(this)); // A label = new label ("+"); // Layout setLayout(new FlowLayout()); add(num1); add(label); add(num2); add(button); add(num3); setVisible(true); pack(); this.ExitWindows(this); } public void ExitWindows(Frame frame){ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); Class MyCalcLaterListener implements ActionListener {CalcLater CalcLater = null; public MyCalcLaterListener(CalcLater calcLater) { this.calcLater = calcLater; } @override public void actionPerformed(ActionEvent e) {int n1 = integer.parseInt (calupdater.num1.gettext ());} @override public void actionPerformed(ActionEvent e) { int n2 = Integer.parseInt(calcLater.num2.getText()); // place the result in the third box calcler.num3. setText(""+(n1+n2)); // Empty the first two numbers calcler.num1.settext (""); calcLater.num2.setText(""); }}Copy the code

The biggest benefit of an inner class is unimpeded access to the properties and methods of the outer class

Internal class ↓

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class CalcLater extends Frame { public static void main(String[] args) { new CalcLater().LoadFrame(); } TextField num1,num2,num3; Button button; Label label; Public void LoadFrame(){num1 = new TextField(10); num2 = new TextField(10); num3 = new TextField(20); // A button = new button ("="); button.addActionListener(new MyCalcLaterListener()); // A label = new label ("+"); // Layout setLayout(new FlowLayout()); add(num1); add(label); add(num2); add(button); add(num3); setVisible(true); pack(); this.ExitWindows(this); } private class MyCalcLaterListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { Int n1 = integer.parseint (num1.gettext ()); int n2 = Integer.parseInt(num2.getText()); Num3. setText(""+(n1+n2)); // empty the first two numbers num1.settext (""); num2.setText(""); } } public void ExitWindows(Frame frame){ frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); }}Copy the code

The brush

import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TestMyPrints { public static void main(String[] args) { new MyPrints().LoadFrame(); } } class MyPrints extends Frame{ public void LoadFrame(){ setVisible(true); SetBounds (200200600500); } @Override public void paint(Graphics g) { //super.paint(g); // set the brush Color g.setColor(color.cyan); // fill a solid circle g.filval (100,100,100,100); // Return to the original Color g.setcolor (color.black); }}Copy the code

The mouse to monitor

// Import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.util.Iterator; Public class MorseListenerTest {public static void main(String[] args) {new MyFrame(); }} class MyFrame extends Frame{ArrayList points; public MyFrame(String title){ super(title); SetBounds (200200600400); setVisible(true); // Store mouse points = new ArrayList(); This.addmouselistener (new MyListener()); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); }}); } public void addPoint(Point Point){points.add(Point); Iterator = points.iterator(); Iterator = points.iterator(); Iterator = points.iterator(); while (iterator.hasNext()){ Point point = (Point) iterator.next(); g.setColor(Color.BLUE); G.f illOval (point x, point y, 10, 10); }} private class MyListener extends MouseAdapter{public void mousePressed(MouseEvent e) { MyFrame myFrame = (MyFrame)e.getSource(); Myframe.addpoint (new Point(LLDB etX(), LLDB etY()))); // Myframe.repaint () needs to be redrawn every time you click the mouse; }}}Copy the code

Window to monitor

import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TestWindows { public static void main(String[] args) { new MyFrame(); } } class MyFrame extends Frame{ public MyFrame(){ setVisible(true); setBackground(Color.CYAN); SetBounds (200200400400); } private class myWindowListEnter extends WindowAdapter @override public void windowClosing(WindowEvent e) { super.windowClosing(e); } @override public void windowActivated(WindowEvent e) {super.windowactivated (e); }}}Copy the code

Keyboard monitor

import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class TestKeyListener { public static void main(String[] args) { new KeyFrame(); } } class KeyFrame extends Frame{ public KeyFrame(){ setBackground(Color.blue); SetBounds (100100200400); setVisible(true); This.addkeylistener (new KeyAdapter() {@override public void keyPressed(KeyEvent e) {// Get the input key code System.out.println(e.getKeyCode()); }}); }}Copy the code

Swing

Window, panel

import javax.swing.*; import java.awt.*; public class JFrameDemo { //init(); Public void init(){JFrame JFrame = new JFrame(" this is a JFrame window "); jFrame.setVisible(true); JFrame. SetBounds (100100200200); Container contentPane = jFrame.getContentPane(); // Get a Container contentPane; contentPane.setBackground(Color.YELLOW); JLabel JLabel = new JLabel(" Welcome to stupid window interface "); / / set the text centered jLabel. SetHorizontalAlignment (SwingConstants. CENTER); jFrame.add(jLabel); / / close event jFrame. SetDefaultCloseOperation (WindowConstants. EXIT_ON_CLOSE); } public static void main(String[] args) {// Create a window new JFrameDemo().init(); }}Copy the code

Popup window

import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class DialogDemo extends JFrame { public DialogDemo(){ this.setVisible(true); Enclosing setBounds (100100700500); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); // Container contentPane = this.getContentPane(); // Absolute layout contentpane.setLayout (null); contentPane.setBackground(Color.lightGray); // button JButton button = new JButton(" this is a button "); Button. The setBounds (30,30,100,100); button.setBackground(Color.BLUE); Button.addactionlistener (new ActionListener() {@override public void actionPerformed(ActionEvent e) { // popover new MyDiolog(); }}); contentPane.add(button); } public static void main(String[] args) { new DialogDemo(); } } class MyDiolog extends JDialog{ public MyDiolog() { this.setVisible(true); Enclosing setBounds (100100300300); // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container Container = this.getContentPane(); container.setLayout(null); JLabel label = new JLabel(" this is a popover "); Label. SetBounds (10,10,400,400); container.add(label); }}Copy the code

The label

package com.Miotsuki.SwingTest; import javax.swing.*; import java.awt.*; import java.net.URL; Public class ImageIconDemo extends JFrame {public ImageIconDemo () {/ / get photo address JLabel label = new JLabel (" "); URL the URL = ImageIconDemo. Class. GetResource (" cake. PNG"); ImageIcon imageIcon = new ImageIcon(url); label.setIcon(imageIcon); label.setHorizontalAlignment(SwingConstants.CENTER); Container container = this.getContentPane(); container.setBackground(new Color(196, 183, 255)); container.add(label); this.setVisible(true); Enclosing setBounds (100100500500); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new ImageIconDemo(); }}Copy the code

panel

import javax.swing.*; import java.awt.*; public class JPanelDemo2 extends JFrame { public JPanelDemo2() { Container container = this.getContentPane(); container.setLayout(new GridLayout(2, 1, 10, 10)); JPanel panel1 = new JPanel(New GridLayout(1, 3)); JPanel panel2 = new JPanel(new GridLayout(1, 2)); JPanel panel3 = new JPanel(new GridLayout(2, 1)); JPanel panel4 = new JPanel(new GridLayout(3, 2)); panel1.add(new JButton("1")); panel1.add(new JButton("1")); panel1.add(new JButton("1")); panel2.add(new JButton("2")); panel2.add(new JButton("2")); panel3.add(new JButton("3")); panel3.add(new JButton("3")); panel4.add(new JButton("4")); panel4.add(new JButton("4")); panel4.add(new JButton("4")); panel4.add(new JButton("4")); panel4.add(new JButton("4")); panel4.add(new JButton("4")); container.add(panel1); container.add(panel2); container.add(panel3); container.add(panel4); this.setVisible(true); Enclosing setSize (500500); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JPanelDemo2(); }}Copy the code

JScrollPanel

import javax.swing.*; import java.awt.*; public class JScrollDemo extends JFrame { public JScrollDemo(){ Container contentPane = this.getContentPane(); // text field JTextArea textArea = new JTextArea(20, 20); Textarea.settext (" Welcome: "); //Scroll pane JScrollPane scrollPane = new JScrollPane(textArea); contentPane.add(scrollPane); this.setVisible(true); Enclosing setBounds (100100300400); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JScrollDemo(); }}Copy the code

button

Ordinary button

import javax.swing.*; import java.awt.*; import java.net.URL; Public class JButtonDemo1 extends JFrame {public JButtonDemo1(){Container Container = this.getContentPane(); / / get picture position resource URL = JButtonDemo1. The class. The getResource (" cake. PNG "); Icon icon = new ImageIcon(resource); JButton button = new JButton(); button.setIcon(icon); Button.settooltiptext (" It's a button, just press it "); container.add(button); SetBounds (100100500500); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JButtonDemo1(); }}Copy the code

The radio button

import javax.swing.*; import java.awt.*; import java.net.URL; Public class JButtonDemo2 extends JFrame {public JButtonDemo2(){Container Container = this.getContentPane(); / / get picture position resource URL = JButtonDemo1. The class. The getResource (" cake. PNG "); Icon icon = new ImageIcon(resource); JRadioButton button1 = new JRadioButton("JRadioButton1"); JRadioButton button2 = new JRadioButton("JRadioButton2"); JRadioButton button3 = new JRadioButton("JRadioButton3"); ButtonGroup group = new ButtonGroup(); group.add(button1); group.add(button2); group.add(button3); container.add(button1,BorderLayout.NORTH); container.add(button2,BorderLayout.CENTER); container.add(button3,BorderLayout.SOUTH); SetBounds (100100500500); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JButtonDemo2(); }}Copy the code

Check button

import javax.swing.*; import java.awt.*; import java.net.URL; Public class JButtonDemo3 extends JFrame {public JButtonDemo3(){Container Container = this.getContentPane(); / / get picture position resource URL = JButtonDemo1. The class. The getResource (" cake. PNG "); Icon icon = new ImageIcon(resource); JCheckBox checkBox1 = new JCheckBox("JCheckBox1"); JCheckBox checkBox2 = new JCheckBox("JCheckBox2"); container.add(checkBox1,BorderLayout.NORTH); container.add(checkBox2,BorderLayout.SOUTH); SetBounds (100100500500); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JButtonDemo3(); }}Copy the code

The list of

The drop-down menu

import javax.swing.*; import java.awt.*; Public Class ComboBosDemo01 extends JFrame{public ComboBosDemo01(){Container Container = this.getContentPane(); JComboBox comboBox = new JComboBox(); comboBox.addItem(null); Combobobox. AddItem (" Contact "); ComboBox. AddItem (" friends "); Combobobox. AddItem (" blacklist "); container.add(comboBox); // Visualization, window size, close event setVisible(true); SetBounds (100100500500); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new ComboBosDemo01(); }}Copy the code

List box

import javax.swing.*; import java.awt.*; import java.util.Vector; Public Class ComboBosDemo02 extends JFrame {public ComboBosDemo02(){Container Container = this.getContentPane(); // String[] contents = {"1","2","3"}; Vector contents = new Vector(); JList jlist = new JList(contents); contents.add("zhangsan"); contents.add("lisi"); contents.add("wangwu"); container.add(jlist); // Visualization, window size, close event setVisible(true); SetBounds (100100500500); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new ComboBosDemo02(); }}Copy the code

The text box

import javax.swing.*; import java.awt.*; Public Class TextTestDemo01 extends JFrame {public TextTestDemo01(){Container Container = this.getContentPane(); // textField JTextField textField = new JTextField("Hello",20); JTextField textField2 = new JTextField("World"); // passwordField JPasswordField passwordField = new JPasswordField(); container.add(textField,BorderLayout.NORTH); container.add(textField2,BorderLayout.SOUTH); container.add(passwordField,BorderLayout.CENTER); // Visualization, window size, close event setVisible(true); SetBounds (100100500500); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TextTestDemo01(); }}Copy the code

Text field

import javax.swing.*; import java.awt.*; public class JScrollDemo extends JFrame { public JScrollDemo(){ Container contentPane = this.getContentPane(); // text field JTextArea textArea = new JTextArea(20, 20); Textarea.settext (" Welcome: "); //Scroll pane JScrollPane scrollPane = new JScrollPane(textArea); contentPane.add(scrollPane); this.setVisible(true); Enclosing setBounds (100100300400); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JScrollDemo(); }} 1(){// Container Container = this.getContentPane(); // textField JTextField textField = new JTextField(" Hello ",20); Textfield textField2 = new JTextField(" World "); // passwordField JPasswordField passwordField = new JPasswordField(); container.add(textField,BorderLayout.NORTH); container.add(textField2,BorderLayout.SOUTH); container.add(passwordField,BorderLayout.CENTER); // Visualization, window size, close event setVisible(true); SetBounds (100100500500); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TextTestDemo01(); } 12 3 4 5 6 7 8 9 10 11 12 13} - text field ' 'Java import javax.swing.*; import java.awt.*; public class JScrollDemo extends JFrame { public JScrollDemo(){ Container contentPane = this.getContentPane(); // text field JTextArea textArea = new JTextArea(20, 20); Textarea.settext (" Welcome: "); //Scroll pane JScrollPane scrollPane = new JScrollPane(textArea); contentPane.add(scrollPane); this.setVisible(true); Enclosing setBounds (100100300400); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new JScrollDemo(); }}Copy the code

The last

At the end of the article the author sorted out a lot of information for you! Including Java core knowledge + a full set of architect learning materials and video + first-line factory interview treasure dictionary + resume template interview ali Meituannetease Tencent Xiaomi IQiyi Quick hand bilibili bilibili interview questions +Spring source code collection +Java architecture actual combat e-books and so on! Welcome to pay attention to the public number: the future has light, receive!