久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='miYop'></tfoot>
<i id='miYop'><tr id='miYop'><dt id='miYop'><q id='miYop'><span id='miYop'><b id='miYop'><form id='miYop'><ins id='miYop'></ins><ul id='miYop'></ul><sub id='miYop'></sub></form><legend id='miYop'></legend><bdo id='miYop'><pre id='miYop'><center id='miYop'></center></pre></bdo></b><th id='miYop'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='miYop'><tfoot id='miYop'></tfoot><dl id='miYop'><fieldset id='miYop'></fieldset></dl></div>
    <bdo id='miYop'></bdo><ul id='miYop'></ul>

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

      1. <legend id='miYop'><style id='miYop'><dir id='miYop'><q id='miYop'></q></dir></style></legend>

        java swing應(yīng)用程序中如何保留和刪除多個圖形對象

        How to keep and remove multiple graphic objects in java swing applications?(java swing應(yīng)用程序中如何保留和刪除多個圖形對象?)
            <legend id='ZHUyw'><style id='ZHUyw'><dir id='ZHUyw'><q id='ZHUyw'></q></dir></style></legend>
          • <tfoot id='ZHUyw'></tfoot>

            <i id='ZHUyw'><tr id='ZHUyw'><dt id='ZHUyw'><q id='ZHUyw'><span id='ZHUyw'><b id='ZHUyw'><form id='ZHUyw'><ins id='ZHUyw'></ins><ul id='ZHUyw'></ul><sub id='ZHUyw'></sub></form><legend id='ZHUyw'></legend><bdo id='ZHUyw'><pre id='ZHUyw'><center id='ZHUyw'></center></pre></bdo></b><th id='ZHUyw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZHUyw'><tfoot id='ZHUyw'></tfoot><dl id='ZHUyw'><fieldset id='ZHUyw'></fieldset></dl></div>
                <tbody id='ZHUyw'></tbody>
            • <small id='ZHUyw'></small><noframes id='ZHUyw'>

                • <bdo id='ZHUyw'></bdo><ul id='ZHUyw'></ul>
                  本文介紹了java swing應(yīng)用程序中如何保留和刪除多個圖形對象?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個圖像,我在其上使用預(yù)定義的位置來創(chuàng)建具有顏色的圖形對象.通過單擊鼠標(biāo),我嘗試在其上創(chuàng)建一些帶有顏色的橢圓.其實(shí)我達(dá)不到這個目的.因?yàn)?,?dāng)我單擊預(yù)定義位置時,我可以在其上創(chuàng)建一個橢圓,但是當(dāng)我單擊另一個預(yù)定義位置時,第一個橢圓消失了.

                  I have an image and I use pre-defined positions on it to create graphic objects with colors . With a mouse click I try to create some ovals on it with colors . Actually I couldn't achieve this objective. Because , when I click on a pre-defined position I could create an oval on it but when I click on another pre-defined position first oval has gone.

                  一個橢圓可以通過點(diǎn)擊兩次來移除.

                  An oval can be removed by click on it twice.

                  看看這個,

                  public class PrintDialog extends javax.swing.JDialog{
                  private int count = 0;
                  private int count_1 = 0;
                  
                  /**
                   * Creates new form PrintFeetDialog
                   */
                  public PrintDialog(java.awt.Frame parent, boolean modal)
                  {
                      super(parent, modal);
                      initComponents();
                      ImagePanel panel = new ImagePanel("Areas.jpg");
                      this.getContentPane().add(panel);
                      this.setResizable(false);
                      this.setLocationRelativeTo(panel);
                      this.pack();
                  }
                  
                  private void formMouseClicked(java.awt.event.MouseEvent evt)                                  
                  {                                      
                      // TODO add your handling code here:
                      System.out.println("Print y - " + evt.getY());
                      System.out.println("Print x - " + evt.getX());
                  
                      if ((evt.getX() >= 68 && evt.getX() <= 84) && (evt.getY() >= 44 && evt.getY() <= 72))
                      {
                          Graphics g = getGraphics();
                          count++;
                          if (count == 1)
                          {
                              g.setColor(Color.red);
                              g.fillOval(66, 52, 20, 20);
                              //  repaint();
                          } else if (count > 1)
                          {
                              g.setColor(new Color(-3692899));
                              g.fillOval(66, 52, 20, 20);
                              repaint();
                              count = 0;
                          }
                          g.dispose();
                      }
                  
                      if ((evt.getX() >= 137 && evt.getX() <= 157) && (evt.getY() >= 50 && evt.getY() <= 75))
                      {
                          Graphics g1 = getGraphics();
                          count_1++;
                          if (count_1 == 1)
                          {
                              g1.setColor(Color.RED);
                              g1.fillOval(137, 54, 20, 20);
                          } else if (count_1 > 1)
                          {
                              g1.setColor(new Color(-3692899));
                              g1.fillOval(66, 52, 20, 20);
                              repaint();
                              count_1 = 0;
                          }
                          g1.dispose();
                      }
                  }
                  }   
                  

                  圖像面板類

                  public class ImagePanel extends JPanel{
                  
                  private Image img;
                  
                  public ImagePanel(String img, String str)
                  {
                      //this(new ImageIcon(img).getImage());    
                  }
                  
                  public ImagePanel(String path)
                  {
                      Image img = new ImageIcon(path).getImage();
                      this.img = img;
                      Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                      setPreferredSize(size);
                      setMinimumSize(size);
                      setMaximumSize(size);
                      setSize(size);
                      setLayout(null);
                  
                       try
                      {
                          BufferedImage image = ImageIO.read(new File(path));
                          int rgb = image.getRGB(66, 52);
                          System.out.println("Colour is: "+rgb);
                      }
                      catch(IOException e)
                      {
                          e.printStackTrace();
                      }
                  }
                  
                  public void paintComponent(Graphics g)
                  {
                      super.paintComponent(g);
                      g.drawImage(img, 0, 0, null);
                  }
                  }
                  

                  有什么想法嗎?

                  謝謝.

                  推薦答案

                  不要使用 getGraphics,這不是自定義繪畫的工作方式,請參閱 在 AWT 和 Swing 中繪畫 和 執(zhí)行自定義繪畫了解更多詳情

                  Don't use getGraphics, this is not how custom painting works, see Painting in AWT and Swing and Performing Custom Painting for more details

                  基本思想是,您需要某種List,在其中添加每個形狀.當(dāng) mouseClicked 發(fā)生時,您遍歷列表并檢查鼠標(biāo)單擊是否出現(xiàn)了其中一個形狀,如果是,則從 List 中刪除該形狀,如果不是,您在單擊它的位置創(chuàng)建一個新形狀并將其添加到 List.

                  The basic idea is, you need some kind of List, into which you add each shape. When the mouseClicked occurs, you iterate through list and check to see if the mouse clicked occur one of the shapes, if it was, you remove the shape from the List, if not, you create a new shape at the point it was clicked and add it to the List.

                  然后,您可以在 paintComponent 方法中使用此 List 來物理繪制形狀.

                  You then use this List inside the paintComponent method to physically paint the shapes.

                  此示例擴(kuò)展了您的 ImagePanel 添加自定義繪畫

                  This example extends your ImagePanel adding in the custom painting

                  import java.awt.Color;
                  import java.awt.Dimension;
                  import java.awt.EventQueue;
                  import java.awt.Graphics;
                  import java.awt.Graphics2D;
                  import java.awt.Image;
                  import java.awt.Shape;
                  import java.awt.event.MouseAdapter;
                  import java.awt.event.MouseEvent;
                  import java.awt.geom.Ellipse2D;
                  import java.awt.image.BufferedImage;
                  import java.io.File;
                  import java.io.IOException;
                  import java.util.ArrayList;
                  import java.util.Iterator;
                  import java.util.List;
                  import javax.imageio.ImageIO;
                  import javax.swing.ImageIcon;
                  import javax.swing.JFrame;
                  import javax.swing.JPanel;
                  import javax.swing.UIManager;
                  import javax.swing.UnsupportedLookAndFeelException;
                  
                  public class Test {
                  
                      public static void main(String[] args) {
                          new Test();
                      }
                  
                      public Test() {
                          EventQueue.invokeLater(new Runnable() {
                              @Override
                              public void run() {
                                  try {
                                      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                      ex.printStackTrace();
                                  }
                  
                                  JFrame frame = new JFrame("Testing");
                                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                  frame.add(new DrawPane("/Volumes/Disk02/Dropbox/MegaTokyo/thumnails/0.jpg"));
                                  frame.pack();
                                  frame.setLocationRelativeTo(null);
                                  frame.setVisible(true);
                              }
                          });
                      }
                  
                      public class ImagePanel extends JPanel {
                  
                          private Image img;
                  
                          public ImagePanel(String img, String str) {
                              //this(new ImageIcon(img).getImage());    
                          }
                  
                          public ImagePanel(String path) {
                              Image img = new ImageIcon(path).getImage();
                              this.img = img;
                              try {
                                  BufferedImage image = ImageIO.read(new File(path));
                                  int rgb = image.getRGB(66, 52);
                                  System.out.println("Colour is: " + rgb);
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                          }
                  
                          @Override
                          public Dimension getPreferredSize() {
                              return img == null ? new Dimension(200, 200) : new Dimension(img.getWidth(this), img.getHeight(this));          
                          }
                  
                          @Override
                          public void paintComponent(Graphics g) {
                              super.paintComponent(g);
                              g.drawImage(img, 0, 0, null);
                          }
                      }
                  
                      public class DrawPane extends ImagePanel {
                  
                          private List<Shape> shapes;
                  
                          public DrawPane(String img, String str) {
                              super(img, str);
                              init();
                          }
                  
                          public DrawPane(String path) {
                              super(path);
                              init();
                          }
                  
                          protected void init() {
                              shapes = new ArrayList<>(25);
                              addMouseListener(new MouseAdapter() {
                                  @Override
                                  public void mouseClicked(MouseEvent e) {
                                      boolean clicked = false;
                                      Iterator<Shape> it = shapes.iterator();
                                      while (it.hasNext()) {
                                          Shape shape = it.next();
                                          if (shape.contains(e.getPoint())) {
                                              it.remove();
                                              clicked = true;
                                              break;
                                          }
                                      }
                                      if (!clicked) {
                                          shapes.add(new Ellipse2D.Double(e.getX() - 10, e.getY() - 10, 20, 20));
                                      }
                                      repaint();
                                  }
                  
                              });
                          }
                  
                          @Override
                          public void paintComponent(Graphics g) {
                              super.paintComponent(g); 
                              Graphics2D g2d = (Graphics2D) g.create();
                              g2d.setColor(Color.RED);
                              for (Shape shape : shapes) {
                                  g2d.draw(shape);
                              }
                              g2d.dispose();
                          }
                  
                      }
                  
                  }
                  

                  這篇關(guān)于java swing應(yīng)用程序中如何保留和刪除多個圖形對象?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)
                    <tfoot id='B644I'></tfoot><legend id='B644I'><style id='B644I'><dir id='B644I'><q id='B644I'></q></dir></style></legend>

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

                          <tbody id='B644I'></tbody>
                      1. <i id='B644I'><tr id='B644I'><dt id='B644I'><q id='B644I'><span id='B644I'><b id='B644I'><form id='B644I'><ins id='B644I'></ins><ul id='B644I'></ul><sub id='B644I'></sub></form><legend id='B644I'></legend><bdo id='B644I'><pre id='B644I'><center id='B644I'></center></pre></bdo></b><th id='B644I'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='B644I'><tfoot id='B644I'></tfoot><dl id='B644I'><fieldset id='B644I'></fieldset></dl></div>

                        • <bdo id='B644I'></bdo><ul id='B644I'></ul>

                          • 主站蜘蛛池模板: 日韩毛片免费看 | 91精品国产色综合久久不卡蜜臀 | 美女日皮网站 | 亚洲性在线 | 精品视频在线播放 | 一区二区三区四区免费观看 | 国产视频线观看永久免费 | 国产一区二区在线免费播放 | 一a级片 | 日韩成人性视频 | 久久亚洲精品久久国产一区二区 | 精产国产伦理一二三区 | 97av视频| 91在线电影 | 国产欧美日韩一区 | 国产高清精品一区二区三区 | 日本一区二区三区在线观看 | 九九热在线免费视频 | 午夜爽爽爽男女免费观看 | 成人午夜毛片 | 91国产视频在线 | 国产午夜精品一区二区三区嫩草 | 国产精品日韩一区 | 午夜久久久久久久久久一区二区 | 成人免费三级电影 | 欧美日韩综合视频 | 免费观看的av毛片的网站 | 一区二区三区中文字幕 | 亚洲一页 | 国产精品免费一区二区三区四区 | 草草视频在线观看 | 视频一区二区在线观看 | 欧美成视频在线观看 | 亚洲福利一区二区 | 大乳boobs巨大吃奶挤奶 | 性生生活大片免费看视频 | 成人一区二区三区在线观看 | 亚卅毛片| 在线观看av中文字幕 | 精品美女在线观看视频在线观看 | 国产欧美日韩视频 |