TextField tf=new TextField(20);
TextArea ta=new TextArea(20,40);
添加监听
package com;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class day2 extends JFrame{
public static void main(String[] args) {
JFrame frame =new JFrame(“东方月初”);
JButton OJ=new JButton(“王权富贵”);
OJ.setLayout(new FlowLayout());
frame.add(OJ);
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setBounds(100,34,78,90);
frame.setLayout(new FlowLayout());
TextField tf = new TextField(20);
frame.add(tf);
TextArea ta = new TextArea(10, 40);
frame.add(ta);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}