Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Guesuper Guesuper is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 408
Rep Power: 15
Guesuper mempunyai hidup yang Normal
Default [ASK] Tentang JAVA(J2SE): Terjadi Flicker. Tolong dong

kenapa ya kok jadinya flicker di layar?



Nih listingnya gan. Pendek kok. Cuman 81 baris.

Tujuanku mau buat game adventure 2D. Cuman aku harus tau konsep2 dasar di java. Jadi aku latihan mini2 gini.

CELAKANYA, mini2 kayak gini ajah udah error. Apalagi nanti kalo udah kompleks. Tolong banget ya gan...




Code:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author MWC
*/
public class MayBeBounceTest implements KeyListener{
//Final Property
public final int WIDTH=800;
public final int HEIGHT=600;

public JFrame frame;
public Graphics g;
public boolean isRunning;

public static void main(String[] args){
new MayBeBounceTest();
}

public MayBeBounceTest(){
frame=new JFrame();
frame.setSize(WIDTH, HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
frame.addKeyListener(this);
frame.createBufferStrategy(2);


isRunning=true;
while(isRunning){
g=frame.getGraphics();
draw(g);
g.dispose();
update();
}

System.exit(0);
}

public void draw(Graphics g){
//Background
g.setColor(Color.BLACK);
g.fillRect(0, 0, WIDTH, HEIGHT);

//Draw Oval
g.setColor(Color.WHITE);
g.drawOval(100, 100, 100, 100);
}

public void update(){
BufferStrategy strategy=frame.getBufferStrategy();
if(!strategy.contentsLost())strategy.show();
}

public void keyTyped(KeyEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}

public void keyPressed(KeyEvent e) {
if(KeyEvent.VK_ESCAPE==e.getKeyCode()){
isRunning=false;
}
}

public void keyReleased(KeyEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
}



</div>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Terkait
Thread Thread Starter Forum Replies Last Post
Dibutuhkan cepat programmer Java J2EE dan Java J2SE InsentifGede Lowongan kerja 0 23rd October 2012 10:39 PM
tolong bantung Tentang Service BB TAM dong lumpiabasah Lounge 0 27th May 2012 06:56 PM
&lt;ask&gt;+ tolong tentang java Darkc0der Programming 0 20th November 2011 10:54 PM
Yang MASTER JAVA,,Tolong saya dong ??? SinggahDapur Programming 0 20th November 2011 01:26 AM

 


All times are GMT +7. The time now is 09:55 PM.