Why won't this work? I'm trying to make a ball appear and move along my screen but it's failing :'( . I'm :( and also trying to make it so when you press any key it restores the full screen but that's also failing. :'( Can anyone help?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class main extends JFrame implements MouseListener{
class keyl implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyReleased(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyTyped(KeyEvent e) {
s.RestoreScreen();
}
}
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
main m = new main();
m.run(dm);
while(right == false){x--;}while(right == true){x++;}
while(down == false){y--;}while(down == true){y++;}
if(x <= 0){right = true;}if(x >= m.getWidth()){right = false;}
if(y <= 0){down = true;}if(y >= m.getWidth());
}
private title s;
private Image bg;
private Image ball;
private static int x = 0;
private static int y = 0;
private static boolean right = false;
private static boolean down = false;
private boolean loaded = false;
public void paint(Graphics g){
g.clearRect(0,0,getWidth(),getHeight());
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
if(loaded){
g.drawImage(bg,0,0,null);
g.drawImage(ball,x,y,null);
}
g.drawString("Click To Start or Press Any Key To Exit",180,500);
}
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.YELLOW);
setFont(new Font("Comic Sans MS",Font.PLAIN,24));
loaded = false;
loadpics();
addMouseListener(this);
addKeyListener(new keyl());
title s = new title();
try{
s.setFullScreen(dm,this);
}
catch(Exception ex){}
}
public void loadpics(){
bg = new ImageIcon("C:\\Documents and Settings\\Lam\\My Documents\\My Pictures\\fun.png").getImage();
ball = new ImageIcon("C:\\Program Files\\Ds Game Maker\\Resources\\Sprites\\Ball.png").getImage();
loaded = true;
repaint();
}
@Override
public void mouseClicked(MouseEvent arg0) {
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
}