问题是为什么我点击一下按钮,就会在左上方也出现个按钮,很奇怪,怎么出现的,怎么去掉啊?效果如下:
(该死的这里不能贴图)
http://www.roboticfan.com/blog/user_2005/104/archives/2006/20063420851.shtml
(请不要问我为什么要这么写代码,因为我本来是要把程序用于视频捕捉的,现在我把一些无关的代码都去掉了,几乎就剩下个框架和一个bug,可以方便你们)
源代码有三个类,videoFrame是主类:import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VideoPanel extends JPanel implements Runnable {
private Thread show = null; private boolean bPlay = false; public VideoPanel() { } public void paintComponent(Graphics g) {
g.draw3DRect(5, 5, 50, 50, true);
}
public void run() { while (bPlay == true) {
repaint();//调用paintComponent() }
} public void play() { if (show == null) { show = new Thread(this);
bPlay = true;
show.start();
}
}}
public class VideoPane extends JPanel implements ActionListener {
private VideoPanel videopanel; private JButton onBtn;
public VideoPane() {
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
onBtn = new JButton("ON");
onBtn.addActionListener(this);
videopanel = new VideoPanel();
this.add(videopanel);
this.add(onBtn);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == onBtn) {
videopanel.play();
}
}
}public class VideoFrame extends JFrame  { public VideoFrame() {
super("Video Frame");
setSize(600, 400);
VideoPane pane = new VideoPane();
setContentPane(pane);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {

VideoFrame videoFrame=new VideoFrame();

}}