The line between two labels

Hello world

I wrote this little program where iam creating two label and I can drag this label and this works perfectly.
I also try to include a line between this label. I am not getting the correct result because I see my tag, but not the line. (I know that my program is incomplete to separating it from the label, since I can't see the line with label iam not able to proceed)

I am a newbie so my code is perhaps not too professional. Hoping to find a few tips.
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Line2D;

import javax.swing.*;

@SuppressWarnings("serial")
public class test extends JFrame implements MouseListener, MouseMotionListener  {

private JPanel panel = new JPanel(null);   
private JLabel label1 = new JLabel();
private JLabel label2 = new JLabel();
private int mouseX = 200;
private int mouseY = 100;
private boolean drag = false;


public test() {
    this.add(panel);
    panel.setBackground(Color.WHITE);

    panel.add(label1);
    label1.setOpaque(true);
    label1.setBackground(Color.BLUE);
    label1.setBounds(mouseX, mouseY, 100, 50);
    label1.addMouseMotionListener(this);
    label1.addMouseListener(this);

    panel.add(label2);
    label2.setOpaque(true);
    label2.setBackground(Color.RED);
    label2.setBounds(mouseX + 200, mouseY, 100, 50);
    label2.addMouseMotionListener(this);
    label2.addMouseListener(this);
      
}

@Override
public void mousePressed(MouseEvent e) {
    if (e.getSource() == label1) {
        drag = true;
    }
    if (e.getSource() == label2) {
        drag = true;
    }
}



@Override
public void mouseReleased(MouseEvent e) {
    drag = false;
}

@Override
public void mouseDragged(MouseEvent e) {
      if (drag == true)
    {
        JComponent jc = (JComponent)e.getSource();
        jc.setLocation(jc.getX()+e.getX(), jc.getY()+e.getY());
    }
}

public void mouseMoved(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Line2D lin = new Line2D.Float(100, 100, 250, 260);
    g2.draw(lin);
    super.paint(g2);
}

public static void main(String[] args) {
    test frame = new test();
    frame.setVisible(true);
    frame.setSize(600, 400);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   
   
}
}
Thanks for all your time and help.

Outside of the Netbeans IDE is also there another tool that can help in creating faster GUI swing application.
public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    Line2D lin = new Line2D.Float(100, 100, 250, 260);
    g2.draw(lin);
}

Also I suggest

public void mousePressed(MouseEvent e) {
    if (e.getSource() == label1 || e.getSource() == label2) {
        drag = true;
    }
}

Tags: Java

