博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java_JFrame_demo
阅读量:4982 次
发布时间:2019-06-12

本文共 4163 字,大约阅读时间需要 13 分钟。

不要见笑,cs基本入行很少做

留个demo备忘

 

/*    * Copyright (c) 2014-2024 . All Rights Reserved.    *    * This software is the confidential and proprietary information of    * LoongTao. You shall not disclose such Confidential Information    * and shall use it only in accordance with the terms of the agreements    * you entered into with LoongTao.    *    */package com.loongtao.main;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.List;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import com.**.utils.RegexUtils;@SuppressWarnings("serial")public class TestJFrame extends JFrame implements ActionListener {    private static int x = 80;    private static int y = 80;    private static int w = 1000;    private static int h = 750;    private JLabel htmlLabel = new JLabel();    private JLabel resultLabel = new JLabel();    private JTextField urlField = new JTextField("", 82);    private JTextField cssPathField = new JTextField("", 82);    private JTextArea htmlArea = new JTextArea(20, 80);    private JScrollPane htmlScrollPane = new JScrollPane(htmlArea);    private JTextArea resultArea = new JTextArea(30, 80);    private JScrollPane resultScrollPane = new JScrollPane(resultArea);    private JButton jbGetSource = new JButton("转换");    private JButton jbResetAll = new JButton("重置");    public TestJFrame() {        this.setTitle("转换工具 1.3 @email cphmvp@163.com");        this.setLayout(new FlowLayout());        // 设置标签        this.add(htmlLabel);        this.htmlLabel.setText("源文本 : ");        // 设置文本域        this.htmlArea.setAutoscrolls(false);        this.htmlArea.setLineWrap(true);        // 分别设置水平和垂直滚动条总是出现        htmlScrollPane                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);        htmlScrollPane                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);        this.add(htmlScrollPane, BorderLayout.CENTER);        // 设置大小不会无限下滑        this.htmlScrollPane.setPreferredSize(new Dimension(900, 200));        this.add(htmlScrollPane);        // 设置标签        this.add(resultLabel);        this.resultLabel.setText("结果集 :");        // 设置文本域        this.resultArea.setAutoscrolls(false);        this.resultArea.setLineWrap(true);        // 分别设置水平和垂直滚动条总是出现        resultScrollPane                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);        resultScrollPane                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);        this.add(resultScrollPane, BorderLayout.CENTER);        // 设置大小不会无限下滑        this.resultScrollPane.setPreferredSize(new Dimension(900, 250));        this.add(resultScrollPane);        this.add(jbGetSource);        this.add(jbResetAll);        jbGetSource.addActionListener(this);        jbResetAll.addActionListener(this);        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    }    public static void main(String[] args) {        TestJFrame t = new TestJFrame();        // 1 x 2 y 3 宽、4 、高        t.setBounds(x, y, w, h);        t.setVisible(true);    }    public void actionPerformed(ActionEvent e) {        JButton jb = (JButton) e.getSource();        String html = "";        String cssQuery = "";        if (jb == jbGetSource) {            dealGetSource(html, cssQuery);        } else if (jb == jbResetAll) {            urlField.setText("");            cssPathField.setText("");            htmlArea.setText("");            resultArea.setText("");        }    }    /**     * @declare:处理得到源码操作     * @param html     * @param cssQuery     * @author cphmvp     */    private void dealGetSource(String html, String cssQuery) {        String txt = htmlArea.getText();        htmlArea.setText(txt);        List
htmls = RegexUtils.getStringList(txt, "\\w+", 0); String result = htmls.toString(); result = result.replace("[", "").replace("]", ""); resultArea.setText(result); }}

 

转载于:https://www.cnblogs.com/cphmvp/p/4095183.html

你可能感兴趣的文章
大数据平台搭建-hadoop集群的搭建
查看>>
安装一些包管理的记录 win10
查看>>
Android RecyclerView notifyDataSetChanged不起作用
查看>>
AndroidStudio3.0 Canary 8注解报错Annotation processors must be explicitly declared now.
查看>>
Android 一个改进的okHttp封装库
查看>>
genymotion下载出现Unable to create virtual device,Server returned HTTP status code 0.
查看>>
Android 下拉刷新框架实现
查看>>
ViewPager + Fragment实现滑动标签页
查看>>
Spring与Hibernate实现增删改查两方法
查看>>
Genymotion 插件在 Eclipse 和 Android Studio 中点击后无法初始化 Initialize Engine: failed 解决方法...
查看>>
1R安装环境
查看>>
初学Python——Socket网络编程
查看>>
Linux 如何实现 VLAN - 每天5分钟玩转 OpenStack(12)
查看>>
Gym - 101252H
查看>>
2019年2月15日,复习
查看>>
线性布局Row和Column
查看>>
关键路径(代码讲解)- 数据结构和算法68
查看>>
if语句三种格式
查看>>
CentOS 7 单用户模式修改root密码
查看>>
Linux DHCP原理
查看>>