<small id='FNtsI'></small><noframes id='FNtsI'>

    <bdo id='FNtsI'></bdo><ul id='FNtsI'></ul>

      <legend id='FNtsI'><style id='FNtsI'><dir id='FNtsI'><q id='FNtsI'></q></dir></style></legend>
    1. <i id='FNtsI'><tr id='FNtsI'><dt id='FNtsI'><q id='FNtsI'><span id='FNtsI'><b id='FNtsI'><form id='FNtsI'><ins id='FNtsI'></ins><ul id='FNtsI'></ul><sub id='FNtsI'></sub></form><legend id='FNtsI'></legend><bdo id='FNtsI'><pre id='FNtsI'><center id='FNtsI'></center></pre></bdo></b><th id='FNtsI'></th></span></q></dt></tr></i><div id='FNtsI'><tfoot id='FNtsI'></tfoot><dl id='FNtsI'><fieldset id='FNtsI'></fieldset></dl></div>
        <tfoot id='FNtsI'></tfoot>

      1. 如何在Java中绘制一个实心圆?

        时间:2023-05-28
        <i id='Dc63b'><tr id='Dc63b'><dt id='Dc63b'><q id='Dc63b'><span id='Dc63b'><b id='Dc63b'><form id='Dc63b'><ins id='Dc63b'></ins><ul id='Dc63b'></ul><sub id='Dc63b'></sub></form><legend id='Dc63b'></legend><bdo id='Dc63b'><pre id='Dc63b'><center id='Dc63b'></center></pre></bdo></b><th id='Dc63b'></th></span></q></dt></tr></i><div id='Dc63b'><tfoot id='Dc63b'></tfoot><dl id='Dc63b'><fieldset id='Dc63b'></fieldset></dl></div>
                <tbody id='Dc63b'></tbody>
              <legend id='Dc63b'><style id='Dc63b'><dir id='Dc63b'><q id='Dc63b'></q></dir></style></legend>
              <tfoot id='Dc63b'></tfoot>
                <bdo id='Dc63b'></bdo><ul id='Dc63b'></ul>

                <small id='Dc63b'></small><noframes id='Dc63b'>

                  本文介绍了如何在Java中绘制一个实心圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有网格布局的 JPanel.在网格的单元格"中,我可以放置不同的元素(例如 JButtons).没有问题.但现在我想在一些单元格中放置一个实心圆圈.我还想将 ActionListener 与这些圈子联系起来.更详细地说,如果我单击圆圈,它将从当前单元格中消失并出现在另一个单元格中.我怎样才能在Java中做到这一点?我正在使用 Swing.

                  I have a JPanel with a Grid Layout. In the "cells" of the grid I can put different elements (for example JButtons). There is no problems with that. But now I want to put a filled circle in some of the cells. I also would like to relate an ActionListener with these circles. In more details, if I click the circle it disappears from the current cell and appears in another one. How can I do it in Java? I am using Swing.

                  推荐答案

                  public void paintComponent(Graphics g) {
                     super.paintComponent(g);
                     Graphics2D g2d = (Graphics2D)g;
                     // Assume x, y, and diameter are instance variables.
                     Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter);
                     g2d.fill(circle);
                     ...
                  }
                  

                  这里有一些关于paintComponent 的文档(链接).

                  Here are some docs about paintComponent (link).

                  您应该在 JPanel 中覆盖该方法并执行类似于上面代码片段的操作.

                  You should override that method in your JPanel and do something similar to the code snippet above.

                  在您的 ActionListener 中,您应该指定 x, y, diameter 并调用 repaint().

                  In your ActionListener you should specify x, y, diameter and call repaint().

                  这篇关于如何在Java中绘制一个实心圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何计算两个角度测量值的差异? 下一篇:Java中是否有像Rectangle类这样的circle类

                  相关文章

                    • <bdo id='5aVda'></bdo><ul id='5aVda'></ul>

                      <small id='5aVda'></small><noframes id='5aVda'>

                      <legend id='5aVda'><style id='5aVda'><dir id='5aVda'><q id='5aVda'></q></dir></style></legend>
                    1. <tfoot id='5aVda'></tfoot>
                      <i id='5aVda'><tr id='5aVda'><dt id='5aVda'><q id='5aVda'><span id='5aVda'><b id='5aVda'><form id='5aVda'><ins id='5aVda'></ins><ul id='5aVda'></ul><sub id='5aVda'></sub></form><legend id='5aVda'></legend><bdo id='5aVda'><pre id='5aVda'><center id='5aVda'></center></pre></bdo></b><th id='5aVda'></th></span></q></dt></tr></i><div id='5aVda'><tfoot id='5aVda'></tfoot><dl id='5aVda'><fieldset id='5aVda'></fieldset></dl></div>