Results 1 to 3 of 3
- 04-03-2012, 10:15 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Drawing with the mouse in the same frame as swing components
Hi - I can't find anything on the internet to help with this.
Any help or suggestions will be greatly appreciated!
I have a frame with swing components (Jbuttons) and two different classes with logical gate drawings..

I want to be able to draw with the mouse on the same panel as these logical gates:
The below works fine if I take super.paint(g) out, but then the lightweight components mess up, I can only have it one way or the other..
Is there any way around this?
Java Code://Class to display gates to screen: class DrawCanvas extends JPanel implements MouseMotionListener { public DrawCanvas() { addMouseMotionListener(this); //setOpaque(false); setVisible(true); } public void paint(Graphics g) { super.paint(g); //<---- setBackground(Color.gray); System.out.println("Painting the screen"); //Display my AND/OR gate drawing: if (bAnd == true) { System.out.println("And gate has been drawn!"); andDisplay.andGraf(g); } if (bOr == true) { System.out.println("Or gate has been drawn!"); orDisplay.OrGraf(g); } //Draw Continuous line: g.setColor(drawingColour); g.fillRect(mx1,my1, 5, 5); } //Continuous drawing: (works without super.paint) public void mouseDragged(MouseEvent e) { mouseMoved(e); repaint(); } public void mouseMoved(MouseEvent e) { mx1 = (int) e.getPoint().getX(); my1 = (int) e.getPoint().getY(); System.out.println("x = " + mx1); System.out.println("y = " + my1); } }
Thanks.Last edited by StillCantPlay; 04-03-2012 at 10:30 PM. Reason: Important bit's in bold
-
Re: Drawing with the mouse in the same frame as swing components
You will want to search this forum, as there are many examples of how to draw. For example:
- 04-07-2012, 12:12 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Repositioning components based on mouse position
By robbie.26 in forum AWT / SwingReplies: 3Last Post: 06-21-2011, 06:55 AM -
Help with drawing a string using mouse events
By ptuckley in forum AWT / SwingReplies: 2Last Post: 12-14-2010, 11:09 AM -
adding components to frame
By roaan in forum New To JavaReplies: 4Last Post: 07-05-2009, 03:30 PM -
drawing with mouse
By aveek in forum Java 2DReplies: 1Last Post: 06-27-2009, 01:38 PM -
drawing points with mouse
By josephdcoleman in forum New To JavaReplies: 4Last Post: 03-03-2009, 12:39 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks