5 Replies - 1020 Views - Last Post: 23 August 2011 - 09:02 AM Rate Topic: -----

#1 wondering_ed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-August 11

Ignorant person Java Help! ^^

Posted 22 August 2011 - 11:35 PM

Hi guys! Am new here and I am new to java. New as in totally noobie here. Our new teacher wanted to test us of how far our knowledge has reached when it comes to coding. He said we have to make a program which is to draw in a polygon shape with points A,B,C,D,E,F,G linking each point and finally to find the source of shortest distance path.

I am really confused because Java is just a new thing to my eye. We were used to web dev. not app programming. I havent even explored it yet. Could somebody here help me out? I would be really grateful. I want to learn java too. This here would be a great start for me. We're using netbeans 7.1

Is This A Good Question/Topic? 0
  • +

Replies To: Ignorant person Java Help! ^^

#2 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: Ignorant person Java Help! ^^

Posted 23 August 2011 - 12:59 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 wondering_ed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-August 11

Re: Ignorant person Java Help! ^^

Posted 23 August 2011 - 01:32 AM

oh! oh! thank you for replying! ^^ My friend which has a little knowledge on java gave me a code I could feast on. I surely dont know if this is right, but when I paste in on netbeans 7.1 it has many errors on it. I really want to learn and start here. btw here is the code.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author User
*/
public class paths{
}
import java.awt.Color;
import java.awt.Graphics;
import java.swing.*;

public class paths
{
private static void main{({String args[]}
{
myFrame g=newFame ()
coor = new int[][]{{300,400},{200,120},{170,50}{80,76}{143,100},{92,130},{55,50},{300,140}};
g.repaint();
}
static class myFrame extends JFrame
{
public myFrame()
{
setDefaultOperation(JFrame.EXIT_ON_CLOSE);
setSize(450,200);
setVisible(true);
}
public void paint(Grapics.g)
{
char a[]=new char[]{'a','b','c','d','e','f','g'};
g.setColor(Color.blue);
for(int i=0;<7;i++)
g.drawLine(coor[i][o],coor[i][1],coor[i+1][o],coor[i+1][1]);

for(int x=0;x<8;x++){
g.setColor(Color.RED);
g.fillOval(coor[x][o]-5,coor[x][1]-5,10,10);
g.setColor(Color.BLACK);ra
g.drawCharts(a,x,1 coor[x][o]-5,coor[x][1]-5);
}

Was This Post Helpful? 0
  • +
  • -

#4 supercorey   User is offline

  • D.I.C Head
  • member icon

Reputation: 119
  • View blog
  • Posts: 207
  • Joined: 15-February 09

Re: Ignorant person Java Help! ^^

Posted 23 August 2011 - 04:21 AM

There's a few things I can say for that code:
1) There really are alot of errors. myFrame g=newFame () looks totally invalid.
2) The indentation is pretty bad.
3) There's a better way of drawing polygons: JavaDoc

I understand you don't know Java very well, but those are the three main issues (and suggestions) here. Hope it helps!
Was This Post Helpful? 1
  • +
  • -

#5 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Ignorant person Java Help! ^^

Posted 23 August 2011 - 05:46 AM

I dont know if this code was written by someone who knows Java as you said. By the way, just having someone to write code for you will product nothing to you. What is the best for you is to ask him(or any) to teach you how to do it and give you some introductory concepts to make you get started.
We have some getting started tutorials(Part1, Part2 & Part3) by NeoTifa which may help you to get started.

Returning to your code:
1. class paths is defined twice, remove the first definition so the imports can be the first thing there:

2. Look at this main method definition
private static void main{({String args[]}

It should look like
public static void main(String[] args){


3. This import is not present
import java.swing.*;
swing is not in java instead it is in javax.

4. Also this line
public void paint(Grapics.g)
This is not how we declare variable(g). It is DatType VariableName no dot and it is Graphics.
Was This Post Helpful? 1
  • +
  • -

#6 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4634
  • View blog
  • Posts: 19,417
  • Joined: 24-September 08

Re: Ignorant person Java Help! ^^

Posted 23 August 2011 - 09:02 AM

Awww thanks for suggesting me! ^__^

Yes, I would use the drawPolygon method, and just use the coords you have but seperated x and y.

int[] x = {300, 200, 170, 80, 143, 92, 55, 300};
int[] y = {400, 120, 50, 76,100, 130, 50, 140};

g.drawPolygon(x, y, 8);


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1