请大家帮我改改这两处程序!

ycx111 2006-12-15 03:45:03
import java.awt.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.*;



class ToeButton extends Canvas {
int state=ToeDialog.BLANK;
ToeDialog parent;

ToeButton(ToeDialog parent){
this.parent=parent;
}
public void paint(Graphics g){
int x1=0;
int y1=0;
int x2=getSize().width-1;
int y2=getSize().height-1;
g.drawRect(x1,y1,x2,y2);
int wide=x2/2;
int high=y2/2;
if(state==ToeDialog.XX){
g.drawLine(x1,y1,x1+wide,y1+high);
g.drawLine(x1,y1+high,x1+wide,y1);
}
if(state == ToeDialog.OO) {
g.drawOval(x1, y1, x1+wide/2, y1+high/2);
}

}
(第一处) public boolean mouseDown(Event evt,int x,int y){
if(state==ToeDialog.BLANK){
state=parent.turn;
parent.turn=(parent.turn==ToeDialog.XX?ToeDialog.OO:ToeDialog.XX);

}
else
state=(state==ToeDialog.XX?ToeDialog.OO:ToeDialog.XX);
repaint();
return true;
}
}
class ToeDialog extends Dialog {
static final int BLANK = 0;
static final int XX = 1;
static final int OO = 2;
int turn = XX;
public ToeDialog(Frame parent, int w, int h) {
super(parent, "The game itself", false);
setLayout(new GridLayout(w, h));
for(int i = 0; i < w * h; i++)
add(new ToeButton(this));
//resize(w * 50, h * 50);
setSize(w*50,h*50);


}


(第二处) public boolean handleEvent(Event evt) {
if(evt.id == Event.WINDOW_DESTROY)
dispose();
else
return super.handleEvent(evt);
return true;
}
}

public class ToeTest extends Frame{
TextField rows = new TextField("3");
TextField cols = new TextField("3");
/** Creates a new instance of ToeTest */
public ToeTest() {
setTitle("Toe Test");
Panel p = new Panel();
p.setLayout(new GridLayout(2,2));
p.add(new Label("Rows", Label.CENTER));
p.add(rows);
p.add(new Label("Columns", Label.CENTER));
p.add(cols);
add("North", p);
Button b=new Button("go");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Dialog d=new ToeDialog(ToeTest.this,Integer.parseInt(rows.getText()),Integer.parseInt(cols.getText()));
d.setVisible(true);
}
});
add("South", b);
/*b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Dialog d = new ToeDialog(this,Integer.parseInt(rows.getText()),Integer.parseInt(cols.getText()));
d.setVisible(true);
}
});*/
add("South",b);
}
/*public boolean handleEvent(Event evt) {
if(evt.id == Event.WINDOW_DESTROY)
System.exit(0);
else
return super.handleEvent(evt);
return true;
}*/

/*public boolean action(Event evt, Object arg) {
if(arg.equals("go")) {
Dialog d = new ToeDialog(this,Integer.parseInt(rows.getText()),Integer.parseInt(cols.getText()));
//d.show();
d.setVisible(true);
}
else
return super.action(evt, arg);
return true;
}*/

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Frame f = new ToeTest();
f.setSize(200,100);
f.setVisible(true);

f.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

}
}
我在编译的时候,程序在这两处报了警告,请问我如何把这两处的代码换成新的消息机制.
...全文
222 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
malligator 2006-12-18
  • 打赏
  • 举报
回复
(第一处) 没发现
(第二处)
handleEvent
@Deprecated
public boolean handleEvent(Event evt)已过时。 从 JDK version 1.1 开始,由 processEvent(AWTEvent) 取代。
ycx111 2006-12-17
  • 打赏
  • 举报
回复
??
haisenmai 2006-12-16
  • 打赏
  • 举报
回复
没有问题可以运行啊
ycx111 2006-12-16
  • 打赏
  • 举报
回复
???
luyang1016 2006-12-16
  • 打赏
  • 举报
回复
jf
fafa2006cici 2006-12-16
  • 打赏
  • 举报
回复
?????????
ycx111 2006-12-15
  • 打赏
  • 举报
回复
???
ycx111 2006-12-15
  • 打赏
  • 举报
回复
???

62,614

社区成员

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

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