zoukankan      html  css  js  c++  java
  • Java里怎么实现点击一个按钮然后在文本框里显示按钮对应的字符?

    package com.y;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class Test extends JFrame implements ActionListener{
        JPanel panel   =new JPanel();
        JButton b1     =new JButton("1");
        JButton b2     =new JButton("2");
        JButton b3     =new JButton(".");
        JLabel  lbl    =new JLabel("我是标签");
        JTextField txt =new JTextField("",10);
        public Test(){
            this.setLayout(new FlowLayout());
            panel.add(b1);panel.add(b2);panel.add(b3);panel.add(lbl);panel.add(txt);
            this.add(panel);
            b1.addActionListener(this);
            b2.addActionListener(this);
            b3.addActionListener(this);
        }
        public static void main(String[] args) {
            Test test=new Test();
            test.setSize(400,260);
            test.setLocationRelativeTo(null);
            test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            test.setVisible(true);
        }
        @Override
        public void actionPerformed(ActionEvent ae) {
            txt.setText( txt.getText() + ae.getActionCommand() );
        }
    }
  • 相关阅读:
    Pandas基本命令
    python——内建模块instance的学习
    pyhton——logging日志模块的学习
    mongoDB集群的搭建
    goahead(web服务器)分析
    2019-9
    cmake
    mqtt+htttp+websocket
    u-boot中filesize环境变量【转载】
    cppcheck下载及使用
  • 原文地址:https://www.cnblogs.com/springcloud/p/9063113.html
Copyright © 2011-2022 走看看