ch10ex6.java
来自「JAVA程序设计 丁岳伟 彭敦陆编 高等教育出版社 第7---11章程序」· Java 代码 · 共 42 行
JAVA
42 行
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Frame5 extends JFrame{
JTextField t1=new JTextField(15);
JTextArea t2=new JTextArea(11,15);
JLabel label=new JLabel("Enter text content");
Container cp;
public Frame5(){
super();
setTitle("Text/Area Field");
cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(label);
cp.add(t1);
cp.add(t2);
t1.addActionListener(new ActionListenerT1());
setSize(300,300);
setLocation(50,50);
addWindowListener(new WindowDestroyer());
}
class ActionListenerT1 implements ActionListener{
public void actionPerformed(ActionEvent e){
String s=t1.getText();
if(t2.getLineCount()<10){
t1.setText("");
t2.append(s+"\n");
}
}
}
}
public class ch10ex6{
public static void main(String args[]){
Frame5 win=new Frame5();
win.setVisible(true);
}
}
class WindowDestroyer extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?