c1考驾照报名费多少钱:java编程问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 15:54:52
import java.awt.*;import java.awt.event.*;
public class ex1 extends java.applet.Applet implements ActionListener
{
Button button;
Label label;
public void init()
{
button=new Button("横向走动");button.setBackground(Color.red);
button.addActionListener(this);
label=new Label("我可以被碰掉",label.CENTER);
label.setBackground(Color.yellow);
add(button);add(label);
}
public void actionPerformed(ActionEvent e)
{
Rectangle rect=button.getBounds();
if(reck.interects(label.getBounds()))
{
label.setVisible(false);
}
if(label.isVisible())
{
button.setLocation(reck.x+3,reck.y);
}
else
{
button.setLocation(reck.x,rect.y+3);
button.setLabel("纵向走动");
}
}
}

帮我改正确后,我会追加分数的,请各位高手帮帮忙,谢谢~~~~~

不知道你最终想要达到什么目的,不过看见你程序有几个地方拼写错了,帮你改了改,

import java.awt.*;import java.awt.event.*;
public class ex1 extends java.applet.Applet implements ActionListener
{
Button button;
Label label;
public void init()
{
button=new Button("横向走动");button.setBackground(Color.red);
button.addActionListener(this);
label=new Label("我可以被碰掉",label.CENTER);
label.setBackground(Color.yellow);
add(button);add(label);
}
public void actionPerformed(ActionEvent e)
{
Rectangle rect=button.getBounds();
if(rect.intersects(label.getBounds()))
{
label.setVisible(false);
}
if(label.isVisible())
{
button.setLocation(rect.x+3,rect.y);
}
else
{
button.setLocation(rect.x,rect.y+3);
button.setLabel("纵向走动");
}
}
}

import java.awt.*;
import java.awt.event.*;
public class ex1 extends java.applet.Applet implements ActionListener
{
Button button;
Label label;
public void init()
{
button=new Button("横向走动");
button.setBackground(Color.red);
button.addActionListener(this);
label=new Label("我可以被碰掉",label.CENTER);
label.setBackground(Color.yellow);
add(button);add(label);
}
public void actionPerformed(ActionEvent e)
{
Rectangle rect=button.getBounds();

//if(rect.interects())
if(rect.intersects(rect));
{
label.setVisible(false);
}
if(label.isVisible())
{
button.setLocation(rect.x+3,rect.y);
}
else
{
button.setLocation(rect.x,rect.y+3);
button.setLabel("纵向走动");
}
}
}