ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
3023
3023
EMPFEHLEN
-
10.01.06 23:36 #1
- 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); }
-
11.01.06 00:48 #2
- 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
-
Div-Box am oberen Rand setzen
Von Duellking im Forum CSSAntworten: 3Letzter Beitrag: 12.08.09, 14:30 -
DrawLine in Bitmap konvertieren und vergrössern
Von alex-test im Forum .NET Grafik und SoundAntworten: 2Letzter Beitrag: 20.12.07, 17:44 -
[VC++] Zeichenbefehle? Bessere anstelle von drawLine usw...
Von the incredible Leitman im Forum VisualStudio & MFCAntworten: 39Letzter Beitrag: 20.02.07, 18:34 -
Kleines Tool welches Linken Kanal nach Verzögerung auch rechts abspielt?
Von Schwarzer Riese im Forum Audiotechnik, Recording & Audio-SoftwareAntworten: 5Letzter Beitrag: 04.10.05, 14:23 -
Tabellenausrichtung am oberen Rand
Von illpsycholli im Forum HTML & XHTMLAntworten: 2Letzter Beitrag: 25.09.05, 20:12





Zitieren
Login





