一直以为,有了import java.awt.*;后面的两句import可以省了。试试却不行!这是不是java.awt.*只能包含了一级目录?import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;class MyWindow extends Frame implements ActionListener {
private static final long serialVersionUID = 1L;
TextField text1, text2, text3;
public MyWindow() {
setLayout(new FlowLayout());
text1 = new TextField(8);
text2 = new TextField(8);
text3 = new TextField(15);
add(text1);
add(text2);
add(text3);
text1.addActionListener(this); //将窗口作为text的监视器
text2.addActionListener(this); //将窗口作为text的监视器
setBounds(100, 100, 150, 150);
setVisible(true);
validate();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == text1) {
String word = text1.getText();
if (word.equals("boy")) {
text3.setText("男孩");
}
else if (word.equals("girl")) {
text3.setText("女孩");
}
else if (word.equals("sun")) {
text3.setText("太阳");
}
else {
text3.setText("没有该单词");
}
}
else if (e.getSource() == text2) {
String word = text2.getText();
if (word.equals("boy")) {
text3.setText("男孩");
}
else if (word.equals("girl")) {
text3.setText("女孩");
}
else if (word.equals("sun")) {
text3.setText("太阳");
}
else {
text3.setText("没有该单词");
}
}
}
}public class Example7_3 {
public static void main(String args[]) {
new MyWindow();
}
}
/*
连接源码
java “D:\Program Files\Java\jdk1.6.0_23\src.zip” 18.8 MB,F3将此zip附着上就可以了。
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;class MyWindow extends Frame implements ActionListener {
private static final long serialVersionUID = 1L;
TextField text1, text2, text3;
public MyWindow() {
setLayout(new FlowLayout());
text1 = new TextField(8);
text2 = new TextField(8);
text3 = new TextField(15);
add(text1);
add(text2);
add(text3);
text1.addActionListener(this); //将窗口作为text的监视器
text2.addActionListener(this); //将窗口作为text的监视器
setBounds(100, 100, 150, 150);
setVisible(true);
validate();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == text1) {
String word = text1.getText();
if (word.equals("boy")) {
text3.setText("男孩");
}
else if (word.equals("girl")) {
text3.setText("女孩");
}
else if (word.equals("sun")) {
text3.setText("太阳");
}
else {
text3.setText("没有该单词");
}
}
else if (e.getSource() == text2) {
String word = text2.getText();
if (word.equals("boy")) {
text3.setText("男孩");
}
else if (word.equals("girl")) {
text3.setText("女孩");
}
else if (word.equals("sun")) {
text3.setText("太阳");
}
else {
text3.setText("没有该单词");
}
}
}
}public class Example7_3 {
public static void main(String args[]) {
new MyWindow();
}
}
/*
连接源码
java “D:\Program Files\Java\jdk1.6.0_23\src.zip” 18.8 MB,F3将此zip附着上就可以了。
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货