textdemo.java
来自「金旭亮的java教案」· Java 代码 · 共 38 行
JAVA
38 行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextDemo {
static JFrame jframe = new JFrame("Example");
public static void setupjframe() {
jframe.setSize(400,100);
jframe.setVisible(true);
jframe.getContentPane().setLayout( new FlowLayout() );
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
jframe.addWindowListener(l);
}
public static void main(String[] args) {
JTextField jtf = new JTextField(25);
JLabel jl = new JLabel("Enter your name:");
jtf.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{ System.out.println(" you entered: " + e.getActionCommand() ); }
} );
Container c = jframe.getContentPane();
c.add( jl );
c.add( jtf );
setupjframe();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?