English 中文(简体)
A. 创建笔工具,重新铺设问题——JAVA
原标题:creating a pen tool, repainting issue - JAVA

我正试图利用摩擦听众创建一种末级工具:

public void mouseDragged(MouseEvent e) {
            imageL.setCoordinates(originalPos, e.getPoint());
            imageL.repaint();
            originalPos = e.getPoint();
        }

JLabel(imageL)的油漆功能有两套点,可以根据 mo泥提取一条线。 唯一的问题是,每当拖拉时,新一层并不包含从以前的暴动中提取的线。 JLabel的油漆功能如下:

public void paint(Graphics g) {
    super.paint(g); 
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(drawingColour);
    g2d.drawLine(originCors.x,originCors.y,endCors.x,endCors.y);
}

因此,基本上我的问题是:我如何“把新线带给目前的层?

any help would be great, Thanks in advance

问题回答

You want to draw in a JComponent s (and JLabel extends from JComponent) paintComponent method, not the paint method unless you plan to handle all the painting of the component s borders and children. Next, you may wish to have your drawing component hold an ArrayList of Point and add Points to this array list in the mouseDragged method. Then the paintComponent method can iterate through the list and paint all the lines. If all you want to do is paint one line, then have the painting JLabel hold both points in a class field.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签