basic game in java
 

 

package basicgame;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.Random;

public class Gamev1 extends JPanel implements Runnable
{
Random randomGenerator = new Random();
Thread mainthrd;
boolean running=true;
int width=400,height=400;
int MAX=1;
int currX[]=new int[MAX];
int currY[]=new int[MAX];

Gamev1()
{
    currX[0]=0;     
    currY[0]=0;     
    mainthrd=new Thread(this);
    try
    {
    mainthrd.start();
    }catch(Exception e){        System.out.println(e);System.exit(0);}

}
public void paintComponent(Graphics g)
{
    super.paintComponent(g);
    Graphics2D g2d=(Graphics2D)g;
    g2d.setBackground(Color.black);
    g2d.clearRect(0,0,width,height);
    g2d.setColor(Color.green);
    g2d.fillOval(currX[0],currY[0],20,20);
}
public void run()
{
}

public static void main(String []args)
{
    JFrame window=new JFrame();
    window.setTitle("Basic Game v1");
    window.setBackground(Color.BLUE);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.getContentPane().add(new Gamev1());
    window.setSize(800,600);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
}
}

share on whatapp
200 Views

Comments

106.215.136.141what do you means by jframe in java?
 
 
Private Policy   Terms of Service   4922