建立一个point,一个jbutton
每次点击jbutton,这个点会随即的跑到另外一个地方
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class pointTest
{
pointTest(){
JFrame myjf=new JFrame("pointTest");
JPanel myjp=new JPanel();
Point myp=new Point(3,5);
JButton myjb=new JButton("Click me");
myjb.addActionListener(new myactionlistener());
myjf.add(myjb);
myjp.add(myp);//编译器提示好像是说在JPanel中不能添加Point,那这个应该添加在哪个容器里面啊
myjf.add(myjp);
myjf.setLayout(new FlowLayout());
myjf.setVisible(true);
}
public class myactionlistener implements ActionListener
{
public void actionPerformed(ActionEvent e){
Random myr=new Random();
int i=myr.nextInt(20);
int j=myr.nextInt(30);
myp.move(i,j);//编译器说找不到myp这个符号;为啥,解释下?作用域问题?????
}
};
public static void main(String[] args){
new pointTest();
}
};
[求助]point小问题