主要用到的技巧包括界面嵌套布局(包括BorderLayout, FlowLayout, GridLayout),匿名类,以及java.util.Map<K,V>泛型类的使用。Enjoy it !
import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TranslateDemo {
public static void main( String[] args ) {
new MyWin( "Translator" );
}
}
class MyWin extends JFrame {
private static final long serialVersionUID = 4965728863455140660L;
private JTextField txtEn = new JTextField( 30 );
private JTextField txtCN = new JTextField( 30 );
private JLabel lblInfo = new JLabel( "Translation Demo", JLabel.CENTER );
private JLabel lblEn = new JLabel( "English", JLabel.LEFT )