⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j_button.java

📁 一个十分好的java基础学习的课件
💻 JAVA
字号:
// ////////////////////////////////////////////////////////
// 
// J_Button.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
//     Button Click: Application as well as Applet.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
//     Jun-Hai Yong. Programming in Java. 
//     Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
//     雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no 
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class J_Button extends JApplet implements ActionListener
{
    Container  m_container= null;
    JButton m_button= new JButton("1");

    public void init( )
    {
        if (m_container==null)
            m_container= getContentPane( );
        m_container.setLayout(new BorderLayout( ));
        m_container.add(m_button, BorderLayout.CENTER);
        m_button.addActionListener(this);
    } // End of method: init

    public void actionPerformed(ActionEvent ev)
    {
        if (ev.getSource( )==m_button)
        {
            int i= Integer.parseInt(ev.getActionCommand( ));
            i++;
        	String s = ""+i;
        	m_button.setText(s);
        }
    } // End of method: actionPerformed

    public static void main( String args[] )
    { 
        JFrame f = new JFrame("Application as well as Applet");
        J_Button app = new J_Button( );

        app.m_container= f.getContentPane( );
        app.init( );
        f.setSize(200, 120);
        f.setVisible( true );
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } // End of method: main

} // End of class: J_Button

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -