Click here to Skip to main content
15,891,316 members
Home / Discussions / Java
   

Java

 
QuestionHow to use Tomcat instead of GlassFish with NetBeans? Pin
Jun Du6-Dec-11 9:22
Jun Du6-Dec-11 9:22 
AnswerRe: How to use Tomcat instead of GlassFish with NetBeans? Pin
Gerben Jongerius6-Dec-11 20:18
Gerben Jongerius6-Dec-11 20:18 
AnswerRe: How to use Tomcat instead of GlassFish with NetBeans? Pin
Skynet_Code6-Dec-11 21:02
Skynet_Code6-Dec-11 21:02 
QuestionUsing Javascript to list local directory contents Pin
Member 84548753-Dec-11 19:17
Member 84548753-Dec-11 19:17 
AnswerRe: Using Javascript to list local directory contents Pin
Richard MacCutchan3-Dec-11 21:30
mveRichard MacCutchan3-Dec-11 21:30 
AnswerRe: Using Javascript to list local directory contents Pin
TorstenH.4-Dec-11 23:55
TorstenH.4-Dec-11 23:55 
GeneralSteganography in Images and Audio Pin
khanhhungict3-Dec-11 18:35
khanhhungict3-Dec-11 18:35 
Answerhanoi tower Pin
bhira29-Nov-11 22:34
bhira29-Nov-11 22:34 
what are the coding is right for out put visualisation hanoi tower in netbeans?



import java.awt.*;

import javax.swing.*;

import no.geosoft.cc.graphics.*;



/**
* G demo program. Demonstrates:
*
*

    *
  • A sample game application
    *
  • Graphics animation
    *
  • GObject reparenting
    *

*
* @author Jacob Dreyer
*/
public class Demo14 extends JFrame
{
private TowersOfHanoi towersOfHanoi_;
private GWindow window_;
private Peg[] pegs_;
private int nDiscs_;
private JButton startButton_;



public Demo14 (int nDiscs)
{
super ("G Graphics Library - Demo 14");
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

nDiscs_ = nDiscs;

// Create the graphic canvas
window_ = new GWindow (new Color (200, 230, 200));
getContentPane().add (window_.getCanvas());

// Create scene
GScene scene = new GScene (window_);
double w0[] = {0.0, 0.0, 0.0};
double w1[] = {4.0, 0.0, 0.0};
double w2[] = {0.0, nDiscs_ * 2, 0.0};
scene.setWorldExtent (w0, w1, w2);

// Add title object and add to scene
scene.add (new Title());

// Create the 3 pegs and add to the scene
int nPegs = 3;
pegs_ = new Peg[nPegs];
for (int i = 0; i < nPegs; i++) {
pegs_[i] = new Peg (i + 1.0);
scene.add (pegs_[i]);
}

// Create the discs and add to the first peg
for (int i = 0; i < nDiscs; i++) {
Disc disc = new Disc ((double) (nDiscs - i) / nDiscs);
disc.setPosition (1.0, i);
pegs_[0].add (disc);
}

pack();
setSize (new Dimension (500, 500));
setVisible (true);

// Create the puzzle and execute the solution
towersOfHanoi_ = new TowersOfHanoi();
towersOfHanoi_.solve();
}



public void discMoved (int source, int destination)
{
// This is the disc to move
Disc disc = (Disc) pegs_[source].getChild (pegs_[source].getNChildren()-1);

double y0 = disc.getY();
double y1 = nDiscs_ + 4.0;

double x0 = pegs_[source].getX();
double x1 = pegs_[destination].getX();

// Animate vertical up movement
double step = 0.2;
double y = y0;
while (y < y1) {
disc.setPosition (x0, y);
disc.redraw();
window_.refresh();
y += step;
}

// Reparent peg
pegs_[source].remove (disc);
pegs_[destination].add (disc);

// Animate horizontal movement
step = 0.05;
double x = x0;
while (x != x1) {
disc.setPosition (x, y);
disc.redraw();
window_.refresh();
x += (x1 > x0 ? step : -step);
if (Math.abs (x - x1) < 0.01) x = x1;
}

// Animate vertical down movement
step = 0.2;
y = y1;
y1 = pegs_[destination].getNChildren() - 1;
while (y > y1) {
if (Math.abs (y - y1) < 0.01) y = y1;
disc.setPosition (x, y);
disc.redraw();
window_.refresh();
y -= step;
}
}



/**
* Graphics object for canvas title.
*/
class Title extends GObject
{
private GSegment anchor_;

public Title()
{
GStyle style = new GStyle();
style.setLineStyle (GStyle.LINESTYLE_INVISIBLE);
style.setForegroundColor (new Color (100, 100, 200));
style.setFont (new Font ("serif", Font.PLAIN, 36));
setStyle (style);

anchor_ = new GSegment();
addSegment (anchor_);

GText text = new GText ("Towers of Hanoi", GPosition.SOUTHEAST);
anchor_.setText (text);
}


public void draw()
{
anchor_.setGeometry (20, 20);
}
}



/**
* Graphics representation of a peg.
*/
class Peg extends GObject
{
private double x_;
private GSegment peg_;
private double[] xy_;


public Peg (double x)
{
x_ = x;

GStyle style = new GStyle();
style.setBackgroundColor (new Color (100, 100, 100));
setStyle (style);

peg_ = new GSegment();
addSegment (peg_);

xy_ = new double[] {x_ - 0.05, 0.0,
x_ - 0.05, nDiscs_ + 2,
x_ + 0.05, nDiscs_ + 2,
x_ + 0.05, 0.0,
x_ - 0.05, 0.0};
}


public double getX()
{
return x_;
}


public void draw()
{
peg_.setGeometryXy (xy_);
}
}



/**
* Graphics representation of a disc.
*/
class Disc extends GObject
{
private double size_;
private GSegment disc_;
private double x_, y_;


public Disc (double size)
{
size_ = size;

GStyle style = new GStyle();
style.setForegroundColor (new Color (255, 0, 0));
style.setBackgroundColor (new Color (255, 150, 150));
setStyle (style);

disc_ = new GSegment();
addSegment (disc_);
}


public void setPosition (double x, double y)
{
x_ = x;
y_ = y;
}


public double getY()
{
return y_;
}


public void draw()
{
double[] xy = new double[] {x_ - size_ / 2.0, y_,
x_ - size_ / 2.0, y_ + 1.0,
x_ + size_ / 2.0, y_ + 1.0,
x_ + size_ / 2.0, y_,
x_ - size_ / 2.0, y_};

disc_.setGeometryXy (xy);
}
}




/**
* Class for solving the "Towers of Hanoi" puzzle.
*/
class TowersOfHanoi
{
public void solve()
{
solve (nDiscs_, 0, 2, 1);
}


private void solve (int nDiscs, int source, int destination, int auxiliary)
{
if (nDiscs == 1)
discMoved (source, destination);

else if (nDiscs > 1) {
solve (nDiscs - 1, source, auxiliary, destination);
discMoved (source, destination);
solve (nDiscs - 1, auxiliary, destination, source);
}
}
}



public static void main (String[] args)
{
int nDiscs = 8;
Demo14 demo = new Demo14 (nDiscs);
}
}

help me please Cry | :((
GeneralRe: hanoi tower Pin
TorstenH.29-Nov-11 22:52
TorstenH.29-Nov-11 22:52 
GeneralRe: hanoi tower Pin
RaviRanjanKr3-Dec-11 10:12
professionalRaviRanjanKr3-Dec-11 10:12 
Generalimage procesing in java Pin
palikalirona29-Nov-11 20:10
palikalirona29-Nov-11 20:10 
GeneralRe: image procesing in java Pin
Richard MacCutchan29-Nov-11 21:44
mveRichard MacCutchan29-Nov-11 21:44 
GeneralRe: image procesing in java Pin
Nagy Vilmos5-Dec-11 1:58
professionalNagy Vilmos5-Dec-11 1:58 
GeneralRe: image procesing in java Pin
Richard MacCutchan5-Dec-11 2:21
mveRichard MacCutchan5-Dec-11 2:21 
GeneralRe: image procesing in java Pin
bharath S h14-Dec-11 15:25
bharath S h14-Dec-11 15:25 
GeneralRe: image procesing in java Pin
Richard MacCutchan14-Dec-11 22:07
mveRichard MacCutchan14-Dec-11 22:07 
QuestionRe: image procesing in java Pin
bharath S h14-Dec-11 15:27
bharath S h14-Dec-11 15:27 
GeneralRe: image procesing in java Pin
RaviRanjanKr3-Dec-11 10:17
professionalRaviRanjanKr3-Dec-11 10:17 
GeneralRe: image procesing in java Pin
bharath S h1-Mar-12 17:37
bharath S h1-Mar-12 17:37 
Questionarray sort performance java vs .net c# Pin
nipsonanomimata29-Nov-11 3:12
nipsonanomimata29-Nov-11 3:12 
AnswerRe: array sort performance java vs .net c# Pin
David Skelly29-Nov-11 3:46
David Skelly29-Nov-11 3:46 
AnswerRe: array sort performance java vs .net c# Pin
TorstenH.30-Nov-11 0:49
TorstenH.30-Nov-11 0:49 
GeneralRe: array sort performance java vs .net c# Pin
nipsonanomimata30-Nov-11 1:03
nipsonanomimata30-Nov-11 1:03 
QuestionJTable cell not going away! SOLVED Pin
venomation26-Nov-11 16:34
venomation26-Nov-11 16:34 
AnswerRe: JTable cell not going away! SOLVED Pin
TorstenH.27-Nov-11 22:33
TorstenH.27-Nov-11 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.