Yeah, :D I made it work!
if(e.getKeyCode() == 38)
{
y = player1.getY();
System.out.println("Pressed");
// y = 200;
...
Type: Posts; User: Fermen
Yeah, :D I made it work!
if(e.getKeyCode() == 38)
{
y = player1.getY();
System.out.println("Pressed");
// y = 200;
...
Because the Y value is the components Y - value. When I change the Y value
int y = 100; the component is changing it's position. Then I just thought it sounded reasonable that it would also change...
Because I change the value of y:
y = y + 10;
Or?? wouldn't that work?
I tried using the .setFocusable(true) in "public Spelplan". I also kept the printline "Pressed" inside the if-statement. Now it says "Pressed", but the component does not move.
Why won't my "player1" move???
Class with main
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
Oh, I think I found out the error now. I should have extended my VisaStapel - class with JPanel instead of JFrame...
Thanks for the help everyone :)
Yes, this change make it work. But it should, according to my instructions work the way I wrote it to. This is the error:
Exception in thread "main" java.lang.IllegalArgumentException: adding a...
Why do I get this error? --> Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
It's ridiculous... I'm just adding a JPanel to a JFrame..or?
Class...
Thank you very much sir. Start to get the thing with the drawing now :D
Hello, I wonder why my oval doesn't show up on the frame.
Class with the oval
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
Hi,
I use this to draw up an image file on the JFrame. But instead of giving x and y pos I want the img to go with the flowlayout like the rest of my code (JButtons and such). How do I do?
...
Thanks :D I looked further and fixed my manifest as it was not correctly made.
I'm going to compile a project. I do like in this example below marked in red and the cmd says it compresses to a jar. The .jar ends up in the same folder as the mainclass and when I press the .jar...
I do like in this example below marked in red and the cmd says it compresses to a jar. The .jar ends up in the same folder as the mainclass and when I press the .jar file I just hear that "windows...
Hi :cool:,
I want to have a picture on the JFrame and for that I use the 2 lines of code below this patagraph. The problem is that when I compile it to .jar, I can only see the picture on the...
It's solved now :D Ok I should think of that
This class shows a GUI with a JLabel, a JButton and a JTextField. When klicking the button, an array of Strings in another class randomizes a String from the array and adds it to the textfield in...
Ok yes thanks a lot :), it helped me understand a bit about classes. Then I looked on the code of a almost similar program we wrote in school and did it like this.
CLASS 1
public class...
Hi, I want to return a randomized string from Class2 to Class1 (the classes are in same "Project". How do I do to make the returned String relevant in Class1?
CLASS 1
public class p12NameGen
{...