How to make lines I draw as an objects??

Hi friends:
I met a problem here, I find a similiar code below, but cannot solve it.
How to make lines I draw as objects in this application??
ie the lines I draw will be selectable as other JLabels, can be highlighted, can be deleted etc, just like any other components or object,
How to do this??
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Vector;
import java.lang.reflect.Array;
import javax.swing.*;
import javax.swing.event.*;
public class Drawines
     public static void main(String[] args)
        JFrame f = new JFrame("Draw Lines");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new ConnectionPanel());
        f.setSize(400,300);
        f.setLocation(200,200);
        f.setVisible(true);
class Drawines extends JPanel
    JLabel                                       label1, label2, label3, label4;
    JLabel[]                       labels;
    JLabel                                       selectedLabel;
    protected              JButton btn            = new JButton("DrawLines");
    protected              JButton btn1           = new JButton("Clear");
    protected              JButton btn2           = new JButton("No Draw");
    protected                      boolean isActivated = false;
    protected           int      stoppoint     = 0;          
    int cx, cy;
    Vector order                     = new Vector();
    Vector order1                     = new Vector();
    Object[] arr                    = null;
    public ConnectionPanel()
        setLayout(null);
        addLabels();
        label1.setBounds( 25,  50, 125, 25);
        label2.setBounds(225,  50, 125, 25);
        label3.setBounds( 25, 175, 125, 25);
        label4.setBounds(225, 175, 125, 25);
        btn.setBounds(10, 5, 100, 25);
        btn1.setBounds(100, 5, 100, 25);
        btn2.setBounds(200, 5, 100, 25);
            add(btn);
         add(btn1);
         add(btn2);
        determineCenterOfComponents();
        ComponentMover mover = new ComponentMover();
         ActionListener lst = new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 ComponentMover mover = new ComponentMover();
                       addMouseListener(mover);
                       addMouseMotionListener(mover);
                       isActivated = false;
        ActionListener lst1 = new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                       isActivated=true;
          btn.addActionListener(lst);
          btn1.addActionListener(lst1);
    public void paintComponent(final Graphics g)
         super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
         Point[] p;
            System.out.println("order.size()"+ order.size());
            System.out.println("order1.size()"+ order1.size());
                 if (!isActivated && order1.size()==0) {
                     for(int i = 0 ; i < order.size()-1; i++) {
                            JLabel l1 = (JLabel)order.elementAt(i);
                           JLabel l2 = (JLabel)order.elementAt(i+1);
                           order1.add(order.elementAt(i));
                           order1.add(order.elementAt(i+1));
                           System.out.println();
                           p = getCenterPoints(l1, l2);
                           g2.setColor(Color.black);
                                        g2.draw(new Line2D.Double(p[0], p[1]));            
                 }else if(!isActivated && order1.size()>0){
                         order=order1;
                     for(int i1 = 0 ; i1 < order.size()-1; i1++) {
                           JLabel l1 = (JLabel)order.elementAt(i1);
                           JLabel l2 = (JLabel)order.elementAt(i1+1);
                           System.out.println();
                           p = getCenterPoints(l1, l2);
                           g2.setColor(Color.red);
                            g2.draw(new Line2D.Double(p[0], p[1]));    
                            System.out.println(" order1.size() = " + order.size());
                 }else {
                      order1 = order;
                     for(int i1 = 0 ; i1 < order1.size()-1; i1++) {
                                JLabel l1 = (JLabel)order1.elementAt(i1);
                                JLabel l2 = (JLabel)order1.elementAt(i1+1);
                                p = getCenterPoints(l1, l2);
                                g2.setColor(Color.blue);
                                if (order.elementAt(i1) !=null){
                                     g2.draw(new Line2D.Double(p[0], p[1]));    
    private Point[] getCenterPoints(Component c1, Component c2)
        Point
            p1 = new Point(),
            p2 = new Point();
        Rectangle
            r1 = c1.getBounds(),
            r2 = c2.getBounds();
             p1.x = r1.x + r1.width/2;
             p1.y = r1.y + r1.height/2;
             p2.x = r2.x + r2.width/2;
             p2.y = r2.y + r2.height/2;
        return new Point[] {p1, p2};
    private void determineCenterOfComponents()
        int
            xMin = Integer.MAX_VALUE,
            yMin = Integer.MAX_VALUE,
            xMax = 0,
            yMax = 0;
        for(int i = 0; i < labels.length; i++)
            Rectangle r = labels.getBounds();
if(r.x < xMin)
xMin = r.x;
if(r.y < yMin)
yMin = r.y;
if(r.x + r.width > xMax)
xMax = r.x + r.width;
if(r.y + r.height > yMax)
yMax = r.y + r.height;
cx = xMin + (xMax - xMin)/2;
cy = yMin + (yMax - yMin)/2;
private class ComponentMover extends MouseInputAdapter
Point offsetP = new Point();
boolean dragging;
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
for(int i = 0; i < labels.length; i++)
Rectangle r = labels[i].getBounds();
if(r.contains(p) && !isActivated )
selectedLabel = labels[i];
order.addElement(labels[i]);
offsetP.x = p.x - r.x;
offsetP.y = p.y - r.y;
dragging = true;
repaint(); //added
break;
public void mouseReleased(MouseEvent e)
dragging = false;
public void mouseDragged(MouseEvent e)
if(dragging)
Rectangle r = selectedLabel.getBounds();
r.x = e.getX() - offsetP.x;
r.y = e.getY() - offsetP.y;
selectedLabel.setBounds(r.x, r.y, r.width, r.height);
//determineCenterOfComponents();
repaint();
private void addLabels()
label1 = new JLabel("Label 1");
label2 = new JLabel("Label 2");
label3 = new JLabel("Label 3");
label4 = new JLabel("Label 4");
labels = new JLabel[] {
label1, label2, label3, label4
for(int i = 0; i < labels.length; i++)
labels[i].setHorizontalAlignment(SwingConstants.CENTER);
labels[i].setBorder(BorderFactory.createEtchedBorder());
add(labels[i]);
Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

2 choice, bundle your app in a jar, or get a native compiler.
executable jar
http://java.sun.com/j2se/1.3/docs/guide/jar/jarGuide.html
http://developer.java.sun.com/developer/qow/archive/21/index.html
native
http://gcc.gnu.org/java/
http://www-106.ibm.com/developerworks/library/j-native.html
http://icafe.sourceforge.net/
http://www.towerj.com/
http://www.xlsoft.com/en/products/development/jet/jetpro.html

Similar Messages

  • How to make a text "drawer" in iWeb

    Does anyone know how to make a text "drawer" in iWeb? What I mean is when you click on a hyperlink to read more text, but instead of opening up a new page, it makes the text appear below the link on the same page.

    Anything fancy with iWeb has to be done in the HTML Snippet or after publishing the page.
    Find the code for the drawer, apply it and show us the result.
    Perhaps not the drawer you had in mind but this is something near:
    http://www.wyodor.net/Ajax/
    Here's another one with drawer in the title:
    http://jqueryfordesigners.com/slide-out-and-drawer-effect/
    http://jqueryfordesigners.com/demo/plugin-slide-demo.html
    Found with : [text drawer|http://www.google.com/search?client=safari&rls=en&q=text+drawer&ie=UTF-8 &oe=UTF-8]

  • How to make multi user drawing application

    how to make multi user drawing application in as 3.0

    I'd suggest using Flash Media Interactive Server if you wish to make this type of application and use Flash as the interface.  I can't give you the details on exactly how to implement it, but using Remote Shared Object and FMIS would serve as the basis.  I believe that the package comes with examples of Shared Objects that can serve as a simple basis from which to proceed.  After that you might want to see if you can find an available whiteboard app that can be leveraged to do as you wish.
    I apologize in advance if using this type of solution is a non-starter, I've been using FMIS locally and have plans to eventually implement something similar to this type of drawing app as well.

  • How to make lines for "fill in the blanks?" (iWork Pages 09)

    This should be easy since it's something many people do: design a form for others to fill out with a pen or pencil.  However, I can't find any information regarding how to make a line after text, like this:
    Name _________________ Address _________________________________ Phone __________
    ...without using the underline character.
    Back on the Clarisworks days there was some way to make nice neat lines after text using tabs.  However, It's been so long that I can't recall how it worked.  I've Googled this issue using every logical term I can think of but found nothing useful.  The Pages 09 help file and the user guide  seem to be mute on this subject. The Word 2008 help file is similarly silent.  However, I'm sure that the greater Pages community knows the answer to this one.
    Thanks,
    Bill

    What you want is called a tab leader. In Pages, to create the underline:
    To create a new tab stop using the Text inspector, click in the document where you want to create a new tab stop, click Inspector in the toolbar, and then click Tabs. Click the Add button in the bottom-left corner of the Tabs pane. The new tab stop appears in the Tab Stops column.
    Then  use the Leader drop down menu to choose a solid line:

  • How to make line-in come out rear speakers? (SB Live! 5

    Card is SB Li've! 5. DE and OS is XP SP2:
    ================================
    I have tried everything that I can think of. It was working fine until I installed a program which screwed up my mixer settings. I have loaded the default mixer settings. Now my rear speakers only work for wave devices, but not line-in.
    Is there a way to make line-in come out both the front and rear speakers, or set the rear speakers to duplicate the front speakers (losing the surround feature)?
    Failing that I will have to resort to plugging both sets of speakers into the one socket via an adapter - I don't wish to do this as I had this working for many months.
    Please help.
    grol
    Message Edited by groslchie on <SPAN class=date_text>-2-2005 <SPAN class=time_text>07:22 AM
    Message Edited by groslchie on -2-2005 07:23 AM

    Weird. I just installed Creative PlayCenter from the driver CD and after the reboot, line-in now comes out the rear speakers again. Must've been some system files updated or something, because CMSS is still off according to PlayCenter. When I turn CMSS on, the line-in stops coming out rear, but turning it off makes it work!!!! So it's sorted, but still have no idea why it screwed up and why I needed PlayCenter installed to change the CMSS settings.

  • How to make a chart/table a background object?

    How do I make that grid into a background objective so that I can draw lines and similar things on top of it without it moving? Intending to use it as a coordinate system/grid/plane (or whatever it is called in English, but the thing refuses to stay still whatever I do to it. :/
    Also, sorry for my bad English.
    Thanks!

    click on table > Inspector > Wrap (3rd tab) > Object Placement > Floating
    Menu > Format > Advanced > Move Object to Section Master
    Peter

  • How to make a curve to join two objects editable?

    Hi, I'm involved in a project in which we're doing a visual editor (written in Java). Now, I'm trying to make curves that join two different objects that I'm painting in a class that extends JPanel (this class is what I'm using to paint, inside a JFrame, overriding the method paintComponent). I'm in troubles because I'm using the class QuadCurve2D to make this, but I cannot make it clickable (I'm using the method contains, but it doesn't work everytime), make it editable (for example, setting a square in its middle point to modify its curvature. The point that is used on the middle of the QuadCurve2D when the constructor is called is outside the curve) or something (method, variable, iterator, etc) that could tell me which Points are in the QuadCurve2D.
    After looking for all of that some time, I have no answer, so I'm trying posting it here to find a solution. Is there anyway to make it with the QuadCurve2D class, or do I have to try with some external library?
    Edited by: mccrank on Jul 2, 2009 10:09 AM

    Used the Pen tool, but click on the correct icon on the top left on the Options Bar. That way you can get a Path instead of a Shape Layer.
    Once you have your Path you can stroke it with a Brush or any drawing tool. Various options appear in the Brushes palette. For a dotted line you will need to increase the spacing. If you want dashes, use a square brush and set the Angle Jitter to Direction.

  • How to make a glow around a person/object?

    I want to just have a glow behind someone.  I know I could make a layer behind it, draw a soft line all the way around the object, and then blur it, but is there an easier way?  Maybe something that could make an automatic outline of an object?  Thanks in advanced.
    -TitanVex

    TitanVex,
    http://www.pixentral.com/show.php?picture=1XSChkSj88uk6oDO0SoLFrHVezOQ1
    Make your selection with one of the selection tools. I used the Magic Extractor
    Place the selection on its own layer, and make the selection active (CTRL+left click the layer thumbnail) - should see marching ants
    Go to Layer>Layer Styles>Style Settings
    Check outer glow and set the parameters for the glow.

  • How to make a text in a text object Bold at run time

    I would like to make a text in a text object Bold depends on a record value. how can I control that ?
    Edited by: Hagita1 on Jan 18, 2011 10:51 AM
    I found the solution-Thank you

    You should share your solution with the community.

  • How to make the new drawing line on the old form?

    I have been reading about Java about 2 months, and now I have to start my first project within this week. I still don't know how to do it!!! I have to get the info from the keyboard to draw a line on the old form of the original project. Please tell me what I should study more, the applet or the java bean. This form will be shown on the website, but I'm not sure that the applet is the right or the java bean is the right one. Yes, now I'm very confusing!!!
    Thanks in advance for all reply :)

    Describe the form please given we know nothing of the Origional one!

  • How to make line thicker?

    When I use "g.drawLine()" to draw a line,the size of the line is fixed.But I would like to make the line thicker.How to do that?Thanks!

    one of my favorite methods :)
        void drawThickLine(Graphics2D g, double x1, double y1, double x2, double y2, double width) {
            Stroke orig = g.getStroke();
            BasicStroke wideStroke = new BasicStroke((float)width);
            g.setStroke(wideStroke);
            g.draw(new java.awt.geom.Line2D.Double(x1,y1,x2,y2));
            g.setStroke(orig);
        }Enjoy!

  • How to make lines in GridLayout?

    I use GridLayout with 2 columns and many rows. I want to draw a line between the two columns. How can I do this in GridLayout?

    tjacobs01 wrote:
    overridding paintComponent probably won't work, because the children will paint over it. Not if the opaque has been set. Also, I wonder if the "gaps" will show through even if the children keep opaque true.
    Yep, you can do this by setting the background color of the panel to the column line color you desired, and let this color "shine through" the gaps in the grid layout:
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JComponent;
    import javax.swing.SwingConstants;
    public class GridsShowQuestion
      private static final int GAP = 10;
      private static final int ROWS = 3;
      private static final int COLS = ROWS;
      private static final int FONT_SIZE = 50;
      private JPanel mainPanel = new JPanel();
      public GridsShowQuestion()
        mainPanel.setBackground(Color.red);
        mainPanel.setLayout(new GridLayout(ROWS, COLS, GAP, 0));
        for (int i = 0; i < ROWS; i++)
          for (int j = 0; j < COLS; j++)
            JLabel lbl = new JLabel("X");
            lbl.setFont(new Font(Font.DIALOG, Font.BOLD, FONT_SIZE));
            int eb = 10;
            lbl.setBorder(BorderFactory.createEmptyBorder(eb, 3*eb, eb, 3*eb));
            lbl.setHorizontalAlignment(SwingConstants.CENTER);
            lbl.setOpaque(true);
            mainPanel.add(lbl);
      public JComponent getComponent()
        return mainPanel;
      private static void createAndShowUI()
        JFrame frame = new JFrame("GridsShowQuestion");
        frame.getContentPane().add(new GridsShowQuestion().getComponent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }Edited by: Encephalopathic on Oct 14, 2008 7:16 PM

  • How to make lines for writing?

    How do I create lines for writing?

    tablet = note book
    Make the paragraph style as mentioned above. Adjust the space after as desired, the line weight for the rule below. Press enter for each paragraph.
    Mike

  • How to make line chart start at y-axis?

    How do you make the series on a line chart start at the y-axis?  I tried adding a data point for y(x=0), but the Xcelsius graph drops it and starts with y(x=1).  How do I fix that?  This is especially important for series that need to start at zero.

    Post Author: amr_foci
    CA Forum: Xcelsius and Live Office
    its all based on ur design of your Excel sheet
    design how it will be in Excel first
    then go to xeclsius
    ,,, by the way it looks very easy task
    you can do it.

  • How to make line segments persist

    I am studying by myself, and I have already Googled the subject line, to no avail.
    I am trying to write lines with movement dictated by the arrow keys. I can get a line segment to move, but after the movement the whole panel gets repainted. So I don't get any lines written anywhere.
    Anyone have a solution to this?
    Here's my code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DrawLinesUsingKeys extends JFrame {
        private DisplayCoordinatePanelSEVEN keyboardPanel =
                new DisplayCoordinatePanelSEVEN();
        public DrawLinesUsingKeys() {
            getContentPane().add(keyboardPanel);
            keyboardPanel.setFocusable(true);
        /**Main method*/
        public static void main(String[] args) {
            // Create a frame
            DrawLinesUsingKeys frame = new DrawLinesUsingKeys();
            frame.setTitle("Draw Lines Using Keys");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300, 300);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    class DisplayCoordinatePanelSEVEN extends JPanel implements KeyListener {
        private boolean pressedAction = false;
        private int x = 150;
        private int y = 150;
        private int z = 150;
        private int a = 150;
        public DisplayCoordinatePanelSEVEN() {
            addKeyListener(this);
        public void keyPressed(KeyEvent e) {
            pressedAction = true;
            switch (e.getKeyCode()) {
                case KeyEvent.VK_DOWN:
                    a = y + 10;
                    break;
                case KeyEvent.VK_UP:
                    a = y - 10;
                    break;
                case KeyEvent.VK_LEFT:
                    z = x - 10;
                    break;
                case KeyEvent.VK_RIGHT:
                    z = x + 10;
            repaint();
        public void keyReleased(KeyEvent e) {
        public void keyTyped(KeyEvent e) {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            if (pressedAction) {
                g.drawLine(x, y, z, a);
                pressedAction = false;
                x = z;
                y = a;
        }Thank you for your time.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class DrawLinesUsingKeys extends JFrame {
        private DisplayCoordinatePanelSEVEN keyboardPanel =
                new DisplayCoordinatePanelSEVEN();
        public DrawLinesUsingKeys() {
            getContentPane().add(keyboardPanel);
            keyboardPanel.setFocusable(true);
        public static void main(String[] args) {
            DrawLinesUsingKeys frame = new DrawLinesUsingKeys();
            frame.setTitle("Draw Lines Using Keys");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300, 300);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    class DisplayCoordinatePanelSEVEN extends JPanel implements KeyListener {
        java.util.List<Point> points = new java.util.ArrayList<Point>();
        private boolean pressedAction = false;
        private int x = 150;
        private int y = 150;
        private int z = 150;
        private int a = 150;
        public DisplayCoordinatePanelSEVEN() {
            addKeyListener(this);
            points.add(new Point(x,y));
        public void keyPressed(KeyEvent e) {
            pressedAction = true;
            switch (e.getKeyCode()) {
                case KeyEvent.VK_DOWN:
                    //a = y + 10;
                    y += 10;
                    points.add(new Point(x,y));
                    break;
                case KeyEvent.VK_UP:
                    //a = y - 10;
                    y -= 10;
                    points.add(new Point(x,y));
                    break;
                case KeyEvent.VK_LEFT:
                    //z = x - 10;
                    x -= 10;
                    points.add(new Point(x,y));
                    break;
                case KeyEvent.VK_RIGHT:
                    //z = x + 10;
                    x += 10;
                    points.add(new Point(x,y));
            repaint();
        public void keyReleased(KeyEvent e) {
        public void keyTyped(KeyEvent e) {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            if (pressedAction) {
                for(int xx = 0, yy = points.size()-1; xx < yy; xx++)
                  Point p1 = points.get(xx);
                  Point p2 = points.get(xx+1);
                  g.drawLine(p1.x, p1.y, p2.x, p2.y);
                pressedAction = false;
                //x = z;
                //y = a;
    }

Maybe you are looking for

  • Default mail client error

    Hi; I get this error mesage when trying to sync my Iphone to my PC: *"Either there is no default mail client or the current mail client cannot fulfill the messaging request. Please run Microsoft Outlook and set it as the default mail client."* I have

  • How to read mseg from bseg!

    Hi forum! I need to read from my bseg table (BUZEI) the corresponding item in the mseg table (ZEILE). the mseg table have the BELNR and BUZEI fields , but they are empty. can this be possible? i'm working with R/3 4.7 thanks in advance. John.

  • How to add a table in the header section

    I would like it to look similar to this: I would like for this to show on each page of the document.  This would be a multi-page standalone document.

  • Audigy 4 Line-in probl

    I have tried using the the line-in feautures of the new Audigy 4, however apart from the microphone I can't get the other line-ins (2 and 3) to work. Mainly trying to hook up a guitar. I've tried straight from the guitar to the external box, then fro

  • Problem in rebate agreement type 0005

    Hi I created a rebate agreement of type 0005 and maintained amount Rs 5000 for a customer while creating billing document the condition type BO06 was determined in the billing doc but without anu value the analysis shows that condition record has bee