请大侠帮忙看看,下面的程序无法执行

qq_37815225 2017-03-08 03:43:01
import java.awt.*;
import java.awt.event.*;
class MyWindow extends Frame implements ActionListener
{
TextField text1,text2,text3;
MyWindow()
{
setLayout(new FlowLayout());
text1=new TextField(8);
text1=new TextField(8);
text1=new TextField(15);
add(text1);
add(text2);
add(text3);
setBounds(100,100,200,150);
text1.addActionListener(this);
text2.addActionListener(this);
setVisible(true);
validate();
}
//对事件处理方法
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 {text3.setText("没有该单词!");
}
}
else if (e.getSource()==text2)
{
String word=text2.getText();
if(word.equals("男孩"))
{
text3.setText("boy");
}
else if(word.equals("女孩"))
{
text3.setText("girl");
}
else {text3.setText("没有该单词!");
}
}
}

}

public class Eve {
public static void main(String args[])
{
MyWindow win=new MyWindow();
}
}
...全文
180 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_37815225 2017-03-10
  • 打赏
  • 举报
回复
import java.awt.*; //import java.awt.event.*; class WindowExit extends Frame //implements ActionListener { MenuBar menubar; Menu menu; MenuItem itemExit; WindowExit(String s) { setTitle(s); Toolkit tool=getToolkit(); Dimension dim=tool.getScreenSize(); setBounds(0,0,dim.width,dim.height/2); menubar=new MenuBar(); menu=new Menu("文件"); itemExit=new MenuItem("退出"); menu.add(itemExit); menubar.add(menu); setMenuBar(menubar); //exit.addActionListener(this); setVisible(true); validate(); } } public class WindowEx { public static void main(String args) { WindowExit win=new WindowExit("窗口"); } }
qq_37815225 2017-03-10
  • 打赏
  • 举报
回复
是的,刚学习,下面还有一条也请帮我看看啊!
合肥-歪歪 2017-03-10
  • 打赏
  • 举报
回复
兄弟,你这基础不行啊。。。。
qq_37815225 2017-03-10
  • 打赏
  • 举报
回复
谢谢楼上的三位大侠!
  • 打赏
  • 举报
回复
楼上说的不错
沙子 2017-03-08
  • 打赏
  • 举报
回复
楼上说的不错
bcsflilong 2017-03-08
  • 打赏
  • 举报
回复
text1=new TextField(8);
text1=new TextField(8);
text1=new TextField(15);
add(text1);
add(text2);
add(text3);
改为
text1=new TextField(8);
text2=new TextField(8);
text3=new TextField(15);
add(text1);
add(text2);
add(text3);

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