17.4

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.swing.*;

public class Test_17_4 extends JFrame{
    private JLabel jl1 = new JLabel("Filename");
    private JTextField jt1 = new JTextField("d:\\a.txt",10);
    private JButton jb1 = new JButton("View");
    private JPanel jholdPanel = new JPanel();
    private JP jp1 = new JP();
    private String s;

    public Test_17_4(){
        add(jp1);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Test_17_4 frame = new Test_17_4();
        frame.setTitle("Test_17_4");
        frame.setSize(400,500);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    class JP extends JPanel{
        private JTextArea jt = new JTextArea();
        private File file;
        private Scanner input;

        public JP(){
            //set textarea
            jt.setLineWrap(true);
            jt.setWrapStyleWord(false);
            jt.setEditable(false);

            JScrollPane scro = new JScrollPane(jt);        

            //create jscrollpanel to hole the textarea
            JScrollPane scrollPane = new JScrollPane(jt);            

            jholdPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
            jholdPanel.add(jl1);
            jholdPanel.add(jt1);
            jholdPanel.add(jb1);

            jb1.addActionListener(new ActionListener(){

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    // TODO Auto-generated method stub
                    s = jt1.getText();
                    try {
                        jp1.setText(s);
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

            });

            setLayout(new BorderLayout(5,5));
            add(scrollPane,BorderLayout.CENTER);
            add(jholdPanel,BorderLayout.SOUTH);
        }

        public void setText(String s) throws FileNotFoundException{
            file = new File(s);
            if(file.canRead() && file.exists()) {
                input = new Scanner(file);
                while(input.hasNext()) {
                    jt.append(input.nextLine());
                    jt.append("\n");
                }
            }
            else System.out.println("does not exists!");
            input.close();
        }
    }

}

效果图:

时间: 2024-10-22 04:12:40

17.4的相关文章

AnimeGAN输出日志

D:\MyFiles\LearnFiles\Code\Python\AnimeGAN\AnimeGAN>python main.py --phase train --dataset Hayao --epoch 1 --init_epoch 1D:\Users\feng_\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning:

[c/c++] programming之路(17)、高级指针

一.二级指针 二级指针的作用:1.函数改变外部变量指针2.外挂改变一个指针的值 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a = 10; 6 int b = 20; 7 int *p1 = &a; 8 int *p2 = &b; 9 int **pp = &p1; 10 printf("%d,", **pp); 11 printf("\n%x,

java核心技术 - 17个重要的知识点

1.Java中没有多继承,而是用接口来代替多继承 2.运行一个已经编译的程序时,Java解释器总是从指定类的main方法中的代码开始执行,因此,执行代码中必须有一个main函数. 3.Java是典型的强类型语言,即必须声明变量的类型,Java中有8种类型,6种数值类型(4个整数型和2个浮点型).一个字符类型和一个boolean类型. 想学习java可以来这个群,首先是二二零,中间是一四二,最后是九零六,里面有大量的学习资料可以下载. 4.强制类型转换: int nx = (int) x; //

Up to 8% free bonus for runescape 2007 gp on Rsorder as july best gift&Enjoy Telos During 7.1-7.22

Now, a small band of freedom fighters struggle to end the osrs gold  long, dark night of Daein's oppression. The big blog news of the day is that Vox Media has acquired Curbed Network. As an amulet you should be wearing an amulet of glory and if you

PSP(5.11——5.17)以及周记录

1.PSP 5.11 14:30 20:00 130 200 Cordova A Y min 5.12 9:00 14:00 100 200 Cordova A Y min 5.13 13:30 15:00 20 70 软件项目管理课 A Y min 19:00 20:00 20 40 Cordova A Y min 5.17 11:00 19:00 240 240 Cordova A Y min 2.PSP分类统计以及圆饼图 分类 A B C D 时间总计 750 0  0 0     3.周

TControl的消息覆盖函数大全(15个WM_函数和17个CM_函数,它的WndProc就处理鼠标与键盘消息)

注意,这些函数只有Private一种形式(也就是不允许覆盖,但仍在动态表格中): TControl = class(TComponent) private // 15个私有消息处理,大多是鼠标消息.注意,消息函数大多只是一个中介,且TWinControl并不重写. procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLBUTTONDOWN; procedure WMLButtonDown(var Messa

【面试题17】合并两个排序的链表

[题目描述] 输入两个递增排序的链表,合并这两个链表并使新链表中的结点是按照递增排序的. [解决方案] 用递归解决,非常简单. 我的代码实现,仅供参考: 1 public static ListNode Merge(ListNode listA, ListNode listB) 2 { 3 if (listA == null) 4 { 5 return listB; 6 } 7 else if(listB == null) 8 { 9 return listA; 10 } 11 12 ListN

Leetcode -- Day 17

substring Question 1 Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Below is my first direct solution, which looks complex in different case checking us

17.如何自学Struts2之Struts2 Annotation注释[视频]

17.如何自学Struts2之Struts2 Annotation注释[视频] 之前写了一篇"打算做一个视频教程探讨如何自学计算机相关的技术",优酷上传不了,只好传到百度云上: http://pan.baidu.com/s/1kTDsa95 有问题可以直接回复这篇文章.

Android学习系列(17)--App列表之圆角ListView(续)

http://www.cnblogs.com/qianxudetianxia/archive/2011/09/19/2068760.html 本来这篇文章想并到上篇Android学习系列(16)--App列表之圆角ListView中的,但是若是如此就让大家错过一篇新的好的文章,着实可惜.上篇中我们使用shape,corners,gradient实现了一个渐变的圆角效果,但是在完文之后的实践中,我发现有时效果不甚满意,选中和放手的事件监听没有去正确的判断,然后渐变效果也比较单一,性能也觉得不是很快