A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

S

© 再见亦是泪 中级黑马   /  2013-1-20 21:33  /  1195 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 张向辉 于 2013-1-22 11:14 编辑

package cn.itzero;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MyJFrame extends javax.swing.JFrame {
        /**
         *
         */
        private static final long serialVersionUID = -3597768312571563368L;
        private JButton jButton1;
        private JTextField jTextField1;

        /**
        * Auto-generated main method to display this JFrame
        */
        public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                                MyJFrame inst = new MyJFrame();
                                inst.setLocationRelativeTo(null);
                                inst.setVisible(true);
                        }
                });
        }
        
        public MyJFrame() {
                super();
                initGUI();
        }
        
        private void initGUI() {
                try {
                        getContentPane().setLayout(null);
                        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        getContentPane().setBackground(new java.awt.Color(0,128,64));
                        {
                                jButton1 = new JButton();
                                getContentPane().add(jButton1);
                                jButton1.setLayout(null);
                                jButton1.setText("\u63d0\u4ea4");
                                jButton1.setBounds(336, 27, 65, 28);
                                jButton1.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent evt) {
                                                jButton1ActionPerformed(evt);
                                        }
                                });
                        }
                        {
                                jTextField1 = new JTextField();
                                getContentPane().add(jTextField1);
                                jTextField1.setBounds(38, 26, 253, 29);

                        }
                        pack();
                        this.setSize(500, 400);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
        int count=1;
        private void jButton1ActionPerformed(ActionEvent evt) {
               
                System.out.println(count++);
               
        }

}

评分

参与人数 1技术分 +1 收起 理由
Rancho_Gump + 1 赞一个!

查看全部评分

4 个回复

倒序浏览

RE: Swing中的一个问题没弄明白

我想要把控制台中打出的数字显示在窗口程里的text文本里,该怎么弄
回复 使用道具 举报
结果如图 我想要将控制台中的数字显示在text里,方法在哪

未命名.jpg (73.33 KB, 下载次数: 39)

未命名.jpg
回复 使用道具 举报
不知道你要显示在哪个text,我想就是那个输入框吧.

那个只用将最后一个方法 jButton1ActionPerformed修改如下
  1. private void jButton1ActionPerformed(ActionEvent evt) {
  2.                
  3.                // System.out.println(count++);
  4.                 jTextField1.setText(count+++"");
复制代码

评分

参与人数 1黑马币 +20 收起 理由
再见亦是泪 + 20

查看全部评分

回复 使用道具 举报
多谢,搞定了 原来是加在按扭事件里,开始我搞错了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马