tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
3023
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Fu-Schnickens Fu-Schnickens ist offline Rookie
    Registriert seit
    Jun 2005
    Beiträge
    5
    Hallo,
    vieleicht weiss einer von euch weiter, wie ich die line löschen und die default ansicht behalten kann.
    Gruss
    Fu

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    
    import java.awt.Color;
    import java.awt.Graphics;
     
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
     
    import javax.swing.JPanel;
    import javax.swing.JButton;
        
    public class DrawAndDelLine extends JPanel {
     
            private Point a;
        private Point b;
        private boolean isMouseClicked = false;
        private JButton jButton = null;
     
        private JButton getJButton() {
            if (jButton == null) {
                jButton = new JButton();
                jButton.setBounds(new java.awt.Rectangle(52,36,168,24));
                jButton.setText("clear last line");
                jButton.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent e) {         
                        repaint();
                    }
                });
            }
            return jButton;
        }
     
     
        public DrawAndDelLine() {
            super();
            initialize();
        }
        
        private void initialize() {
            this.setLayout(null);
            this.setSize(500, 400);
            this.add(getJButton(), null);
            this.addMouseListener(new MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent e) {
                    if (isMouseClicked){
                        b = e.getPoint();
                        repaint();                  
                    }
                    else{
                        a = e.getPoint();
                        isMouseClicked = true;
                    }
                }       
            });
        }
        
        public void paint(Graphics g) {
            Color oColor = this.getBackground();
                    
            if (a != null && b != null){
                
                if (isMouseClicked) {
                    isMouseClicked = false;                     
                    g.setColor(Color.BLUE);
                    g.drawLine(a.x, a.y, b.x, b.y); 
                }else{          
                    g.setColor(this.getBackground());
                    g.drawLine(a.x, a.y, b.x, b.y);
                }   
                    
            }
            //g.clearRect(0,0,100,100);
            //this.setBackground(oColor);
            this.paintChildren(g);
            //this.paintComponents(g);
        }
     

  2. #2
    Fu-Schnickens Fu-Schnickens ist offline Rookie
    Registriert seit
    Jun 2005
    Beiträge
    5
    danke, ich habs hinbekommen
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    
        
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
     
        /**
         * @author Darimont
         * 
         * TODO Explain me
         */
        public class RectanglePaintingExample extends JFrame {
            private Point a;
            private Point b;
            private Point aOld;
            private Point bOld;
            private Color BackColor;
            private JButton jButton = null;
            /**
             * This method initializes jButton  
             *  
             * @return javax.swing.JButton  
             */
            private JButton getJButton() {
                if (jButton == null) {
                    jButton = new JButton();
                    jButton.setBounds(new java.awt.Rectangle(52,36,168,24));
                    jButton.setText("clear last line");
                    
                }
                return jButton;
            }
            
            public RectanglePaintingExample() {
                super("RectanglePaintingExample");
                this.setLayout(null);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                this.add(getJButton(), null);
                BackColor = this.getBackground();
                setSize(640, 480);
                addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent e) {
                        a = e.getPoint();
                    }               
                    public void mouseReleased(MouseEvent e) {
                        a = null;
                    }
                });
     
                addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseDragged(MouseEvent e) {
                        Point b = e.getPoint();
     
                        if (a != null && b != null){
                            Graphics g = getGraphics();
                            //g.clearRect(0, 0, 640, 480);
                            if (aOld != null && bOld != null){
                                g.setColor(BackColor);
                                g.drawLine(aOld.x, aOld.y, bOld.x, bOld.y);
                            }   
                            g.setColor(Color.BLACK);
                            g.drawLine(a.x, a.y, b.x, b.y);
                            
                            aOld = a;
                            bOld = b;
     
                            
                        }
                    }
                });
     
                
     
                setVisible(true);
            }
     
            public static void main(String[] args) {
                new RectanglePaintingExample();
                
            }
     

Ähnliche Themen

  1. Div-Box am oberen Rand setzen
    Von Duellking im Forum CSS
    Antworten: 3
    Letzter Beitrag: 12.08.09, 14:30
  2. DrawLine in Bitmap konvertieren und vergrössern
    Von alex-test im Forum .NET Grafik und Sound
    Antworten: 2
    Letzter Beitrag: 20.12.07, 17:44
  3. [VC++] Zeichenbefehle? Bessere anstelle von drawLine usw...
    Von the incredible Leitman im Forum VisualStudio & MFC
    Antworten: 39
    Letzter Beitrag: 20.02.07, 18:34
  4. Kleines Tool welches Linken Kanal nach Verzögerung auch rechts abspielt?
    Von Schwarzer Riese im Forum Audiotechnik, Recording & Audio-Software
    Antworten: 5
    Letzter Beitrag: 04.10.05, 14:23
  5. Tabellenausrichtung am oberen Rand
    Von illpsycholli im Forum HTML & XHTML
    Antworten: 2
    Letzter Beitrag: 25.09.05, 20:12