• java 文本窗口


    简介

    java 文本窗口

    code

    package calcu;
    
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;
    
    public class TextComponentFrame extends JFrame {
        public static final int TEXTAREA_ROWS = 8;
        public static final int TEXTAREA_COLUMNS = 20;
    
        public static void main(String[] args) {
            TextComponentFrame t = new TextComponentFrame();
            t.setTitle("ImageTest");
            t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            t.setVisible(true);
        }
    
        public TextComponentFrame() {
            JTextField textField = new JTextField();
            JPasswordField passwordField = new JPasswordField();
            JPanel northPanel = new JPanel();
            northPanel.setLayout(new GridLayout(2, 2));
            northPanel.add(new JLabel("User name:", SwingConstants.RIGHT));
            northPanel.add(textField);
            northPanel.add(new JLabel("Password: ", SwingConstants.RIGHT));
            northPanel.add(passwordField);
    
            add(northPanel, BorderLayout.NORTH);
    
            JTextArea textArea = new JTextArea(TEXTAREA_ROWS, TEXTAREA_COLUMNS);
            JScrollPane scrollPane = new JScrollPane(textArea);
            add(scrollPane, BorderLayout.CENTER);
            // add button to append text into the text area
            JPanel southPanel = new JPanel();
    
            JButton insertButton = new JButton("Insert");
            southPanel.add(insertButton);
            insertButton.addActionListener(event -> textArea.append(
                    "User name :" + textField.getText() + "Password: " + new String(passwordField.getPassword()) + "
    "));
            add(southPanel, BorderLayout.SOUTH);
            pack();
        }
    
    }
    
    

    Q&A

    滚动窗口应该是textArea的子类。

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    typescript接口初识
    TypeScript如何创建一个工程
    typescript开发入门
    node.js下面创建一个express应用的几条命令【乱序版】
    一天入门typescript
    Node.js快速创建一个Express应用的几个步骤
    数据结构--栈
    数据结构--单链表
    数据结构--二叉树
    数据结构--树
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13924258.html
Copyright © 2020-2023  润新知