Two loops speeds drawing in a Jframe
Posted
by
noahn567
on Stack Overflow
See other posts from Stack Overflow
or by noahn567
Published on 2014-08-22T21:01:06Z
Indexed on
2014/08/22
22:21 UTC
Read the original article
Hit count: 233
I have a program that requires two classes. The player-Names class, and the Player-Model class. I want the player-Names class to repaint every half second, and the Player-Model class to repaint 60 times per second because i want the movement to be smooth. The problem that i am having is that i want all of this to be done on one J-frame. How would i go about doing this? If you could lead me in the right direction or give me a little example that would be great! Thank you :).
for some reason it wont let me post so i'm going to put in some random code
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class PlayerNames extends JFrame {
static int connectionTimer = 0;
static int connectionTimer2 = 0;
static int reconnect = 0;
static int reconnectValue = 1;
static int x = 0;
static int reconnectWait = connectionTimer + reconnectValue;
private static final long serialVersionUID = 1L;
public graph gg = new graph();
public graph g = new graph();
private static GameClient socketClient;
private GameServer socketServer;
public static void main(int width, int height) {
PlayerNames tt = new PlayerNames();
// PlayerGraphics t = new PlayerGraphics();
tt.setSize(width, height);
if (Game.ServerOwner == 1) {
tt.setTitle("Server: " + Game.username);
} else {
tt.setTitle("Username: " + Game.username);
}
tt.setVisible(true);
tt.getContentPane().add(tt.gg);
tt.getContentPane().add(tt.g);
tt.setDefaultCloseOperation(EXIT_ON_CLOSE);
tt.setResizable(false);
}
© Stack Overflow or respective owner