为什么我的不显示按钮

package lianxi;

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.io.*;

public class Ftest1 extends JFrame {

    private static final long serialVersionUID=1L;
    private JPanel jContentPane=null;
    private JTextArea jTextArea=null;
    private JPanel controlPanel=null;
    private JButton openButton=null;
    private JButton colesButton=null;

    private JTextArea getJTextArea() {
        if (jTextArea == null) {
            jTextArea = new JTextArea();
        }
        return jTextArea;
    }
    private JPanel getControlPanel() {
        if (controlPanel == null) {
            FlowLayout flowLayout = new FlowLayout();
            flowLayout.setVgap(1);
            controlPanel = new JPanel();
            controlPanel.setLayout(flowLayout);
            controlPanel.add(getOpenButton(), null);
            controlPanel.add(getCloseButton(), null);
        }
        return controlPanel;
    }

    private JButton getOpenButton(){
        if(openButton==null){
            openButton=new JButton();
            openButton.setText("写入文件");
            openButton.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent e){
                    File file=new File("word.txt");

                    try {
                        FileWriter out= new FileWriter(file);
                        String s=jTextArea.getText();
                        out.write(s);
                        out.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }

            });

        }
        return openButton;

    }

    private JButton getCloseButton(){
        if(openButton==null){
            openButton=new JButton();
            openButton.setText("读取文件");
            openButton.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent e){
                    File file=new File("word.txt");
                    try {
                        FileReader in=new FileReader(file);

                        char byt[]=new char[1024];
                        int len=in.read(byt);
                        jTextArea.setText(new String(byt,0,len));
                        in.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }

            });

        }
        return openButton;

    }

    public Ftest1(){
        super();
        initialize();
    }

    private void initialize(){
        this.setSize(300,200);
        this.setContentPane(getJContentPane());
        this.setTitle("JFrame");
    }

    private JPanel getJContentPane(){
        if(jContentPane==null){
            jContentPane=new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getJTextArea(), BorderLayout.CENTER);
            jContentPane.add(getContentPane(),BorderLayout.SOUTH);
        }
        return jContentPane;
    }

    public static void main(String[] args) {
        Ftest1 thisClass=new Ftest1();
        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        thisClass.setVisible(true);

    }

}

应该是上图结果我的为什么是下面这

个图

时间: 2024-08-10 17:18:15

为什么我的不显示按钮的相关文章

鼠标经过显示按钮的详细信息

之前介绍了几款css3实现的按钮,今天为网友来款比较新鲜的,用css3的data-attribute属性开发按钮,当鼠标经过显示按钮的详细信息.而且实现过程很简单,几行代码就搞定.大家试一试吧.如下图: 不错吧,贴上实现代码: html代码: <button data-hover="爱编程(w2bc.com)收集编程资料,web前端案例"> 爱编程</button> <button data-hover="爱编程(w2bc.com)收集编程资料,

非主窗体在任务栏显示按钮(简单好用)good

非主窗体在任务栏显示按钮 type TForm2 = class(TForm) private { Private declarations } public { Public declarations } procedure CreateParams(var Params:TCreateParams); override; end; ... procedure TForm2.CreateParams(var Params: TCreateParams); begin inherited Cre

C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值

关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using System; using System.Windows.Forms; namespace Simon.WinForms.Examples.PropertyGrid { public class EditorControl : UserControl { public EditorControl() {

UITableViewCell左滑显示按钮菜单

http://blog.jobbole.com/67272/ 编辑模式下左滑可以显示DELETE按钮.如何可以自定义左滑显示的按钮呢? 整体思路 1.自定义UITableViewCell,并为其contentView添加左滑时希望显示的按钮. 2.在contentView上添加一个相同大小subView,作为正常情况下tableViewCell显示的内容. 3.为此subView添加pan事件,滑动的时候移动其位置,使按钮可以显示出来. 需要注意的问题 具体实现(仿微信效果) 新建自定义的Tab

js--手机头像点击显示按钮的位置自适应

在手机页面的中,头像显示的div,第一行的最后一个为点击显示更多的按钮(more),因为手机宽度的大小不一致,所以每行显示的头像个数也不一致,more按钮的位置总是固定在最后一排,所以需要通过计算屏幕宽度的大小,然后根据每个li的大小算出一行中最多能放几个,然后在将more通过js插入,如下图 iPhone5 显示如下: iPhone6 显示如下: 一下贴代码: HTML <div class="pic"> <ul> <li><img src=

(转)RadioButton左侧显示文字,右侧显示按钮时文字不靠边的问题解决

作者:  发布日期:2014-02-13 21:00:45 我来说两句(0) 0 Tag标签:RadioButton  左侧  显示 项目中有一个这样的需求: 下面三行点击某行即选中,颜色变深.自然的想到使用RadioButton因此决定使用RadioButton和RadioButton实现. 1.RadioButton实现上述效果 view sourceprint? 01.<RadioButton 02.android:id="@+id/rbAll" 03.android:la

使用swiper 3的时候,图片滑动无法显示按钮的方法

1.在项目于当中使用swiper3做上下滑动H5页面的时候,里面再次嵌套一个swiper或者touchslider滑动插件的时候(在width:100%的时候显示正常),当宽度小于100%的时候,按钮控件无法显示 方法一 在向上滑动的时候显示一个遮罩层 语言组织太差,不知道有没有看懂

Android 浮动按钮+上滑隐藏按钮+下滑显示按钮

1.效果演示 1.1.关注这个红色的浮动按钮 . 可以看到,上滑的时候浮动按钮消失,因为用户迫切想知道下面的东西,而不是回到顶部. 当下滑的时候,用户想回到原来的位置,就可以点击浮动按钮,快速回到顶部.所以浮动按钮弹上来了. 2.定义一个动画通用类AnimatorUtil 2.1.源代码如下 public class AnimatorUtil { private static LinearOutSlowInInterpolator FAST_OUT_SLOW_IN_INTERPOLATOR =

C# 时间控件 竖直进度条 饼图显示 按钮基础控件库

Prepare 本文将使用一个NuGet公开的组件来实现一些特殊的控件显示,方便大家进行快速的开发系统. 在Visual Studio 中的NuGet管理器中可以下载安装,也可以直接在NuGet控制台输入下面的指令安装: Install-Package HslCommunication NuGet安装教程  http://www.cnblogs.com/dathlin/p/7705014.html 技术支持QQ群:592132877 (组件的版本更新细节也将第一时间在群里发布) Summary

猎豹MFC--在窗口中显示按钮

现在框架窗口上定义私有的数据成员: 然后跳转到cpp文件: 上面是把按钮放在了框架窗口内而坐标 工具栏是在框架窗口的哦内部客户区中. 该按钮时放在了外面的框架窗口中.由以下可知: 现在重新做一个放在视图中: 增加私有变量: .给视图类增加OnCreate消息: 以上其实是由两个窗口构成外面的是框架窗口,里面的是视图窗口.两个按钮分别在不同的窗口. 来自为知笔记(Wiz)