⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jscrollbardemo.java

📁 本压缩文件中含有线程的控制
💻 JAVA
字号:
package gui;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class JScrollBarDemo extends JFrame implements ActionListener{
    public static final int WIDTH = 600;
    public static final int HEIGHT = 300;
    public static final int LINES = 8;
    public static final int CHAR_PER_LINE = 32;

    private JTextArea theText;
    private String memo1 = "No Memo 1.";
    private String memo2 = "No Memo 2.";

    public JScrollBarDemo(String str ){
		super(str);
		setSize(WIDTH, HEIGHT);
		setLocation(400, 200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(Color.WHITE);
		buttonPanel.setLayout(new FlowLayout());

		JButton memo1Button = new JButton("Save memo 1");
		JButton memo2Button = new JButton("Save memo 2");
		JButton clear = new JButton("Clear");
		JButton get1Button = new JButton("Get memo 1");
		JButton get2Button = new JButton("Get memo 2");

		memo1Button.addActionListener(this);
		memo2Button.addActionListener(this);
		clear.addActionListener(this);
		get1Button.addActionListener(this);
		get2Button.addActionListener(this);

		buttonPanel.add(memo1Button);
		buttonPanel.add(memo2Button);
		buttonPanel.add(clear);
		buttonPanel.add(get1Button);
		buttonPanel.add(get2Button);

		JPanel textPanel = new JPanel();

		textPanel.setBackground(Color.LIGHT_GRAY);

		theText = new JTextArea(LINES, CHAR_PER_LINE);
		JScrollPane scrolledText = new JScrollPane(theText);
		theText.setFont(new Font("Arial", Font.BOLD, 20));
		theText.setBackground(Color.WHITE);
		scrolledText.setHorizontalScrollBarPolicy(
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrolledText.setVerticalScrollBarPolicy(
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		textPanel.add(scrolledText);

		contentPane.add(textPanel, BorderLayout.CENTER);
		contentPane.add(buttonPanel, BorderLayout.SOUTH);

		buttonPanel.add(memo1Button);
		buttonPanel.add(memo2Button);

	}

    public void actionPerformed(ActionEvent e){
        String actionCommand = e.getActionCommand( );
        if (actionCommand.equals("Save memo 1"))
            memo1 = theText.getText( );
        else if (actionCommand.equals("Save memo 2"))
            memo2 = theText.getText( );
        else if (actionCommand.equals("Clear"))
            theText.setText("");
        else if (actionCommand.equals("Get memo 1"))
            theText.setText(memo1);
        else if (actionCommand.equals("Get memo 2"))
            theText.setText(memo2);
        else
            theText.setText("Error in memo interface");
    }

    public static void main(String[] args){
        JScrollBarDemo guiMemo = new JScrollBarDemo("Scrolling memo Savor");
        guiMemo.setVisible(true);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -