有个题目,它的要求是用swing做,但是我不知道swing写的界面的响应函数怎么办?我坚强的用了awt做了响应那块,可是心里忐忑啊,求只有swing的代码,这里我也把我写的代码附上。
package com.exam.study;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.*;
public class test3 extends JFrame implements ActionListener {
JButton print;
JTextField field1;
JTextField field2;
JPanel p;
public test3(String title)
{
super(title);
print=new JButton("show");
print.addActionListener(this);
field1=new JTextField();
field2=new JTextField();
p=new JPanel();
p.setLayout(new GridLayout(3, 1));
p.add(field1);
p.add(field2);
p.add(print);
this.getContentPane().add(p,BorderLayout.CENTER);
this.setLocation(100,100);
this.setSize(250,250);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String message1=field1.getText();
String message2=field2.getText();
System.out.println(message1+" "+message2);
}
public static void main(String [] args)
{
new test3("111");
}
}
|