请大虾再出手相助!

cchandyou 2001-09-18 01:15:59
为什么我java.exe命令运行涉及有awt包的java application程序,程序运行后,我想用右上角的叉叉关闭按钮退出程序,但该按钮失效,为什么?
我的Email: cchandyou@163.net
...全文
69 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wilddragon 2001-09-24
  • 打赏
  • 举报
回复
好困呀
johnbull_bull 2001-09-24
  • 打赏
  • 举报
回复
加上window监听器试试看 :)
import java.awt.*;
import java.awt.event.*;

public class TwoListenInner
{
private Frame f;
private TextField tf;
public static void main(String args[]){
TwoListenInner That=new TwoListenInner();
}

public TwoListenInner(){

f=new Frame("Two listeners example");
f.add("North",new Label("Click and drag the mouse"));
f.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

tf=new TextField(30);
f.add("South",tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseListener(new MouseEventHandler());
f.setSize(300,300);
f.setEnabled(true);
f.setVisible(true);
}
public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s="Mouse dragging: X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
}

public class MouseEventHandler extends MouseAdapter{
public void mouseEntered(MouseEvent e){
String s="The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s="The mouse has left the building";
tf.setText(s);
}
}
}

cchandyou 2001-09-18
  • 打赏
  • 举报
回复
我的jdk版本是1.3,以下是我的一段程序:(用1.3版本编译后运行就出问题,请指教)

import java.awt.*;
import java.awt.event.*;

public class TwoListenInner
{
private Frame f;
private TextField tf;

public static void main(String args[]){
TwoListenInner That=new TwoListenInner();

}

public TwoListenInner(){
f=new Frame("Two listeners example");
f.add("North",new Label("Click and drag the mouse"));
tf=new TextField(30);
f.add("South",tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseListener(new MouseEventHandler());
f.setSize(300,300);
f.setEnabled(true);
f.setVisible(true);
}

public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s="Mouse dragging: X="+e.getX()+"Y="+e.get();
tf.setText(s);
}
}

public class MouseEventHandler extends MouseAdapter{
public void mouseEntered(MouseEvent e){
String s="The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s="The mouse has left the building";
tf.setText(s);


}
}
}

johnbull_bull 2001-09-18
  • 打赏
  • 举报
回复
不知道你的jdk的版本是多少,我用jdk2.1.3没有出现你说的问题。
hexiaofeng 2001-09-18
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;

public class MyApp333 extends Frame
{
public MyApp333()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}

public static void main(String args[])
{
System.out.println("Starting App");
MyApp333 f = new MyApp333();
f.setSize(100,100);
f.show();
}
}

62,614

社区成员

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

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