Senin, 18 September 2023

Scroll Text in InputBox VB6

Double klik tombol Start
ketik kode di bawah ini :

Option Explicit
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private GInt, PreLen, SufLen As Integer
Const MyMessage As String = "Hello World   "

Private Sub Command1_Click()
' Start the timer
' Parameters - handle, ID, MilSecs, address of handler
SetTimer Me.hwnd, 50, 200, AddressOf TimerHandler
End Sub

Private Sub Command2_Click()
' Stop the timer
' Parameters - handle, ID
KillTimer Me.hwnd, 50
End Sub

Public Sub MoveTicker()
If GInt = Len(MyMessage) Then GInt = 1
PreLen = Len(MyMessage) - GInt
SufLen = Len(MyMessage) - PreLen
Text1.Text = Mid(MyMessage, GInt, PreLen) & Left(MyMessage, SufLen)
GInt = GInt + 1
End Sub

Private Sub Form_Load()
GInt = 1
End Sub


buat file modul baru
Modul1.bas
ketik kode di bawah ini
Public Sub TimerHandler(ByVal hwnd As Long, ByVal uMsg As Integer, ByVal idEvent As Integer, ByVal dwTime As Long)
' This is our time callback event handler
Form1.MoveTicker
End Sub

struktur folder


 

Sabtu, 09 September 2023

Minggu, 03 September 2023

GAME JAVA EMPAT

 



STRUKTUR FILE JAVA

HASIL RUN 

Run.java
package Core;

public class Run {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Window("Game Kotak").start();
        
    }
}

Window.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Core;
import inputs.KeyboardHandler;

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

import objects.Player;

/**
 *
 * @author Acer
 */
public class Window extends Canvas implements Runnable{
    private static final long serialVersionUID=1L;
    private Thread thread;
    private boolean running=false;
    
    private KeyboardHandler KListener=new KeyboardHandler(this);
    
    public Player player=new Player(100,100,64,64);
    
    public Window(String Title){
    JFrame frame=new JFrame(Title);
    frame.setSize(800,600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.add(this);
}
    public void start(){
        running=true;
        thread=new Thread(this);
        thread.start();
        
    }
    public void stop(){
        running=false;
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
    }
public void run(){
        while(running){
        tick();
        Render();
    }
    
}
public void tick(){
   player.tick();
   
}
public void Render(){
    BufferStrategy bs=this.getBufferStrategy();
    if(bs==null){
        this.createBufferStrategy(2);
        bs=this.getBufferStrategy();
    }
    Graphics g=bs.getDrawGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,this.getWidth(), this.getHeight());
    player.Render(g);
    bs.show();
    g.dispose();
}
}

KeyboardHandler.java
package inputs;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import Core.Window;
public class KeyboardHandler implements KeyListener {
private Window w;
public KeyboardHandler(Window w){
this.w=w; 
w.addKeyListener(this);
        w.setFocusable(true);
        w.requestFocusInWindow();

}
boolean MovingLeft=false;

//@Override
public void keyPressed(KeyEvent e) {
int key=e.getKeyCode();
if (key == KeyEvent.VK_D) {
w.player.velx=w.player.speed;
MovingLeft=false;
}
if(key==KeyEvent.VK_A){
w.player.velx=-w.player.speed;
MovingLeft=true;
}
}

//@Override
public void keyReleased(KeyEvent e) {
int key=e.getKeyCode();
if (key == KeyEvent.VK_D && !MovingLeft) {
w.player.velx=0;
}
if (key == KeyEvent.VK_A && MovingLeft) {
w.player.velx=0;
}
}

//@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}

}

Player.java
package objects;
import java.awt.Color;
import java.awt.Graphics;
public class Player {
public int  x,y,width, height;
public int velx, vely;
public int speed=1;
public Player(int x, int y, int width, int height){
this.x=x;
this.y=y;
this.width=width;
this.height=height;
}
public void tick(){
   // player.tick();
    x+=velx;
    y+=vely;
}
public void Render(Graphics g){
g.setColor(Color.RED);
g.fillRect(x, y, height, width);
}

}



Jumat, 01 September 2023

Game Java Tiga


Yang diubah hanya file Window.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package core;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Acer
 */
public class Window extends Canvas implements Runnable{
    private static final long serialVersionUID=1L;
    private Thread thread;
    private boolean running=false;
    public Window(String Title){
    JFrame frame=new JFrame(Title);
    frame.setSize(800,600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.add(this);
}
    public void start(){
        running=true;
        thread=new Thread(this);
        thread.start();
    }
    public void stop(){
        running=false;
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
    }
public void run(){
        long lastTime=System.nanoTime();
        double amountOfTicks=60.0;
        double ns=1000000000/amountOfTicks;
        double delta=0;
        long timer=System.currentTimeMillis();
        int updates=0;
        int frames=0;
        while(running){
            long now=System.nanoTime();
            delta += (now-lastTime)/ns;
            lastTime=now;
            while(delta>=1)
            {
                tick();
                updates++;
                delta--;
            }
        
            Render();
            frames++;
            if(System.currentTimeMillis()-timer>1000)
            {
                timer+=1000;
                System.out.println("FPS: "+ frames + "TICKS : " + updates);
                frames=0;
                updates=0;
            }
    }
        stop();
    
}
public void tick(){
    
}
public void Render(){
    BufferStrategy bs=this.getBufferStrategy();
    if(bs==null){
        this.createBufferStrategy(2);
        bs=this.getBufferStrategy();
    }
    Graphics g=bs.getDrawGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,this.getWidth(), this.getHeight());
    bs.show();
    g.dispose();
}
}


 

Game Java Dua

 



Run.java

package core;

/**
 *
 * @author Acer
 */
public class Run {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Window("Game Kotak").start();
        
    }
    
}


Window.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package core;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/**
 *
 * @author Acer
 */
public class Window extends Canvas implements Runnable{
    private static final long serialVersionUID=1L;
    private Thread thread;
    private boolean running=false;
    public Window(String Title){
    JFrame frame=new JFrame(Title);
    frame.setSize(800,600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.add(this);
}
    public void start(){
        running=true;
        thread=new Thread(this);
        thread.start();
    }
    public void stop(){
        running=false;
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
    }
public void run(){
        while(running){
        tick();
        Render();
    }
    
}
public void tick(){
    
}
public void Render(){
    BufferStrategy bs=this.getBufferStrategy();
    if(bs==null){
        this.createBufferStrategy(2);
        bs=this.getBufferStrategy();
    }
    Graphics g=bs.getDrawGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,this.getWidth(), this.getHeight());
    bs.show();
    g.dispose();
}
}