Get your CodeRanch badge!*
The moose likes Beginning Java and the fly likes Aaah I am Going Insane: Please help me find what is wrong with this script... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Aaah I am Going Insane: Please help me find what is wrong with this script..." Watch "Aaah I am Going Insane: Please help me find what is wrong with this script..." New topic
Author

Aaah I am Going Insane: Please help me find what is wrong with this script...

Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
When I run the following script, the variable armHoekWaarde isn't taken from the scrollbar but it's handeled like a normal value.
I can't find where I went wrong so please help me out!
import java.awt.*;
import java.applet.Applet;
import java. awt.event.*;
public class KraanHerMethodes extends Applet implements AdjustmentListener {
private Scrollbar horizontaal;
private Scrollbar verticaal;
private Scrollbar arm;
private Scrollbar touw;
private int horizontaalWaarde = 325;
private int verticaalWaarde = 275;
private int armLengte = 200;
private int armHoekWaarde = 45;
private int touwWaarde = 150;

//Omzetten van Graden naar Radialen
private double armHoek = ((Math.PI/180)*armHoekWaarde);

//Uit Rekenen van de x en y waarden
privateint armX = (int) ((Math.cos(armHoek))*armLengte);
privateint armY = (int) ((Math.sin(armHoek))*armLengte);


public void init() {
setLayout(null);
resize(800,600);

//ScrollBar Horizontale Beweging Kraan
Label horizontaalTitel;
horizontaalTitel = new Label("Horizontaal:");
horizontaalTitel.setBounds(180,10,70,25);
add(horizontaalTitel);
horizontaal = new Scrollbar(Scrollbar.HORIZONTAL,325,0,0,600);
horizontaal.setBounds(250,10,300,20);
add(horizontaal);
horizontaal.addAdjustmentListener(this);

//ScrollBar Verticale Beweging Kraan

//Label
Label verticaalTitel;
verticaalTitel = new Label ("Verticaal:");
verticaalTitel.setBounds(5,120,50,25);
add(verticaalTitel);
//Scrollbar
verticaal = new Scrollbar(Scrollbar.VERTICAL,275,0,0,500);
verticaal.setBounds(10,150,20,300);
add(verticaal);
verticaal.addAdjustmentListener(this);

//ScrollBar Arm Beweging

//Label
Label armTitel;
armTitel = new Label ("Arm:");
armTitel.setBounds(60,120,35,25);
add(armTitel);
//Scrollbar
arm = new Scrollbar(Scrollbar.VERTICAL,45,1,0,90);
arm.setBounds(65,150,20,300);
add(arm);
arm.addAdjustmentListener (this);


//Scrollbar Touw Beweging

//Label
Label touwTitel;
touwTitel = new Label ("Touw:");
touwTitel.setBounds(120,120,35,25);
add(touwTitel);
//Scrollbar
touw = new Scrollbar(Scrollbar.VERTICAL,150,0,0,180);
touw.setBounds(125,150,20,300);
add(touw);
touw.addAdjustmentListener (this);
}
public void paint(Graphics g) {

//Weergave Waardes
g.drawString("De Horizontale Waarde is " + horizontaalWaarde,200,100);
g.drawString("De Verticale Waarde is " + verticaalWaarde,200,125);
g.drawString("De Waarde van het Touw is " + touwWaarde,200,150);
g.drawString("De Waarde van de Armhoek is " +armHoekWaarde,200,175);

//Auto
drawAuto(g, 150, 50);

//Wielen
drawWielen(g, 25);

//Blok
drawBlok(g, 25);

//Arm
g.setColor(Color.blue);
g.drawLine(horizontaalWaarde,verticaalWaarde,horizontaalWaarde + armX, verticaalWaarde - armY);


//Touw
g.setColor(Color.green);
g.drawLine(horizontaalWaarde + armX, verticaalWaarde - armY,horizontaalWaarde + armX, verticaalWaarde - armY + touwWaarde);


}
//Methodes----------------------------------------------------------------------------------------------
//Auto
private void drawAuto(Graphics g, int autoLengte, int autoBreedte) {
g.setColor(Color.red);
g.fillRect(horizontaalWaarde,verticaalWaarde,autoLengte,autoBreedte);
}

//Wielen
private void drawWielen(Graphics g, int wielGroote) {
g.setColor(Color.black);
g.fillOval((horizontaalWaarde + 13),(verticaalWaarde + 38),wielGroote,wielGroote);
g.fillOval((horizontaalWaarde + 113),(verticaalWaarde + 38),wielGroote,wielGroote);
}

//Blok
private void drawBlok (Graphics g, int blokGrootte) {
g.setColor(Color.orange);
g.fillRect(horizontaalWaarde + armX - 13, verticaalWaarde - armY + touwWaarde,blokGrootte,blokGrootte);
}
//----------------------------------------------------------------------------------------------
public void adjustmentValueChanged(AdjustmentEvent e) {
horizontaalWaarde = horizontaal.getValue();
verticaalWaarde = verticaal.getValue();
armHoekWaarde = arm.getValue();
touwWaarde = touw.getValue();
repaint();
}
}
Sayed Ibrahim Hashimi
Ranch Hand

Joined: May 17, 2001
Posts: 148
That value is being taken from the scrollbar, but that value isn't the one that is drawing the blue line.
Here is your code

You need to update some variables here is some code to fix your problem

You needed to update the values for armHoek, armX, and armY. Just because armHoekWaarde changes that doesn't mean that all the variables that depend on that will be updated. That is your job.
Hope this helps.


SCJP 1.4<br /><a href="http://www.cise.ufl.edu/~sih" target="_blank" rel="nofollow">www.cise.ufl.edu/~sih</a>
Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23
Great! Thanks a lot! I haven't learned anything about updating yet so I didn't know how to fix it, once again thanks a bunch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Aaah I am Going Insane: Please help me find what is wrong with this script...
 
Similar Threads
Graphic g problem
drawing graph
Slot Machine
Slot Machine
Ladders and slides