当浏览器窗口最小化或调整大小时,Applet 出现问题

发布于 2024-09-13 01:32:26 字数 1009 浏览 3 评论 0原文

我制作了一个带有一些面板的小程序。 我用我创建的特定方法在面板上绘制一些东西,它们使用图形对象来绘制。
为了绘图,我使用如下命令:

gr = this.getGraphics;  
gr.drawString... etc  

然后我从小程序类中调用这些方法。
我的问题如下:在我最小化或调整浏览器窗口大小后,面板不
显示任何内容,我想这是因为我没有在面板的 paint() 方法中实现任何内容。
有没有办法在不改变我所有方法的情况下解决这个问题?

我的一些方法是这样的:

//paint a node with coords x,y and nodeNumber in the center of the node
public void paintNode(int x,int y,Integer numberOfNode){

    gr = this.getGraphics();
    gr.setColor(ShowGUI.getPanelColor());
    gr.fillOval(x,y,40,40);
    gr.setColor(Color.BLACK);
    gr.drawOval(x,y,40,40);
    gr.drawString(numberOfNode.toString(),x+17,y+25);

}

//marks red the processing edge
public void markEdge(int x1,int y1,int x2,int y2,Integer numberOfNode1,Integer numberOfNode2,int weight){

    gr.setColor(Color.red);
    this.paintEdge(x1,y1,x2,y2,numberOfNode1,numberOfNode2,weight);
    this.paintNode(x1, y1, numberOfNode1);
    this.paintNode(x2, y2, numberOfNode2);

}

I made an Applet with some Panels on it.
I draw something on a panel with specific methods I created, they use a graphics object to draw.
To draw I use commands like:

gr = this.getGraphics;  
gr.drawString... etc  

Then I call these methods from the applet class.
My problem is the following: After I minimize or resize the browser window the panel does not
show anything, I suppose it's because I didn't implement anything in the paint() method of the panel.
Is there an way to fix that problem without changing all my methods?

Some of my methods are like that:

//paint a node with coords x,y and nodeNumber in the center of the node
public void paintNode(int x,int y,Integer numberOfNode){

    gr = this.getGraphics();
    gr.setColor(ShowGUI.getPanelColor());
    gr.fillOval(x,y,40,40);
    gr.setColor(Color.BLACK);
    gr.drawOval(x,y,40,40);
    gr.drawString(numberOfNode.toString(),x+17,y+25);

}

//marks red the processing edge
public void markEdge(int x1,int y1,int x2,int y2,Integer numberOfNode1,Integer numberOfNode2,int weight){

    gr.setColor(Color.red);
    this.paintEdge(x1,y1,x2,y2,numberOfNode1,numberOfNode2,weight);
    this.paintNode(x1, y1, numberOfNode1);
    this.paintNode(x2, y2, numberOfNode2);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浸婚纱 2024-09-20 01:32:26

当窗口最小化和最大化时,您需要调用Panel上的update()/repaint()方法。

您将需要重写小程序的 start() 方法并向其添加 repaint() 。
start() 的定义:

public void start():
这是在“init”事件之后调用的。当用户不使用您的小程序并开始再次使用它时,例如当包含您的小程序的最小化浏览器最大化时,也会调用它。

您的代码应如下所示:

public void start(){
    super.start();
    this.repaint();
}

希望这会有所帮助。

You need to call update()/repaint() methods on Panel when window is minimized and maximized.

You will need to override start() method of applet and add repaint() to it.
Defination for start():

public void start():
This is called after the "init" event. It is also called at times when the user is not using your applet and starts to use it again such as when a minimized browser containning your applet is maximized.

Here is how you code should look:

public void start(){
    super.start();
    this.repaint();
}

Hope this helps.

不一样的天空 2024-09-20 01:32:26

当小程序调整大小时,图像将被清除,并调用 paint 方法重新绘制它。
目前,默认的绘制方法不知道您从 paintNode 对显示所做的更改。

正确的方法是保留要绘制的对象的列表,包括位置、颜色等任何相关信息。当用户添加/删除/更改某些内容时,列表会发生更改,并且 repaint() 被调用。然后,绘制代码需要遍历列表并将形状、文本等绘制到显示器上。

When the applet is resized, the image is cleared and the paint method is called to repaint it.
At the moment, the default paint method has no knowledge of the changes you are making to the display from paintNode.

The correct way to do this is to keep a list of the objects to be painted, including any relevant information like location, color, etc. When the user adds/removes/changes something, the list is changed and repaint() is called. The paint code then needs to walk the list and paint the shapes, text, etc to the display.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文