Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPanel不绘画_Java_Swing_Jpanel_Paint_Repaint - Fatal编程技术网

Java JPanel不绘画

Java JPanel不绘画,java,swing,jpanel,paint,repaint,Java,Swing,Jpanel,Paint,Repaint,我遇到了一个相当奇怪的问题——只要点击一个按钮,程序就会初始化一个新的JPanel对象,并试图立即绘制它。在repaint()之后,它将打开服务器的套接字并执行一些交互。我遇到的问题是,repaint()直到套接字交互完成后才会绘制屏幕。这是密码 创建GameGUI JPanel对象 this.startmenu.setVisible(false); //startmenu is what the user looks at prior to clicking the button this.g

我遇到了一个相当奇怪的问题——只要点击一个按钮,程序就会初始化一个新的JPanel对象,并试图立即绘制它。在repaint()之后,它将打开服务器的套接字并执行一些交互。我遇到的问题是,repaint()直到套接字交互完成后才会绘制屏幕。这是密码

创建GameGUI JPanel对象

this.startmenu.setVisible(false);
//startmenu is what the user looks at prior to clicking the button
this.game = new GameGUI(this, this.saver,
                        new Player(this.startmenu.getPlayerDataSelection()), in);
this.game.run();//performs the socket interactions
this.game = new PlayingFieldGUI();
//this is a panel inside the panel
this.setLayout(new FlowLayout());
//just need game panel and users panel side by side
this.add(this.game);
this.client.add(this);//client is the jpanel that holds this
this.setVisible(true);
this.game.setVisible(true);
this.client.repaint();//attempting to repaint
构建gameguijpanel对象

this.startmenu.setVisible(false);
//startmenu is what the user looks at prior to clicking the button
this.game = new GameGUI(this, this.saver,
                        new Player(this.startmenu.getPlayerDataSelection()), in);
this.game.run();//performs the socket interactions
this.game = new PlayingFieldGUI();
//this is a panel inside the panel
this.setLayout(new FlowLayout());
//just need game panel and users panel side by side
this.add(this.game);
this.client.add(this);//client is the jpanel that holds this
this.setVisible(true);
this.game.setVisible(true);
this.client.repaint();//attempting to repaint
run()
函数为
GameGUI
绘制背景。完成套接字调用后,它会正确地绘制背景。如果我要在交互过程中杀死套接字与服务器交互的服务器,那么在GAMGUI构建中应该发生一个异常抛出事件。

< P>考虑发布一个,没有它,很难说是什么问题。但是,根据您的描述,您可能正在使用套接字交互阻止事件调度线程(EDT)

repaint()
仅计划组件更新,不会立即触发
paint()
。绘画发生在EDT上,所以若你们阻止了EDT,那个么你们就是在干扰绘画机制

考虑使用辅助线程来处理长时间运行的任务。请看,它就是为此而设计的。另外,有关EDT的更多详细信息,请参阅

考虑发布一篇文章,没有它,很难说问题出在哪里。但是,根据您的描述,您可能正在使用套接字交互阻止事件调度线程(EDT)

repaint()
仅计划组件更新,不会立即触发
paint()
。绘画发生在EDT上,所以若你们阻止了EDT,那个么你们就是在干扰绘画机制


考虑使用辅助线程来处理长时间运行的任务。请看,它就是为此而设计的。另外,有关EDT的更多详细信息,请参阅

为了确保我理解正确,您需要在网络上启动连接以初始化对象,然后将其添加到面板,然后重新绘制。如果是这样的话,你就不能消费你还不可用的东西。不,我只是在画一些我可用的东西,执行一个无关的网络动作,然后画一些其他的东西。第一次绘制没有完成。这是一个正在进行的操作。为了确保我正确理解您的意思,您需要在网络上启动一个连接来初始化一个对象,然后将其添加到面板中,然后重新绘制。如果是这样的话,你就不能消费你还不可用的东西。不,我只是在画一些我可用的东西,执行一个无关的网络动作,然后画一些其他的东西。第一道漆不透,这是一道工序。