如何从Java类的JFrame中读取数据?

问题描述 投票:0回答:0

“Dashboard”JFrame 和“main”java 类上有“textarea”,需要将数据从dashboard textarea 读取到Java 类中并执行一些任务

1- 从文本区域(链接)获取数据。
2-默认浏览器打开它。
3-等待元素可点击并点击。
4- Thread.sleep with try & catch.
5- 等待元素可点击并(再次)点击。
6- 更快、更准确地同步和更新表格数据。

JTextArea textarea = new JTextArea();
        textarea.setBackground(Color.WHITE);
        textarea.setFont(new Font("SansSerif", Font.PLAIN, 12));
        textarea.setBounds(0, 0, 250, 284);
        textarea.setBorder(null);

        JScrollPane scrollPane = new JScrollPane(textarea);
        scrollPane.setBounds(44, 69, 250, 284);

        JScrollBar scrollBar = new JScrollBar(JScrollBar.VERTICAL);
        scrollBar.setBounds(277, 69, 17, 284);
        scrollPane.setVerticalScrollBar(scrollBar);

        contentPane.add(scrollPane);
        
        JButton start = new JButton("S T A R T");
        start.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                
                
            }
        });
        start.setBackground(Color.BLACK);
        start.setForeground(Color.WHITE);
        start.setFont(new Font("SansSerif", Font.BOLD, 11));
        start.setBorder(new LineBorder(Color.WHITE, 1, true));
        start.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        start.setFocusPainted(false);
        start.setContentAreaFilled(false);
        start.setOpaque(true);
        start.setBounds(44, 364, 120, 40);
        contentPane.add(start);
        
        JButton stop = new JButton("S T O P");
        stop.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
            }
        });
        stop.setBackground(Color.BLACK);
        stop.setForeground(Color.WHITE);
        stop.setFont(new Font("SansSerif", Font.BOLD, 11));
        stop.setFocusPainted(false);
        stop.setContentAreaFilled(false);
        stop.setOpaque(true);
        stop.setBorder(new LineBorder(Color.WHITE, 1, true));
        stop.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        stop.setBounds(174, 364, 120, 40);
        contentPane.add(stop);
        
        JButton reset = new JButton("R E S E T");
        reset.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                String textArea = textarea.getText();
                if(textArea.isBlank() || textArea.isEmpty()) {
                    assert false;
                } else {
                    textarea.setText("");
                }
                
            }
        });
        reset.setBorder(new LineBorder(Color.WHITE, 1, true));
        reset.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        reset.setFocusPainted(false);
        reset.setContentAreaFilled(false);
        reset.setOpaque(true);
        reset.setBackground(Color.BLACK);
        reset.setForeground(Color.WHITE);
        reset.setFont(new Font("SansSerif", Font.BOLD, 11));
        reset.setBounds(44, 415, 250, 40);
        contentPane.add(reset);
        
        JPanel table = new JPanel();
        table.setBorder(new LineBorder(Color.GRAY, 2, true));
        table.setBackground(Color.BLACK);
        table.setBounds(307, 69, 350, 386);
        contentPane.add(table);
        table.setLayout(null);
        
        JPanel x = new JPanel();
        x.setBackground(Color.GRAY);
        x.setBounds(175, 0, 2, 386);
        table.add(x);
        
        JPanel xxx = new JPanel();
        xxx.setBackground(Color.GRAY);
        xxx.setBounds(0, 64, 350, 2);
        table.add(xxx);
        
        JPanel xxxx = new JPanel();
        xxxx.setBackground(Color.GRAY);
        xxxx.setBounds(0, 128, 350, 2);
        table.add(xxxx);
        
        JPanel xxxxx = new JPanel();
        xxxxx.setBackground(Color.GRAY);
        xxxxx.setBounds(0, 192, 350, 2);
        table.add(xxxxx);
        
        JPanel xxxxxx = new JPanel();
        xxxxxx.setBackground(Color.GRAY);
        xxxxxx.setBounds(0, 256, 350, 2);
        table.add(xxxxxx);
        
        JPanel xxxxxxx = new JPanel();
        xxxxxxx.setBackground(Color.GRAY);
        xxxxxxx.setBounds(0, 320, 350, 2);
        table.add(xxxxxxx);
        
        JLabel line = new JLabel("L I N E");
        line.setFont(new Font("SansSerif", Font.BOLD, 11));
        line.setForeground(Color.LIGHT_GRAY);
        line.setHorizontalAlignment(SwingConstants.CENTER);
        line.setBounds(0, 0, 175, 64);
        table.add(line);
        
        JLabel x1 = new JLabel("");
        x1.setLabelFor(line);
        x1.setFont(new Font("SansSerif", Font.BOLD, 12));
        x1.setForeground(Color.LIGHT_GRAY);
        x1.setHorizontalAlignment(SwingConstants.CENTER);
        x1.setBounds(0, 64, 175, 64);
        table.add(x1);
        
        JLabel x2 = new JLabel("");
        x2.setLabelFor(line);
        x2.setFont(new Font("SansSerif", Font.BOLD, 11));
        x2.setForeground(Color.LIGHT_GRAY);
        x2.setHorizontalAlignment(SwingConstants.CENTER);
        x2.setBounds(0, 128, 175, 64);
        table.add(x2);
        
        JLabel x3 = new JLabel("");
        x3.setLabelFor(line);
        x3.setForeground(Color.LIGHT_GRAY);
        x3.setFont(new Font("SansSerif", Font.BOLD, 11));
        x3.setHorizontalAlignment(SwingConstants.CENTER);
        x3.setBounds(0, 192, 175, 64);
        table.add(x3);
        
        JLabel x4 = new JLabel("");
        x4.setLabelFor(line);
        x4.setFont(new Font("SansSerif", Font.BOLD, 11));
        x4.setForeground(Color.LIGHT_GRAY);
        x4.setHorizontalAlignment(SwingConstants.CENTER);
        x4.setBounds(0, 256, 175, 64);
        table.add(x4);
        
        JLabel x5 = new JLabel("");
        x5.setLabelFor(line);
        x5.setFont(new Font("SansSerif", Font.BOLD, 11));
        x5.setForeground(Color.LIGHT_GRAY);
        x5.setHorizontalAlignment(SwingConstants.CENTER);
        x5.setBounds(0, 320, 175, 64);
        table.add(x5);
        
        JLabel link = new JLabel("L I N K");
        link.setHorizontalAlignment(SwingConstants.CENTER);
        link.setForeground(Color.LIGHT_GRAY);
        link.setFont(new Font("SansSerif", Font.BOLD, 11));
        link.setBounds(175, 0, 175, 64);
        table.add(link);
        
        JLabel v1 = new JLabel("");
        v1.setLabelFor(link);
        v1.setFont(new Font("SansSerif", Font.BOLD, 11));
        v1.setForeground(Color.LIGHT_GRAY);
        v1.setHorizontalAlignment(SwingConstants.CENTER);
        v1.setBounds(175, 64, 175, 64);
        table.add(v1);
        
        JLabel v2 = new JLabel("");
        v2.setLabelFor(link);
        v2.setFont(new Font("SansSerif", Font.BOLD, 11));
        v2.setForeground(Color.LIGHT_GRAY);
        v2.setHorizontalAlignment(SwingConstants.RIGHT);
        v2.setBounds(175, 128, 175, 64);
        table.add(v2);
        
        JLabel v3 = new JLabel("");
        v3.setLabelFor(link);
        v3.setFont(new Font("SansSerif", Font.BOLD, 11));
        v3.setForeground(Color.LIGHT_GRAY);
        v3.setHorizontalAlignment(SwingConstants.CENTER);
        v3.setBounds(175, 192, 175, 64);
        table.add(v3);
        
        JLabel v4 = new JLabel("");
        v4.setLabelFor(link);
        v4.setFont(new Font("SansSerif", Font.BOLD, 11));
        v4.setForeground(Color.LIGHT_GRAY);
        v4.setHorizontalAlignment(SwingConstants.CENTER);
        v4.setBounds(175, 256, 175, 64);
        table.add(v4);
        
        JLabel v5 = new JLabel("");
        v5.setLabelFor(link);
        v5.setFont(new Font("SansSerif", Font.BOLD, 11));
        v5.setForeground(Color.LIGHT_GRAY);
        v5.setHorizontalAlignment(SwingConstants.CENTER);
        v5.setBounds(175, 320, 175, 64);
        table.add(v5);
public class main {
}

java selenium-webdriver selenium-chromedriver selenium-ide
© www.soinside.com 2019 - 2024. All rights reserved.