Similar Questions

  • Measure the time between two digital pulse

    Hello

    For a non-critical calendar application, I need to measure the time interval between consecutive TTL pulses, ranging from the order of 0.5 s for a few seconds, with a low accuracy of +/-10-50ms. The interval being measured varies between the rising edge of the first pulse and the front of the next and so on.

    I have several input lines I need to deal with. Because it's a critical machination low cost, I don't want to use digital counters for each line, so I work with an acquisition of data USB6008 and have connected the input rows TTL on the digital inputs of the device. Avoiding will be sufficient.

    I found a good example of VI on discussion forums that does almost the same thing, only it uses instead of the DAQ Assistant user input. The VI works including the time the program going on in a while loop. I replaced with the DAQ Assistant output (a channel) user input in the hope that it is still work.

    When I run the program in "run once" mode, it seems to work perfectly. However, in "continuous run" it measures only a very small interval, probably just the time between two samples.  I think it has something to do with the help of a while loop in combination with the DAQ Assistant. Anyone who has any suggestions how to solve this problem?

    Thank you!

    OK... first of all, you should never use the button "run continuously.  I wish that NEITHER would be to eliminate it, but told me that it is sometimes useful for debugging.  If you want your program to run over and over again, use a while loop with a stop"" button.

    If I'm reading your code correctly, you make your initial moment, and then collect data from data acquisition.  When one of the channels is "T", you stop your loop and the end time of capture.  (By the way, why you convert your table to a cluster?  Why not just index the appropriate channel in the table directly?)

    Since you want to capture the time between two consecutive pulses, you need to know when a transition has occurred... i. e when your digital line went from F (no pulse) to T (pulse start).  This will give you your forehead.  Right now, all you're doing is looking for a value T - so you have no way of knowing if you are looking for to the previous impulse again, or a new impetus.  You also burn 100% of your processor with the way you have your programme in place.

    You need a small loop delay so that your VI is not 100% of your hogs CPU time.  Given that you can live with an accuracy of 50msec, what I suggest that you use.

    See attached picture for you give an idea of how to implement.  He will probably need some refining operations, but it should point you in the right direction.

    I hope this helps.

  • Regular expression help please. (extraction of a subset of the string between two markers)

    I haven't used regular expressions before, and I can't find a regular expression to extract a subset of the string between two markers.

    The chain;

    Stuff of header I want
    Stuff of header I want
    Stuff of header I want

    Stuff of header I want
    Stuff of header I want
    Stuff of header I want

    6 ERRORS
                         
    Info I want to line 1
    Info I want line 2
    Info I want line 3
    Info I want to line 4
    Info I want to line 5
    Info I want line 6
    END_ERRORS

    From the string above (it is read from a text file), I try to extract the subset of string between ERRORS 6 and END_ERRORS. The number of errors (6 in this case) can be any number from 1 to 32, and the number of lines I want to extract will correspond with this number. I can provide this number of a caller VI if necessary.

    My current solution, which works, but is not very elegant;

    (1) using Match Regular Expression for the return of the string after you have synchronized the 6 ERRORS

    (2) uses the Regular Expression matches to return all characters before game END_ERRORS of the string returned by (1)

    Is there a way this can be accomplished using 1 Regular Expression Match? If so someone could suggest how, as well as an explanation of the work of the given regular expression.

    Thank you very much

    Alan

    I used a character class to catch any word or whitespace characters.  This put inside parentheses a substring matching the criteria that you can get by developing the node for regular expression matching.  The \d matches the numbers and the two * s repetition of the previous term.  So, \d* will find the '6', as well as "123456".

  • Calculate the hours between two dates

    Hello

    I have a requirement to count the hours with 2 given timestamps, something like:
    SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ;
    
             B
    ----------
            48
    However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).
    So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
    How can I achieve this? Any idea will be useful.

    Thank you

    My query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.

    There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).

    Ben

  • Take the time between two values

    Hi people,

    I have a problem and I know idea how to solve... I need help.

    The problem is I want to take the time between two values max as you can see in the chart.

    For example, in the image that I have add

    4.5 - 1 840 = 2.66

    And enter this value in the 'time between mostra '.

    It's that I want...

    But what I think is very complicated, because I don't know how to take the time correctly and does remove...

    Thank you very much

    Any solution?

    Hi jocuma,

    I tried something and hope that helps u.

    Just create two arrays of temperature and voltage. First of all, I'll get the value of the voltage when it is more of a certain value and that same index to get the value of time and store in the shift register.

    When I get the second higher than the limit value, I'll get time and subtract the previous value.

  • How to avoid synchronization of the settings between two computers

    I have two computers (a desktop computer all-in-one DELL and HP laptop).  Log-in at once is my Microsoft account.

    PROBLEM: When I 'customize' screen on one, the same changes are made on the other.   It is not desirable.  How to avoid that, far from making a second Microsoft account?

    To clarify - the ICONS are not duplicated, just any changes made to the themes of office such as colors or backgrounds.

    Thanks in advance!

    Hello Beckinista,

    Thanks for posting your question on the Microsoft community.

    Thank you for your query details.

    I also like the fact you want to avoid synchronization of the settings between two computers.

    I suggest you stop the synchronization of all of the settings between two computers and check if it helps.

    Please see this link:
    Sync between multiple PCs with OneDrive settings
    http://Windows.Microsoft.com/en-us/Windows-8/sync-settings-PCs

    Note: Please see section "to stop all sync settings" in the article above.

    I hope this information helps.

    Please let us know if you need more help.

    Thank you

  • MaxL Script to clear the data between two dates

    Hi all

    I need advice to clear the data between two dates, I have three dimensions in my sketch, 'eno', 'hiredate' and the 'actualamount '.

    Now I need to erase the data between the date range, up to now, I have this script,

    Fix ("HireDate", "Eno")

    Difficulty (@relative ("00:00:00",0),@relative("eno",0)) 2015-07-15 "))

    CLEARDATA "sal."

    endfix

    ENDFIX

    These scripts only clears on a specific day, but I tried to write the script to clear between two dates, I surfed on a few sites, but no clear answers, finaanly came here, kindly help in this regard.

    Thanks in advance.

    Have you not tried the format of "startdate":"enddate" for example "August":"September."

    See you soon

    John

  • Display the months between two dates

    Hello:
    I need all the months between two dates. I entered two dates as January 15, 2001 and 2011-mar-03. I want the result as below.

    JANUARY 15, 2011 - JANUARY 31, 2011
    February 1, 2011 - February 28, 2011
    MARCH 1, 2011 - MARCH 3, 2011

    I held this result of sql query in oracle. Could you please suggest me?
    Thanks in advance.
    Abhishek
    SELECT     GREATEST(st, ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1))) dt,
               LEAST(ed, LAST_DAY(ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1)))) ld
          FROM (SELECT DATE '2011-01-15' AS st, DATE '2011-03-03' AS ed
                  FROM DUAL)
    CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(ed, 'MONTH'), TRUNC(st, 'MONTH')) + 1
      ORDER BY 1;
    
    DT                       LD
    ------------------------ ------------------------
    15.01.2011 00:00:00      31.01.2011 00:00:00
    01.02.2011 00:00:00      28.02.2011 00:00:00
    01.03.2011 00:00:00      03.03.2011 00:00:00
    

    HTH, Urs

  • How to find the difference between two dates in the presentation layer

    Hi gurus,

    Hello to everyone. Today, I came with the new requirement.


    I need to know the difference between a date and the current date in the formula column application presentation layer.by.



    Thank you and best regards,
    Prates

    Hi Navin,

    TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".

    If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...

    hope you understand...

    Award points and to close the debate, if your question is answered.

    See you soon,.
    Aravind

  • Calculating the distance between two images... ?

    Hello

    I'm trying to calculate the distance between two images (A and F - there are other images between A and F), but I can't seem to understand how to make good sense.

    Image A.x is "(stage/2)-(A.width/2)" and the image of F.x is "provable - imgSpace" which is a negative value (all images x is a negative value for image A.x). "

    In my view, the calculation is F.x - A.x, and although it could be good I still ned the value to be non-negative.

    Does anyone know how to do this?

    Thanks in advanse...

    I think you can find out the distance with this equation,

    var len:Numer = Math.abs (A.x - F.x);

  • Dynamic action - Get the difference between two dates + times

    I have problems a little dynamic to work action. I'm trying to get the time between two dates with the time difference.

    Here is what I got (this is apex 4.0):

    Two date pickers + two numbers fields (date/start/end times)

    I created a dynamic action on the page who fires on the point lose focus (above points).

    The real action for the DA is the body of the PL/SQL function:
    declare
      end_date DATE;
      start_date DATE;
    Begin
      start_date := to_char(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MON-YYYY HH:MIAM');
      end_date := to_char(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MON-YYYY HH:MIAM');
      :P1_HOURS := end_date-start_date;
    End;
    When I change the values on the page, I get the following error:

    AJAX call back Server error ORA-06502: PL/SQL: digital or value error: character number conversion error to set the value.

    I'm guessing that there is a problem with the date formatting, but I can't make it work. Thanks in advance!

    Hi djston,

    because you chose the dynamic action of 'Set value' with the "Body of the PL/SQL function" type you need to return the value. Try the following code

    declare
      end_date DATE;
      start_date DATE;
    Begin
      start_date := to_date(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MM-YYYY HH:MIAM');
      end_date := to_date(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MM-YYYY HH:MIAM');
      RETURN (end_date-start_date)*24;
    End;
    

    and P1_REQUESTED_HOURS like 'item affected. "

    Concerning
    Patrick
    -----------
    My Blog: http://www.inside-oracle-apex.com
    APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

    Published by: Patrick Wolf on January 17, 2011 10:54

  • Find the difference between two date and time

    Hi friends,

    I wanted to find the difference between two date and time, but my qury is slightest error "invalid number."

    select sql_step_num,proc_name,run_seqno,start_date,end_date,(to_char(start_date,'HH24-MI-SS') - to_char(end_date,'HH24-MI-SS') ) as ed  
    from eval.EVAL_RUNTIME_DETAILS
    where trunc(start_date) = trunc(sysdate) 
    order by sql_step_num;

    You try to get the feel between two char strings.
    And more difference between two dates gives a NUMBER of days.
    Try this:

    select sql_step_num,proc_name,run_seqno,start_date,end_date,numtodsinterval(end_date-start_date,'DAY') as ed
    from eval.EVAL_RUNTIME_DETAILS
    where trunc(start_date) = trunc(sysdate)
    order by sql_step_num;
    
  • How to reduce the space between two lines in a panelformlayout who is lain in the panelbox?

    Mr President.

    I have a panelbox in which I put a panelformlayout which have two rows as below

    panelformspace.png

    I want to reduce the space between inputfield first and second inputfield.

    Thus, this second inputfield closer to the first inputfield

    Respect of

    You can define simple = true in the first entry field (name), sorround who on the ground with panelLabelAndMessage and add the second inputField (address) about to end of panelLabelAndMessage.

    In fact, you can add more or less space with spacer between them and panelGroupLayout with horizontal layout as a facet of the end child

  • Get the lines between colors in Illustrator

    Hello

    I have a problem and I'm looking for some advice. I dropped a raster image in Illustrator (AI) and with the trace function, has turned into a vector image which looks great on my monitor. However, when I load the vector file in PDF format and then open the PDF file, I see a small, light, grey hairlines between colors.

    I do a product for a customer label. He wants a photo (JPEG) for the background. Printing wants vector images to CMYK.

    I am fairly new to HAVE and probably not using 'approved methods' although I took what I thought, is a logical step to achieve my goal.

    I took the JPEG RGB, converted into a .tiff to CMYK. I also tried to convert the JPEG in .bmp and .esp - all in CMYK mode, before moving to HAVE. I also tried putting the JPEG directly in I.

    I dropped these images in Illustrator separately and Live tracks on each. At this point, each attempt gave me excellent vector images in CMYK mode, but went wobbly when I transfer to PDF.

    Curiously, when I make a hard copy of this PDF on a Hi ground digital printer (2400 dpi), the lines do not appear. However, I am still very concerned about these lines, because I send a power off to work on offset printing. I'm sure that the printer will panic if he sees these lines and I am even more worried that these lines may appear in the print process four colors.

    A local graphics person I spoke with that suggested I'd find my solution to scout, but I fiddled a little this feature and could not solve the problem. Although I still wonder if maybe it's where I could find the solution, because when I hit Expand the blue path lines seem to match with the troublesome gray lines.

    Someone else told me to hit Expand and then turn off the Stroke. I think that I did it correctly, but there is no difference. I also didn't see any difference when I applied to the maximum value for the race. Other attempts to find a cure included deselected Resample, then re - sample with a resolution of 300.

    This is driving me crazy and I hope I can find help.

    Matt

    Here's a quick and easy way to get rid of these lines.  Place the image raster in illustrator.  Then click on copy.  Then direct route on the image use, using the preset of 8 colors.  This will give you a very simple version of the photo.  Click on expand.  Then click on paste in front to put a new copy of the raster on the top of the first image.  Use the tracing once again, but this time with a screening of high resolution.  Click on expand.  This should solve the problem.

    You see, these lines are only tiny spaces between the vector objects.  By creating two vector images in the same frame, the bottom a slightly simpler from the top edge, you can get rid of these lines.

    I hope this helps!

  • How to calculate the hours between two dates by the numbers

    If I update 09:00 start time 17:00 end time of shift in C3 and B3, how to use a D3 formula to calculate the number of hours between the two?  Then I can just copy down the lines for nth years...

    It is a spreadsheet of the part-time staff payroll.

    I'm sure that a lot of people out there have done that.

    Help, please.

    Thank you.

    Eddie

    What program of worksheet that you are using? Since you have a newer iMac running El Capitan, I can safely assume that you use NOT AppleWorks, which is a Power PC application that can run on any OS newer than the snow leopard, OS X 10.6.8.

    If you use numbers, try to repost your question in numbers for Mac forum. If you use Microsoft Excel, try posting in the Microsoft forums. LibreOffice also has community support.

Maybe you are looking for

  • Mozilla is hang on when I start firebug

    When I work on mozilla, then it crashes. This problem occurs when I activate the firebug.

  • Export model

    I was wondering if there was a way to export the downloads\unpack in a folder named for the model of the deivce? The idea is to have a sharing folder with all the systems that we have. I want a tech to just open the sharing and have a list of folders

  • Extended warranty info.

    I searched this info here and on HP.com and could not find. I'm sorry if it's been asked before, and I was just so this is. When I bought my most recent computer, a p6703w, (works very well by the way) on the "major retailer" even asked me an extende

  • ALPS Touchpad strangeness on V5 - 573P

    Hello world I have upgraded to Windows 10, everything seems almost smooth so far, with the exception of my touchpad. I use the finger double scroll function quite frequently, but now when I try to use it, I see a strange box poster (touch screen rela

  • Change the folder on Windows Explorer.

    How can I change the folder that opens at the start of the Explorer?