Question:
What is wrong with my coding? ~Java?
Greggy
2013-02-08 16:26:03 UTC
http://gyazo.com/2d32f972c1afd0c49e9f6646d3bf40fe
http://gyazo.com/f2f7ba99a808b8b4810f8b20e89f38c1
http://gyazo.com/be79cbf8ee3ed587fbd4d8f95e029fa8
http://gyazo.com/5f1081df52d3036949b356040f8895c9


Text:





package game;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.util.BitSet;

/**
*
* @author Austin
*/
public class Ausc extends Game {

int characterSize = 20;
int x, y;
BitSet keyBits = new BitSet (256);
boolean A = false;
boolean D = false;
boolean W = false;
boolean S = false;

Ausc() {
title = "Ausc";
width = 400;
height = 400;

x = (width / 2) - (characterSize / 2);
y = (height / 2) - (characterSize / 2);
}

@Override
public vid update() {
if (A && S) {
moveLD();
} else if (A && W) {
moveLU();
} else if (A) {
moveL();
} else if (D && S) {
moveRD();
} else if (D) {
moveR();
} else if (S) {
moveD();
} else if (W) {
moveU();
}
}

@Override
public void draw(Graphics2d g) {

RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderHints.VALUE_ANTIALIS_ON);
rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHints(rb);

g.setColor(Color.WHITE);
g.fillRecr(0, 0, width, height);

g.setColor(Color.BLACK);
g.fillOval(x, y, characterSize, characterSize);
}

@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_A:
A = true;
break;
case KeyEvent.VK_D:
D = true;
break;
case KeyEvent.VK_W:
W = true;
break;
case KeyEvent.VK_S:
S = true;
break;
}
}

@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_A:
A = false;
break;
case KeyEvent.VK_D:
D = false;
break;
case KeyEvent.VK_W:
W = false;
break;
case KeyEvent.VK_S:
S = false;
break;
}
}

public static void main(String[] args) {
FrameApplication.start(new Ausc());
}

private void moveLD() {
x -= step;
y += step;
}

private void moveLU() {
x -= step;
y -= step;
}

private void moveL() {
x -= step;
}

private void moveRD() {
x += step;
y += step;
}

private void moveRU() {
x += step;
y -= step;
}

private void moveR() {
x += step;
}

private void moveD() {
y += step;
}

private void moveU() {
y -= step;
}
}
Four answers:
2013-02-08 16:59:14 UTC
1. The update() method is supposed to have the return value "void", not "vid".

2. The parameter "g" for the draw method should be "Graphics2D" instead of "Graphics2d".

3. When declaring the variable rh, the parameters should be "RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON" as they were misspelled and formatted wrong.

4. The variable "rh" should be used instead of "rb" in "g.setRenderingHints(rb);".

5. "g.fillRecr()" should be "g.fillRect()".

6. The Object "FrameApplication" and the variable "step" could not be found.



I would recommend that you use a program that tells you exactly what you've done wrong and offers suggestions to you code, such as the Eclipse IDE for Java Developers. Since I don't have access to the code in the other classes (Game, FrameApplication) I'm not completely sure about suggestion 6; it may not apply. Good luck with your project!
Erika
2016-12-05 04:35:09 UTC
i don't understand what you propose by using "marked as unread". even with the undeniable fact that, one subject you're transforming into is which you're comparing 2 Strings with the == operator. while utilized to merchandise varieties, like String, the == operator compares the references — in truth that is checking to look if the two variables examine with an identical merchandise. it does not make sure the values of those products. What you will desire to do is locate the String type's equals() technique to examine them, like so: if (character.Equals("Bob")) which will would desire to get you the end result you opt for.
Mystic
2013-02-08 16:35:00 UTC
public vid update() {

to

public void update() {



public void draw(Graphics2d g) {

to

public void draw(Graphics2D g) { // note capitalized 'D'



g.setRenderingHints(rb);

to

g.setRenderingHints(rh);



don't know about the others

because i don't have code of

FrameApplication and Game

classes
Ratchetr
2013-02-08 16:30:47 UTC
Can you tell us what is wrong with your code?



Does it not compile? If not, what error message(s) are you getting? Which lines of code have errors?



Does it compile but blow up when you run it? If so, what is the error message you get?



Does it compile and run, but just not do what you think it should do? If so, what does it do that you don't want it to do? Or what doesn't it do that you do want it to do?



Tell us what is wrong with your code, and somebody here can probably tell you what is wrong with your code.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...