Drawing line with button??
Hi all.
Why won't this class draw a line when i click the mouse button. Nothing happens when i click on the panel.
import java.util.*;
import java.awt.*;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.Action.*;
import java.awt.event.*;
import java.awt.event.MouseAdapter;
public class DrawingPanel extends JPanel implements Observer
private ViewableEtch etch;
private ClearPanel clear;
public DrawingPanel(ViewableEtch etch, ClearPanel clear)
this.etch = etch;
this.clear = clear;
etch.addView(this);
clear.addView(this);
setLayout(new FlowLayout());
setLayout(new GridLayout(200,200));
//etch.addActionListener(this);
DrawingControl dc = new DrawingControl();
public void update(Observable obs, Object obj)
Views v = (Views)obs;
if (v.getSource() == etch)
//etch.getLineColor();
getGraphics().setColor(etch.getLineColor() );
getGraphics().drawLine(etch.getStartX(), etch.getStartY(), etch.getEndX(), etch.getEndY());
else
v.getSource().equals(clear);
public void mouseClicked(MouseEvent e)
//etch.setLine(new etch(getStartX(), getStartY(), e.getEndX(), e.getEndY()));
getGraphics().drawLine(etch.getStartX(), etch.getStartY(), etch.getEndX(), etch.getEndY());
}thanx
This should work
public class MyPanel extends JPanel implements MouseListener {
public MyPanel() {
addMouseListener(this);
public void mouseClicked(MouseEvent e) {
// Add code here
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
Similar Messages
-
Can j2me draw line with double values.
Hi,
Can any body know how to darw line in j2me with double values.
I don't want use draw Line with int.
Shall i use svg or j2me has solution.
Thanks and regards,
Rakesh.not possible
graphics.drawLine(float,float,float,float);...there's no such method in MIDP API: [click here for javadoc of Graphics class methods|http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Graphics.html#drawLine(int,%20int,%20int,%20int)] -
Draw line with float values possible
Hi,
Using Canvas drawing is possible to draw line with float values.
graphics.drawLine(int,int,int,int);
graphics.drawLine(float,float,float,float);Thanks and regards,
Rakesh.not possible
graphics.drawLine(float,float,float,float);...there's no such method in MIDP API: [click here for javadoc of Graphics class methods|http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Graphics.html#drawLine(int,%20int,%20int,%20int)] -
Drawing lines with smooth curves
Hi,
I'm trying to make a map for an underground system in a PC game and I want something similar to the one Transport for London has:
http://www.tfl.gov.uk/assets/downloads/standard-tube-map.gif
I'm a total newbie with Adobe Illustrator, but I'm trying it as I've heard it's what Transport for London uses.
My question is then, what would be the easiest way of accomplishing multiple lines with different colours and smooth curves, like the lines in my reference picture?
Thanks in advance,
MartinMartin,
In addition to what Kurt said, you may draw paths with straight segments and then round the corners afterwards, using Effect>Stylise>Round Corners (you may Object>Expand Appearance to obtain actual roundings). -
How to draw line with width at my will
Dear frineds:
I have following code to draw lines, but I was required:
[1]. draw this line with some required width such as 0.2 or 0.9 or any width at my will
[2]. each line after I draw, when I use mouse to click on it, it will be selected and then I can delete it,
Please advice how to do it or any good example??
Thanks
sunny
package com.draw;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class DrawingArea extends JPanel
Vector angledLines;
Point startPoint = null;
Point endPoint = null;
Graphics g;
public DrawingArea()
angledLines = new Vector();
setPreferredSize(new Dimension(500,500));
MyMouseListener ml = new MyMouseListener();
addMouseListener(ml);
addMouseMotionListener(ml);
setBackground(Color.white);
public void paintComponent(Graphics g)
// automatically called when repaint
super.paintComponent(g);
g.setColor(Color.black);
g.setFont(getFont());
AngledLine line;
if (startPoint != null && endPoint != null)
// draw the current dragged line
g.drawLine(startPoint.x, startPoint.y, endPoint.x,endPoint.y);
for (Enumeration e = angledLines.elements(); e.hasMoreElements();)
// draw all the angled lines
line = (AngledLine)e.nextElement();
g.drawPolyline(line.xPoints, line.yPoints, line.n);
class MyMouseListener extends MouseInputAdapter
public void mousePressed(MouseEvent e)
if (SwingUtilities.isLeftMouseButton(e))
startPoint = e.getPoint();
public void mouseReleased(MouseEvent e)
if (SwingUtilities.isLeftMouseButton(e))
if (startPoint != null)
AngledLine line = new AngledLine(startPoint, e.getPoint(), true);
angledLines.add(line);
startPoint = null;
repaint();
public void mouseDragged(MouseEvent e)
if (SwingUtilities.isLeftMouseButton(e))
if (startPoint != null)
endPoint = e.getPoint();
repaint();
public void mouseClicked( MouseEvent e )
if (g == null)
g = getGraphics();
g.drawRect(10,10,20,20);
class AngledLine
// inner class for angled lines
public int[] xPoints, yPoints;
public int n = 2;
public AngledLine(Point startPoint, Point endPoint, boolean left)
xPoints = new int[n];
yPoints = new int[n];
xPoints[0] = startPoint.x;
xPoints[1] = endPoint.x;
yPoints[0] = startPoint.y;
yPoints[1] = endPoint.y;
/*if (left)
xPoints[1] = startPoint.x;
yPoints[1] = endPoint.y;
else
xPoints[1] = endPoint.x;
yPoints[1] = startPoint.y;
public static void main(String[] args)
JFrame frame = new JFrame("Test angled lines");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
DrawingArea d = new DrawingArea();
frame.getContentPane().add( d );
frame.pack();
frame.setVisible(true);
}Message was edited by:
sunnymanmansonudevgan wrote:
dear piz tell me how i can read integer from user my email id is [email protected]
foolish, foolish question -
Hi,
I am trying to implement drawing on canvas with two colors, red and blue.
For example, to draw with the mouse "with two colors".
I do not need a filled rectangle.
I am looking into gradient but without any success.
Is there a better way to draw a line with two colors?
I also tried to use BasicStroke, but the line had an inner/outer strokes.
Please help with suggestions.devboris wrote:
..For example, to draw with the mouse "with two colors".
import java.awt.*;
import javax.swing.*;
class GradientLine {
public static void main(String[] args) {
GradientPanel gp = new GradientPanel();
gp.setPreferredSize( new Dimension(600,400) );
JOptionPane.showMessageDialog(null, gp);
class GradientPanel extends JPanel {
public void paintComponent(Graphics g) {
// cast the Graphics objkect to a Graphics2D object
// (G2D includes setPaint() method)
Graphics2D g2 = (Graphics2D)g;
GradientPaint bgPaint = new GradientPaint(
0,
0,
Color.black,
getWidth(),
getHeight(),
Color.white );
g2.setPaint(bgPaint);
g2.fillRect( 0, 0, getWidth(), getHeight() );
GradientPaint fgPaint = new GradientPaint(
0,
0,
Color.yellow,
getWidth(),
getHeight(),
Color.red );
// set the paint to a gradient.
g2.setPaint(fgPaint);
for (int ii=0; ii<getWidth()/10; ii++) {
g2.drawLine( ii*10, 0, ii*10, getHeight() );
for (int ii=0; ii<getHeight()/10; ii++) {
g2.drawLine( 0, ii*15, getWidth(), ii*15 );
} -
Draw Line With Arrow between containers in flex
I need to connect multiple containers by drawing arrow . can any one provide me the idea how to do?
Thanks in Advance,
senthil
[email protected]If your containers are within a spark container them self then you could use fxg to draw arrows based on the containers boundaries
eg this code will draw a red arrow:
<Graphic xmlns="http://ns.adobe.com/fxg/2008" version="2"> <!-- Use Use compact syntax with absolute coordinates. --> <Path data=" M 20 0 C 50 0 50 35 20 35 L 15 35 L 15 45 L 0 32 L 15 19 L 15 29 L 20 29 C 44 29 44 6 20 6"> <!-- Define the border color of the arrow. --> <stroke> <SolidColorStroke color="#888888"/> </stroke> <!-- Define the fill for the arrow. --> <fill> <LinearGradient rotation="90"> <GradientEntry color="#000000" alpha="0.8"/> <GradientEntry color="#FFFFFF" alpha="0.8"/> </LinearGradient> </fill> </Path> </Graphic>
you will have to scale the arrow according to your needs -
Draw lines with a specfic width and color
how to do it?
if given x arrays and y arrays, then connect points.
public void drawLine(int x1, int y1, int x2, int y2)This function doesn't have width and color.thanks.
I met a problem that the color is obtained by
calculating RGB.
color=a*R+b*G+c*B;
a+b+c=1;
How to get it?huh? -
Draw lines and columns button is disbaled inde template
Hi all,
Im developing a custom smartform with a template.
Now in the template,Draw lines and columns button is disbaled .How do i enable it.Also all the "SELCT PATTER" buttons are also disabled.Go to settings->table painter->select the required ones.
-
How to draw and modify double lines with Adobe Illustrator?
I need tot draw roadmaps. This should be easy using the pen tool, but my problem is that I cannot find a way to draw double lines with this tool. I have seen many fancy border styles and patterns. Some do have double or even quadruple lines, but the problem is than that they have an offset from the vector line and the space in between the two lines (the edges of the road) cannot be filled. Somewere I also found some pens called 'Double line 1.1' to 'Double line 1.6' but they also had an offset from the vector and I could not chance the size of the lines and the interval in between them independently.
What I am looking for is a way to draw two lines in parallel and have the option tot fill the space in between with a color or even a pattern.
The color and size of the lines should be changeable to make a distinction between several types of road.
Is there an existing set of pencils for this purpose? It would be nice to be able to draw not only roads, but also railways and rivers!
I am surely not the first person who needs to do this?
I use AI version 6Jacob,
Thanks for the answer. I have been searching for a solutions for a long
time, but today I found the solution on a forum (not on this one). That
solution is exactly as you described below, i.e. using a coloured line and a
narrower white line on top of the first one. My problem was that I did not
know how to create a custom brush based on the two lines. Now I know how to
do that. However, I still have the problem. I can now draw double lines and
I can change the color of the background line (the coloured one) but I
cannot change the white colour of the narrower line. I assume that I have to
completely redefine a new brush when I need to change that colour too.
Regards,
Rob Kole
Van: Jacob Bugge [email protected]
Verzonden: donderdag 28 maart 2013 17:04
Aan: RKOLE
Onderwerp: How to draw and modify double lines with Adobe
Illustrator?
Re: How to draw and modify double lines with Adobe Illustrator?
created by Jacob Bugge <http://forums.adobe.com/people/Jacob+Bugge> in
Illustrator - View the full discussion
<http://forums.adobe.com/message/5186535#5186535 -
How to draw centre line with white background?
Hi,
I need to draw a centre line with white background on it. Now i'm doing it by pasting the main line in the background and giving it white so that it shows a white backgound. Is there a way to do just by drawing like normal lines. If we can, is it possible to control the white backgound only to show less than the original line in both ends. This is for illustrations i do for exploding views and i need to draw this line to show it as assembly drawing.
Thanks
Manoj1. Draw a white line segment of desired width (stroke weight) with round cap (Stroke panel) for the background line.
2. Copy, Paste in Front
3. Change to desired foreground color, butt cap, reduce stroke weight.
4. Opt/Alt–drag foreground segment to overhang background segment by desired amount on both ends.
5. Select both segments and drag to Brushes panel, choose Art Brush.
6. In Art Brush Options choose Stretch Between Guides, drag guides somewhere to the inside of curve of round caps. (If in step 3 you chose black, set Colorization Method to Tints. Then you can select any color for the foreground segment by setting the stroke color.) Name the brush as you choose. Click OK.
7. Draw any path and apply the brush. -
How can i draw a straight line with a brush?
i know the pencil tool can draw a straight line with anchor points. is there a setting for the pencil tool that can mimic a 30 point brush, low hardness (faded side to side) at about an 80 degree angle or is there a way to make a straight line with the brush tool using a mouse?
i know this image is a bit blurry. what i want to do is replace the 2 white angled lines with the 30 point brush effect 230 pixels wide. the project on the left of the pic is a 2ft by 4ft canvas. any ideas? please help.Hello Mike, I wonder if you can help, no one else can. I asked this question on the forum in August Brush line fades on start with anchor points
Only on Photoshop CC does this happen, drawing a diagonal line with shift key, instead of line starting dark & then fading out, it does the reverse, starts on nothing & then darkens towards anchor point. I am on trial versions & can't purchase until this is cleared up. -
Draw lines and columns button was disabled
hi friends,
in my smartform template draw lines and columns button was disabled which results select pattern button also disabled. now i am unable to change any lines, can any one help me how to enable this button to change.
thanks and regards,
venkat suman.Hi
I come to the same problem and google lead me here.
Not the problem of Display/Change mode or authorization.
I fix this problem as below:
1) create a new smartform and create a template
2) click the "Settings" button
3) in tab General, check the "Draw Lines and Columns", click OK
4) exit without saving
5) now I can use the "Draw Lines and Columns" button
but here when I click the Settings button again, the "Draw Lines and Columns" is unchecked.
Hope this can help
May some mentor give an explanation. -
Flash IDE unable to draw pure black line with zero alpha
As Title
Use line or pancil tool in Flash CS 5.0 or 5.5.
Choose pure black color #000000 and zero alpha.
Try to draw line on the tage.
result : stage is emptycan u tell me what u are trying to achieve? this is very criptic
-
Hi All,
I want to draw multiple line with a arrow. Please guide me how can i do it by code dynamically. exactly as below.
Regards,
Kameshwaran A.create an empty symbol
put this code in it.
//***** Set some opening parameters
onClipEvent (load) {
//Make original line invisible
_root.line._visible = 0;
//Initiate some variables
number_lines = 0;
line_active = 0;
//***** Every time the mouse button is released...
onClipEvent (mouseUp) {
//Get the position of the mouse
origin_x = _xmouse;
origin_y = _ymouse;
//Increase the number of lines by one
number_lines++;
//Generate a new line name
name = "line"+number_lines;
//Duplicate a new line
_root.line.duplicateMovieClip(name, number_lines);
//Position the line's end point at mouse position
_root[name]._x = origin_x;
_root[name]._y = origin_y;
//Update line length / orientation
_root[name]._xscale = _root._xmouse-origin_x;
_root[name]._yscale = _root._ymouse-origin_y;
//If this is the start of a new shape
if (!line_active)
//Set the line tracking variable
line_active = 1;
//Set the start point of the new shape
start_x = origin_x;
start_y = origin_y;
//***** Every time the mouse is moved
onClipEvent (mouseMove) {
//If there's a line currently being drawn...
if (line_active)
//Update line length / orientation
_root[name]._xscale = _root._xmouse-origin_x;
_root[name]._yscale = _root._ymouse-origin_y;
updateAfterEvent();
//***** When a key is pressed
onClipEvent (enterFrame) {
//If it's the Enter key
if (Key.isDown(Key.ENTER))
//Join the end point of this line...
//...to the start point of the first line in this shape
_root[name]._xscale = "";
_root[name]._yscale = "";
//Reset line-tracking variable
line_active = 0;
draw a line convert it to a symbol and give it an instance name of line.
and there you can draw lines.
detach the lines by pressing enter.
and thats it.
your welcome in advance (:
INPORTANT to leave all your symbols in the scene not in the libery are it will not work
Message was edited by: xFARRELLx
Maybe you are looking for
-
I just started to use my new MacBook Pro, and am looking for a way to resize Safari to fill the screen. Clicking the maximize button doesn't do it, neither does clicking on a corner of a window and trying to drag it. Thanks.. MacBook Pro, Power Mac G
-
ITuneU - French accent (éèàê...)
Every time I try to upload files in iTunesU with french accent in the tag, I found after the upload some characters I never write in the tags. For example, if the name of the artist is «Hélène David» after the upload the name in tags is «Hélène David
-
Exporting a movie as an image sequence... cropped?
I've created a short sequence (4 seconds) in iMovie '09 that I am trying to export as an image sequence for insertion into a stop motion animation I'm creating with QuickTime Pro. The movie segment has been created with an aspect ration of 3:2 from
-
Here's a scripting VI for LVClass default menu
I was asked this morning for a bit of functionality that has been in LV for years but not exposed as a standalone function: how to set or clear the default menu associated with a LabVIEW class. So I did a "create subVI", cleaned up the code a bit, an
-
why i cannot activate my facetime in my iphone 4 ios 6.1.3 that i bought here in al khobar saudi arabia anyone can help me with my problem and i just read lots of forum that i need to turn on/off my facetime time in the settings but i dont have that