当前位置: 代码迷 >> Java相关 >> 编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中 ...
  详细解决方案

编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中 ...

热度:79   发布时间:2011-05-03 21:44:15.0
编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中显示按钮上显示的字
编写一个小应用程序,在其中有一个按钮和一个文本框。单击按钮时,文本框中显示按钮上显示的字
搜索更多相关的解决方案: 应用程序  文本框  

----------------解决方案--------------------------------------------------------
好像不难
----------------解决方案--------------------------------------------------------
恩恩。。。。。路过。。。
----------------解决方案--------------------------------------------------------
程序代码:
public class Activity {
    public static void main(String args[])
    {
        new yxf();
    }
}

class yxf extends Frame implements ActionListener
{
    private Button button = null;//按钮句柄
    private TextArea textarea = null;//文本句柄
   
    yxf()
    {
        super("测试...");
        setBounds(100, 100, 300, 200);
        setBackground(Color.gray);
      
        initComponent();
      
        setVisible(true);
        validate();
    }
   
    private void initComponent()
    {
        button = new Button("嘿嘿...");
        button.addActionListener(this);
        add(button, BorderLayout.SOUTH);
      
        textarea = new TextArea();
        add(textarea, BorderLayout.CENTER);
      
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent event)
            {
                System.exit(0);
            }
        });
      
    }
    @Override
    public void actionPerformed(ActionEvent event) {
        // TODO Auto-generated method stub
        if (event.getSource() == button)
        {
            textarea.append(button.getLabel().toString() + "\n");
        }
    }
}

----------------解决方案--------------------------------------------------------
回复 4楼 诸葛修勤
真棒。。。。。。
----------------解决方案--------------------------------------------------------
  相关解决方案