producing javadoc

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2005
Posts: 2
Reputation: ismedave is an unknown quantity at this point 
Solved Threads: 0
ismedave ismedave is offline Offline
Newbie Poster

producing javadoc

 
0
  #1
Dec 30th, 2005
Hello, I want someone to comment off the following coding so that I can produce appropriate javadocs. Thanks. Here's the coding:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
import java.util.Random;
import javax.swing.*;

public class ShellGame extends JPanel implements ActionListener
{
final int ROWS = 10;
final int COLS = 10;
final int PAD = 20;
final int EMPTY = 0;
final int COIN = 1;
final int LINEAR = 0;
final int BINARY = 1;
int[] shells = new int[ROWS*COLS];
int coin = 0;
int lastCoin = coin;
int currentShell = -1;
int high;
int low;
int searchMode;
JLabel label;
Random seed = new Random();
Seeker seeker = new Seeker(this);

public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
String ac = button.getActionCommand();
if(ac.equals("linear"))
searchMode = LINEAR;
if(ac.equals("binary"))
{
searchMode = BINARY;
high = shells.length;
low = -1;
}
if(!seeker.isRunning())
{
label.setText(" ");
coin = seed.nextInt(shells.length);
System.out.println("coin = " + coin);
shells[coin] = COIN;
shells[lastCoin] = EMPTY;
lastCoin = coin;
currentShell = -1;
seeker.start();
}
}

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
double w = getWidth();
double h = getHeight();
double xInc = (w - 2*PAD)/COLS;
double yInc = (h - 2*PAD)/ROWS;
double dia = Math.min(xInc, yInc)*3/4;
Color color;
for(int j = 0; j < shells.length; j++)
{
if(j < currentShell)
color = Color.green.darker();
else if(j == currentShell)
color = Color.red;
else
color = Color.blue;
g2.setPaint(color);
double x = PAD + (j%10) * xInc + xInc/2;
double y = PAD + (j/10) * yInc + yInc/2;
g2.fill(new Ellipse2D.Double(x-dia/2, y-dia/2, dia, dia));
}
}

public void checkNext()
{
if(searchMode == LINEAR)
currentShell++;
else // BINARY
{
currentShell = (high + low)/2;
if(currentShell > coin)
high = currentShell;
else
low = currentShell;
}
repaint();
if(shells[currentShell] == COIN)
{
seeker.stop();
Thread t = new Thread(pause);
t.setPriority(Thread.NORM_PRIORITY);
t.start();
}
}

private Runnable pause = new Runnable()
{
public void run()
{
try
{
Thread.sleep(500);
}
catch(InterruptedException ie)
{
System.err.println("pause.run interrupt: " + ie.getMessage());
}
label.setText("coin found - game over");
}
};

private JLabel getLabel()
{
label = new JLabel(" ", JLabel.CENTER);
Dimension d = label.getPreferredSize();
d.height = 25;
label.setPreferredSize(d);
return label;
}

private JPanel getUIPanel()
{
JButton linear = new JButton("linear");
JButton binary = new JButton("binary");
linear.setActionCommand("linear");
binary.setActionCommand("binary");
linear.addActionListener(this);
binary.addActionListener(this);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("search"));
panel.add(linear);
panel.add(binary);
return panel;
}

public static void main(String[] args)
{
ShellGame game = new ShellGame();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(game.getLabel(), "North");
f.getContentPane().add(game);
f.getContentPane().add(game.getUIPanel(), "South");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}

class Seeker implements Runnable
{
ShellGame shellGame;
Thread runner;
boolean keepSearching;

public Seeker(ShellGame sg)
{
shellGame = sg;
keepSearching = false;
}

public void start()
{
if(!keepSearching)
{
keepSearching = true;
runner = new Thread(this);
runner.setPriority(Thread.NORM_PRIORITY);
runner.start();
}
}

public void stop()
{
keepSearching = false;
runner = null;
}

public boolean isRunning()
{
return keepSearching;
}

public void run()
{
while(keepSearching)
{
try
{
Thread.sleep(500);
}
catch(InterruptedException ie)
{
System.err.println("Seeker.run interrupt: " + ie.getMessage());
keepSearching = false;
}
shellGame.checkNext();
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: producing javadoc

 
0
  #2
Dec 30th, 2005
It's your program, you document the methods.

http://java.sun.com/j2se/javadoc/writingdoccomments/
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 2
Reputation: ismedave is an unknown quantity at this point 
Solved Threads: 0
ismedave ismedave is offline Offline
Newbie Poster

Re: producing javadoc

 
0
  #3
Jan 3rd, 2006
No, it's not my code. I was asked by my lecturer to comment on the code and I'm stuck. Just wanted to see how you would have done it so that I can make more of it and try to understand it.

Originally Posted by Phaelax
It's your program, you document the methods.

http://java.sun.com/j2se/javadoc/writingdoccomments/
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: producing javadoc

 
0
  #4
Jan 4th, 2006
So it's your homework indeed and we're not here to do it for you.
There's ample documentation about how to write javadoc online and included with the JDK documentation, read it.
Or buy a book about the subject and read that.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1571 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC