我的GUI程序怎么了,大家帮我看看可以吗,很简单的一个问题?问题接贴马上给分
问题是为什么我点击一下按钮,就会在左上方也出现个按钮,很奇怪,怎么出现的,怎么去掉啊?效果如下:
(该死的这里不能贴图)
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();
}
}
问题点数:20、回复次数:3Top
1 楼gtlang78()回复于 2006-03-04 20:28:40 得分 20
把
public void paintComponent(Graphics g) {
g.draw3DRect(5, 5, 50, 50, true);
}
改成
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.draw3DRect(5, 5, 50, 50, true);
}
Top
2 楼jiangguilong2000(流子)回复于 2006-03-04 20:34:02 得分 0
先谢谢你啊,给个理由先啊,为什么我的程序会出现毛病,而加了这句就解决了?Top
3 楼jiangguilong2000(流子)回复于 2006-03-04 20:36:32 得分 0
高手,我QQ是41157121,你的是多少?我想听你好好指教一下,可以吗?Top




