How to see my code drawing a line from one point to another
hi, im wondering if you could help me.
i am working on my project which is to visualise travelling salesman heuristics.
i have managed to make my first heuristic work, but my problem is that when i clicked the run button on my GUI,
the output is already a complete tour with all the edges already drawn, but what i want is to see how it solves or draw the lines from one vertex to another just by clickin the run button once.
would be great if you could advice me of what method or technique i need to use to see my application solving the tour or drawing the edges.
below is my cofe for drawing the edges from one point to another
void drawLineNNh(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.blue);
int i = 0;
if (P == null) return;
else
for(i=0; i<P.getSize(); i++)
Line2D.Double drawLine = new Line2D.Double(P.x_coor[nnH.seen]+5, P.y_coor[nnH.seen[i]]+5, P.x_coor[nnH.seen[i+1]]+5,P.y_coor[nnH.seen[i+1]]+5);
Line2D.Double drawLastEdge = new Line2D.Double(P.x_coor[nnH.seen[P.getSize()-1]]+5, P.y_coor[nnH.seen[P.getSize()-1]]+5, P.x_coor[0]+5,P.y_coor[0]+5);
g2.drawString( " Total Distance : " + nnH.totalDistance , 10, 300);
g2.draw(drawLine);
g2.draw(drawLastEdge);
public void setNNh(Points p)
nnH = new NNheuristic(p);
useNNh = true;
public void paint(Graphics g)
frame(g);
drawpoints(g);
if(useNNh)
drawLineNNh(g);
below is my code for calling the above method to draw edges, actionlistererun.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Run")) {
if (chooseHeur.getSelectedItem()=="Nearest-Neighbour")
System.out.println(chooseHeur.getSelectedItem());
//points = new Points(toInt((String)chooseNum.getSelectedItem()));
//PlotArea.set(points);
PlotArea.setNNh(points);
PlotArea.repaint();
I AM USING SWING.
HERE IS MY CODE, HOPEFULLY ENOUGH TO UNDERSTAND THE PROBLEM.
class Plot extends Panel{
public static int num;
NNheuristic nnH;
Closest_insertion CI;
Points P;
public static boolean useNNh= false;
boolean useCI=false;
boolean triangleDrawn = false;
boolean CIupdate;
void drawpoints (Graphics g)
Graphics2D g2 = (Graphics2D) g;
Graphics2D g3 = (Graphics2D) g;
int i=1;
g2.setColor(Color.red);
if (P==null) return;
else
while (i<P.getSize())
Ellipse2D.Double vertices = new Ellipse2D.Double(P.x_coor,P.y_coor[i],10,10);
g2.fill(vertices);
i++;
g3.setColor(Color.MAGENTA);
Ellipse2D.Double initial = new Ellipse2D.Double(P.x_coor[0],P.y_coor[0],10,10);
g3.fill(initial);
System.out.println("No. of Vertices: " + P.getSize());
for(int k = 0; k < P.getSize(); k++)
System.out.println("x coordinate: " + P.x_coor[k] + ", " + "y coordinate :" + P.y_coor[k] );
// System.out.println("next:"+ P.x_coor[k+1]);
triangleDrawn = false;
void drawLineNNh(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.blue);
int i = 0;
if (P == null) return;
else
for(i=0; i<P.getSize(); i++)
Line2D.Double drawLine = new Line2D.Double(P.x_coor[nnH.seen[i]]+5, P.y_coor[nnH.seen[i]]+5, P.x_coor[nnH.seen[i+1]]+5,P.y_coor[nnH.seen[i+1]]+5);
Line2D.Double drawLastEdge = new Line2D.Double(P.x_coor[nnH.seen[P.getSize()-1]]+5, P.y_coor[nnH.seen[P.getSize()-1]]+5, P.x_coor[0]+5,P.y_coor[0]+5);
g2.drawString( " Total Distance : " + nnH.totalDistance , 10, 300);
g2.draw(drawLine);
g2.draw(drawLastEdge);
public void set (Points p)
P=p;
useNNh = false;
useCI = false;
public void setNNh(Points p)
nnH = new NNheuristic(p);
useNNh = true;
void frame (Graphics g)
g.setColor(Color.white);
g.fillRect(0,0,size().width,size().height);
g.setColor(Color.green);
g.drawRect(0,0,579,280);
public void paint(Graphics g)
frame(g);
drawpoints(g);
if(useNNh)
drawLineNNh(g);
else if(useCI)
if(!CIupdate)
drawTriCI(g);
else
drawRestCI(g);
// drawLineNNh(g);
public void clear ()
// remove the points and the graph.
P=null;
triangleDrawn = false;
code of my GUIpublic class TSP extends JFrame{
JButton run;
...................codes...........
TSP() {
...............................codes...........
run = new JButton ("Run");
run.setPreferredSize(new Dimension(113,30));
run.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Run")) {
if (chooseHeur.getSelectedItem()=="Nearest-Neighbour")
System.out.println(chooseHeur.getSelectedItem());
//points = new Points(toInt((String)chooseNum.getSelectedItem()));
//PlotArea.set(points);
PlotArea.setNNh(points);
PlotArea.repaint();
else if(chooseHeur.getSelectedItem()=="Closest-Insertion")
PlotArea.setC_I(points);
PlotArea.repaint();
pane2.add(run);
Similar Messages
-
Is there a way to draw a straight line from one point to another?
Is there a way of drawing a straight line from one point to another please?
Yes. First click on this icon:
Now select the line drawing icon:
Now press a shift key and drag your mouse on the image to draw a straight line.
These instructions are for Windows system so you need to adapt the method for Macs. I can't afford to by an Apple Mac!!!!!
Good luck. -
Drawing a line from one nested MC to another
I'm using the Drawing API to draw a line from one MC nested
within two levels of parent MCs to another similarly-nested MC. Can
someone tell me how to get the X,Y coordinates of both points?Try this:
var objPointA:Object = new Object()
var objPointB:Object = new Object()
objPointA.x = grandparentA_mc.parentA_mc.childA_mc._x;
objPointA.y = grandparentA_mc.parentA_mc.childA_mc._y;
objPointB.x = grandparentB_mc.parentB_mc.childB_mc._x;
objPointB.y = grandparentB_mc.parentB_mc.childB_mc._y;
grandparentA_mc.parentA_mc.localToGlobal(objPointA);
grandparentB_mc.parentB_mc.localToGlobal(objPointB);
var lineHolder = _root.createEmptyMovieClip("lineHolder", 1);
lineHolder.lineStyle(1, clr, 100);
lineHolder.moveTo(objPointA.x, objPointA.y);
lineHolder.lineTo(objPointB.x, objPointB.y);
Remove '_spamkiller_' to mail -
How do I transfer an Itunes gift card from one account to another ? I do not remember my password or know my security questions.
You can't do it yourself. If you've just redeemed it and not spent any of it then you could try contacting iTunes Support and see if they can move it the other account : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
-
How can I move the ODI Work Repository from one server to another server?
How can I move the ODI Work Repository from one server to another server?
Hi,
If you would like to move your source models, target models and project contents from Work repository 1 to another work repository.
I.e. Dev. server to Prod Server.
1. Firstly, replicate the master repository connections i.e. with same naming conventions manually
2. Go to Dev. Server work repository -> File Tab -> Click on Export work repository (save it in a folder)
3. After exporting, you can view the xml files in the folders.
4. Now, Open the Prod. server and make sure you already replicated mas. rep. details.
5. Now, right click on model and import source model in synonym mode insert_update (select source model from the folder where your xml file located)
6. Similarily, import again target then Project.
Now, check. It should work.
Thank you. -
How can I transfer my app store purchases from one account to another?
Can I transfer my apps to a new iTunes account from my old one? How?
Thanks.No, you cannot transfer apps from one account to another iTunes account. Apps are DRM protected and forever tied to the account used to originally obtain them.
-
How can I make a Face Time call from one country to another( supporsing both parties using iphone 4s). What will be the caller charges. If there is no charges as we use wifi, will there be a charge till connecting the call?
FaceTime is free to use. You will not be charged for using FaceTime.
-
How can I transfer my apple ID acc from one Itouch to another ?
How can I transfer my apple ID acc from one Itouch to another ?
No, you cannot transfer apps from one account to another iTunes account. Apps are DRM protected and forever tied to the account used to originally obtain them.
-
How do I transfer my SMS text messages from one Iphone to another or to my Macbook Pro?
Or you can be guided bt this 'officail' Apple support document:
http://support.apple.com/kb/PH4441
Ciao.
Csound 1 greetings: Nothing wrong with a little plagiarism. -
How to pass column name as a values from one page to another
hi
i have created a report(pivot) from a table
SQL> SELECT * FROM T;
C1 C2 C3 D SEQ
A AA 2 1
A AB 3 2
A AC 2 3
B AB 5 4
B AC 6 5
SQL> SELECT C1
2 ,NVL(MAX(CASE WHEN C2='AA' THEN C3 END),'') AA
3 ,NVL(MAX(CASE WHEN C2='AB' THEN C3 END),'') AB
4 ,NVL(MAX(CASE WHEN C2='AC' THEN C3 END),'') AC
5 ,SUM(C3) FROM T GROUP BY C1;
C1 AA AB AC SUM(C3)
A 2 3 2 7
B 5 6 11
SQL>
my requirement in Apex is like this(reverse)
eg-
when i click on cell values '2' then,it should return
C1 C2 C3 D SEQ
A AA 2 1
{quote}how to pass column name as a values from one page to another
for example i have to pass 'c2' as a value to next page{quote}for report pivot you can reffer below link
Report
Amuthanks for your reply
i 'm doing what exactly you mention here .
my problem here is
i have 15 columns
i am executing a query based on the values of the column(column name) in the target page
1)here i am passing(all) the column values to the next page-but i want to pass only one column values(column name)
when i click on any cell of that column
OR
2)i can pass all column name to target page -there(in the target page) i can filter out
i think option 1 would good if you filter out the unwanted columns
Regards
Amul -
How to use utl_ftp package to transfer files from one system to another
Hi all,
How to use utl_ftp package to transfer files from one system to another using plsql procedure .
I failed to find the appropriate document ,kindly help me .
Thanks,
P Prakashprakash wrote:
I am sorry tell you, this blog is not enough to for me.It's not a blog, it's Chris' website where you download the package from. Once you download the package and unrar it, then the package spec gives instructions (and I think there's instructions on how to install it too).
Kindly let me know if there is any oracle documentation for this .It's not an Oracle created package, it was created by Chris. It's based around the UTL_TCP package if you really want to get into the nitty gritty of how it works, but I don't think you do. -
help! I recently upgraded my iphone to the latest IOS but my GPS seems to have a problem... I am unable to get directions from one point to another ... how do I solve this problem?
If using the built-in Maps app, directions are not available everywhere. Read here:
http://www.apple.com/ios/feature-availability/#maps-directions
If that's your problem, download the Google Maps app. -
T code to Copy Data from one table to another table
Hi,
I want copy all data of one table to its copy table. Anyone knows transaction code to copy data from one table to another table.
Regards,
Jigar Thakkar.Hi
Create a small program.
Extract data from T1 - database table and put it in one internal table - itab1.
loop the itab1 data .............
insert itab1 into tab2. (tab2 - second database table)
endloop.
try this....
hope it works.... -
How do i transfer music i have bought from one laptop to another?
how do i transfer music i have bought from one laptop to another?
Welcome to the Apple Community messilionel.
The following article(s) may help you.
Moving your iTunes library to a new computer -
How do you move adobe acrobat XI pro from one computer to another?
how do you move adobe acrobat XI standard pro from one computer to another?
Hi jeszamom,
You'll need either the installation media (if you bought from a retailer), or a downloaded installer. If you don't have the CD, you can download Acrobat from this links in this document: Download Acrobat products | Standard, Pro | XI, X - Adobe.
It's OK to keep it on the other computer; your license allows you to install it on up to two computers. But, if you'd like you can deactivate it on that old computer, which would free up that activation for use on yet another computer. Please see Activation & Deactivation Help - Adobe
You'll need your serial number to activate on the new computer.
Please let us know how it goes.
Sara
Maybe you are looking for
-
Hard Drive crash, creating a new iTunes Library from my iPhone
Hi, My hard drive crashed with my iPhone back up and all my pictures, music etc. I have no back up. I need now to make sure my iPhone is backed up and get my photo's off the phone. So I have created a new iTunes and iPhoto file and copied the picture
-
In Acrobat 9 Pro, when creating forms and testing the fields, I have to jump back and forth between Preview and Edit Layout view. In Preview view, the list of form fields on the left disappears; back in Edit Layout view the list of form fields reappe
-
Can't get redemption code recognition when trying to install on 2nd computer
I am trying to install Elements on a 2nd computer as the first one is not functioning properly. When I try to get the serial number through the redemption code, it doesn't recognize the code. Can someone assist? Thanks!
-
HT201302 How to import photos that are imported from itunes back to iphoto?
I had imported photos from Itunes( Iphoto ) to my iphone and i deleted all the photos in Iphoto. Now I wanted to control some of the photos but I can't! If I sync photos again, all the photos will be gone. So I wanted to import the photos in my Iphon
-
Update podcasts automatically using iTunes12.01
Is it possible to update podcasts automatically in iTunes 12.01.06? Clicking the three little buttons is a pain