次程序在eclipse中可运行,但在DOS下运行不了,还有java标识符不能用中文,下面程序却能运行,奇怪!

java3399 2009-04-14 12:32:47
package jichu.shiyi12;


import java.awt.*;
public class Example11_12
{ public static void main(String args[])
{ new MyFrame();
}
}
class MyFrame extends JFrame implements Runnable,ActionListener
{ /**
*
*/
private static final long serialVersionUID = 1L;
售票员 王小姐;
Thread 张平,李明;
static JTextArea text;
JButton startBuy=new JButton("开始买票");
MyFrame()
{ 王小姐=new 售票员();
张平=new Thread(this);
李明=new Thread(this);
text=new JTextArea(10,30);
startBuy.addActionListener(this);
add(text,BorderLayout.CENTER);
add(startBuy,BorderLayout.NORTH);
setVisible(true);
setSize(360,300);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{ try{ 张平.start();
李明.start();
}
catch(Exception exp) {}
}
public void run()
{ if(Thread.currentThread()==张平)
{ 王小姐.售票规则(20);
}
else if(Thread.currentThread()==李明)
{ 王小姐.售票规则(5);
}
}
}
class 售票员
{ int 五元钱的个数=2,十元钱的个数=0,二十元钱的个数=0;
String s=null;
public synchronized void 售票规则(int money)
{ if(money==5) //如果使用该方法的线程传递的参数是5,就不用等待
{ 五元钱的个数=五元钱的个数+1;
s= "给您入场卷您的钱正好";
MyFrame.text.append("\n"+s);
}
else if(money==20)
{ while(五元钱的个数<3)
{ try { wait(); //如果使用该方法的线程传递的参数是20须等待
}
catch(InterruptedException e){}
}
五元钱的个数=五元钱的个数-3;
二十元钱的个数=二十元钱的个数+1;
s="给您入场卷"+" 您给我20,找您15元";
MyFrame.text.append("\n"+s);
}
notifyAll();
}
}
...全文
71 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
airbak 2009-04-14
  • 打赏
  • 举报
回复
dos 进入jichu.shiyi12,再运行
wzg112 2009-04-14
  • 打赏
  • 举报
回复
大哥,你非要用中文定义吗?不乱啊
你的问题估计是字符集编码的问题!

58,452

社区成员

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

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