#illegal start ot expression
1 messages · Page 1 of 1 (latest)
i am making a 2d game and for some reason, paincomponent, which is built in isnt working
*paintcomponent
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
zabuzard • used /tag id: code
·
okay
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
public class Screen extends JPanel implements Runnable{
final int standardTileSize=16; //16x16
final int scale=4;
final int currentTileSize=standardTileSize*scale; //64
final int maxColumn=16;
final int maxRow=16;
final int screenWidth=currentTileSize*maxRow; //1024
final int screenHeight=currentTileSize*maxRow; //1024
int playerXval=400;
int playerYval=400;
int playerSpeed=5;
Keyboard keyboard=new Keyboard();
Thread gameThread;
public Screen() {
this.setPreferredSize(new Dimension(screenWidth,screenHeight));
this.setBackground(Color.blue);
this.setDoubleBuffered(true);
this.addKeyListener(keyboard);
this.setFocusable(true);
}
public void update() {
if(keyboard.upPressed==true) {
yPlayer-=playerSpeed;
}
if(keyboard.downPressed==true) {
yPlayer+=playerSpeed;
}
if(keyboard.leftPressed==true) {
xPlayer-=playerSpeed;
}
if(keyboard.rightPressed==true) {
xPlayer+=playerSpeed;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics2d=(Graphics2D)g;
graphics2d.setColor(Color.red);
graphics2d.fillRect(playerXval,playerYval,currentTileSize,currentTileSize);
graphics2d.dispose();
}
}
public void thread() {
gameThread=new Thread(this);
gameThread.start();
}
@Override
public void run() {
while(gameThread!=null) {
//update stuff like character position (costume,position)
update();
repaint();
//render screen with update
//
}
}
}
Detected code, here are some useful tools:
import java.awt.Graphics;
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
public class Screen extends JPanel implements Runnable{
final int standardTileSize=16; //16x16
final int scale=4;
final int currentTileSize=standardTileSize*scale; //64
final int maxColumn=16;
final int maxRow=16;
final int screenWidth=currentTileSize*maxRow; //1024
final int screenHeight=currentTileSize*maxRow; //1024
int playerXval=400;
int playerYval=400;
int playerSpeed=5;
Keyboard keyboard=new Keyboard();
Thread gameThread;
public Screen() {
this.setPreferredSize(new Dimension(screenWidth,screenHeight));
this.setBackground(Color.blue);
this.setDoubleBuffered(true);
this.addKeyListener(keyboard);
this.setFocusable(true);
}
public void update() {
if(keyboard.upPressed==true) {
yPlayer-=playerSpeed;
}
if(keyboard.downPressed==true) {
yPlayer+=playerSpeed;
}
if(keyboard.leftPressed==true) {
xPlayer-=playerSpeed;
}
if(keyboard.rightPressed==true) {
xPlayer+=playerSpeed;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics2d=(Graphics2D)g;
graphics2d.setColor(Color.red);
graphics2d.fillRect(playerXval,playerYval,currentTileSize,currentTileSize);
graphics2d.dispose();
}
}
public void thread() {
gameThread=new Thread(this);
gameThread.start();
}
@Override
public void run() {
while(gameThread!=null) {
//update stuff like character position (costume,position)
update();
repaint();
//render screen with update
//
}
}
}
Detected code, here are some useful tools:
import java.awt.Graphics;
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
public class Screen extends JPanel implements Runnable{
final int standardTileSize=16; //16x16
final int scale=4;
final int currentTileSize=standardTileSize*scale; //64
final int maxColumn=16;
final int maxRow=16;
final int screenWidth=currentTileSize*maxRow; //1024
final int screenHeight=currentTileSize*maxRow; //1024
int playerXval=400;
int playerYval=400;
int playerSpeed=5;
Keyboard keyboard=new Keyboard();
Thread gameThread;
public Screen() {
this.setPreferredSize(new Dimension(screenWidth,screenHeight));
this.setBackground(Color.blue);
this.setDoubleBuffered(true);
this.addKeyListener(keyboard);
this.setFocusable(true);
}
public void update() {
if(keyboard.upPressed==true) {
yPlayer-=playerSpeed;
}
if(keyboard.downPressed==true) {
yPlayer+=playerSpeed;
}
if(keyboard.leftPressed==true) {
xPlayer-=playerSpeed;
}
if(keyboard.rightPressed==true) {
xPlayer+=playerSpeed;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics2d=(Graphics2D)g;
graphics2d.setColor(Color.red);
graphics2d.fillRect(playerXval,playerYval,currentTileSize,currentTileSize);
graphics2d.dispose();
}
}
public void thread() {
gameThread=new Thread(this);
gameThread.start();
}
@Override
public void run() {
while(gameThread!=null) {
//update stuff like character position (costume,position)
update();
repaint();
//render screen with update
//
}
}
}
it jad been formatted