📄 j_button.java
字号:
// ////////////////////////////////////////////////////////
//
// J_Button.java
//
// ////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class J_Button
{
public static void main( String args[] )
{
JFrame app = new JFrame( "Example of event-handling" );
Container cp = app.getContentPane( );
JButton b= new JButton("Pressed 0 times!");
cp.setLayout( new BorderLayout( ) );
cp.add(b, BorderLayout.CENTER);
b.addActionListener( new ActionListener( )
{
int m_count = 0;
public void actionPerformed(ActionEvent e)
{
JButton b= (JButton)e.getSource( );
b.setText("Pressed " + (++m_count) + " times");
} // End of method: actionPerformed
} // End of the anonymous inner class
); // End of invoking addActionListener
app.setSize( 100, 80 );
app.setVisible( true );
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
} // End of method: main
} // End of class: J_Button
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -