Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Help with an JApplet that asks a user for points and draws a line from said points

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, so my teacher makes everything 100x more complicated than it should and this lab is making me so frustrated it isn't even funny. I'm sure that there is a easy solution that I am completely missing lol.

This is what he wants: He wants us to prompt the user to input x values and y values (that will be entered into an array when clicking one of the two buttons (this one will say: Add point)). When they click the second button (draw lines), it should take all the points and draw a line that connects all the points together using a method that we write. In the method we have to call the paint method up which the lines will be drawn. The lines drawn should be touching every point added. It shouldn't have parameters. It will also use Graphics painter = getGraphics(); We can't use frames either.

I have everything up until the method understood.

I guess what I really need help is an explanation on how to write a method that will draw a line from points inputted that is called up in the action listener when the second button (draw lines) is pressed.

Sorry for such a beginner question :P

Any help will be appreciated, thank you!
 
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you already know how to draw a line right? drawLine(x1,y1,x2,y2). So what difficulty exactly are you facing? So considering your case as you said you have to use an array, it can go somewhat like this

drawLine(xArr[0],yArr[0],xArr[1],yArr[1])
 
Get out of my mind! Look! A tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic