62,615
社区成员
发帖
与我相关
我的任务
分享
以下是程序段,我实在找不出哪里出了错,编译老是提示找不到符号,
import java.awt.*;
import javax.swing.*;
public class testpoint
{
static JButton button;
testpoint()
{
JFrame jframe=new JFrame();
button=new JButton();
jframe.getContentPane().add(button);
jframe.setSize(200,200);
button.setSize(50,50);
jframe.setVisible(true);
}
public static void main(String[] args)
{
Point p=button.getLocationOnScreen();
p=new Point(p.x+1,p.y+1);
Dimension d=new Dimension(50,50);
Rectangle rec=new Rectangle(p,d);
System.out.println(rec.x+","+rec.y+","+rec.height+","+rec.width);
}
}
/*图像采集发送线程*/
class imagecapture extends Thread
{
BufferedImage image;
Rectangle rec;
Dimension dimension;
Robot robot=new Robot();
static byte imagedata[];
DatagramPacket datapack;
Point p;
DatagramSocket senddatapack;
ByteArrayOutputStream capturestream;
InetAddress address;
/*构造方法*/
imagecapture()
{
dimension=new Dimension(300,500);
address=InetAddress.getByName(addnetuserpanel.IPtextfield.getText());
capturestream=new ByteArrayOutputStream();
}
public void run()
{
while(gamecontrol.gamestate!=0)
{
p=jframe.gamecanvas1.getLocationOnScreen();
p=new Point(p.x+1,p.y+1);
rec=new Rectangle(p,dimension);
try{
image=robot.createScreenCapture(rec);
ImageIO.write(image,"gif",capturestream);
imagedata=capturestream.toByteArray();
datapack=new DatagramPacket(imagedata,imagedata.length,address,1988);
senddatapack=new DatagramSocket(1988);
senddatapack.send(datapack);
}catch(IOException e){}
try{
sleep(gamecontrol.time);
}catch(InterruptedException e){}
imagedata=null;
}
}
}
import java.awt.*;
import javax.swing.*;
public class testpoint
{
static JButton button;
testpoint()
{
JFrame jframe=new JFrame();
button=new JButton();
jframe.getContentPane().add(button);
jframe.setSize(200,200);
button.setSize(50,50);
jframe.setVisible(true);
}
public static void main(String[] args)
{
testpoint test=new testpoint();
Point p=new Point();
p=button.getLocationOnScreen();
p=new Point(p.x+1,p.y+1);
Dimension d=new Dimension(50,50);
Rectangle rec=new Rectangle(p,d);
System.out.println(rec.x+","+rec.y+","+rec.height+","+rec.width);
}
}