Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to start Applet Window in Main Class
    primarykey
    data
    text
    <p>I am designing a simple multiplayer java game. I want to run the java game in an applet from a JAR file. I my code currently is able to send coordinates to the server but when I add code to initialize the applet I will run the game in, it freezes and doesn't reach the code to send the coordinates.</p> <p>Am I doing anything wrong in my code?</p> <p>Client.java</p> <pre><code>package Client_Test; import java.net.*; import java.util.Scanner; import java.io.*; public class Client { public static void main(String [] args) throws UnknownHostException, IOException { Client_Applet Client_AppletObj = new Client_Applet(); String playerX = "3001", playerY = "300"; String serverName = "127.0.0.1"; int port = 6789; int port1 = 6788; System.out.println("Connecting to " + serverName + " on port " + port); Socket client = new Socket(serverName, port); Socket client1 = new Socket(serverName, port1); System.out.println("Connected"); Scanner test = new Scanner(System.in); OutputStream outsetup = client.getOutputStream(); OutputStream out1setup = client1.getOutputStream(); DataOutputStream out = new DataOutputStream(outsetup); DataOutputStream out1 = new DataOutputStream(out1setup); //freezes here Client_AppletObj.init(); Client_AppletObj.start(); Client_AppletObj.run(); while(true) { playerX = test.nextLine(); playerY = test.nextLine(); if (playerX == "stop") { System.exit(1); } out.writeUTF(playerX); out1.writeUTF(playerY); } } } </code></pre> <p>My Client_Applet Code: </p> <pre><code>package Client_Test; import java.applet.Applet; public class Client_Applet extends Applet implements Runnable{ @Override public void init() { this.setSize(500, 800); } @Override public void start() { Thread thread = new Thread(this); thread.start(); } @Override public void stop() { // TODO Auto-generated method stub } @Override public void destroy() { // TODO Auto-generated method stub } @Override public void run() { while(true) { repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { e.printStackTrace(); } } } } </code></pre> <p>Also I have seen some people say that coding with applets are bad, should I be using SWING?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload