Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:13:49+00:00 2026-06-02T01:13:49+00:00

I am trying to make a GUI for a game. First off I load

  • 0

I am trying to make a GUI for a game. First off I load a welcome screen in a jFrame. They enter details and if the details are correct it should load the next screen which is in a different class. It checks the details correctly and opens the new window but does not display it, it is just black? I’m not sure if it is my computer or my code?
This is the code for the second window:

import java.net.*;
import java.io.*;
import java.util.*;

public class ClientGUI extends javax.swing.JFrame {

/**
 * Creates new form ClientGUI
 */
private BufferedWriter writer;
public ClientGUI() {
     /*
     * Set the Nimbus look and feel
     */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
     * If Nimbus (introduced in Java SE 6) is not available, stay with the
     * default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /*
     * Create and display the form
     */
    setVisible(true);
    initComponents();
}

/**
 * This method is called from within the constructor to initialise the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

    jButton1.setText("Move N");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("Move E");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jButton3.setText("Move S");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });

    jButton4.setText("Move W");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton4ActionPerformed(evt);
        }
    });

    jButton5.setText("Pickup");
    jButton5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton5ActionPerformed(evt);
        }
    });

    jButton6.setText("Quit");
    jButton6.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton6ActionPerformed(evt);
        }
    });



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    try{
        writer.write("Move N");
        writer.newLine();
        writer.flush();
    }
    catch(Exception e){
            System.out.println("error");
    }

}                                        

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   try{
        writer.write("Move E");
        writer.newLine();
        writer.flush();
    }
    catch(Exception e){
            System.out.println("error");
    }
}                                        

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
        writer.write("Move S");
        writer.newLine();
        writer.flush();
    }
    catch(Exception e){
            System.out.println("error");
    }
}                                        

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
        writer.write("Move W");
        writer.newLine();
        writer.flush();
    }
    catch(Exception e){
            System.out.println("error");
    }
}                                        

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
        writer.write("PICKUP");
        writer.newLine();
        writer.flush();
    }
    catch(Exception e){
            System.out.println("error");
    }
}                                        

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    setVisible(false);
}                                        

/**
 * @param args the command line arguments
 */
public void run(){
try {
        final Socket server = new Socket("localhost", 30000);
    //Creates the socket to be used, has to be final because of innerclass
    InputStream in = server.getInputStream();
    OutputStream out = server.getOutputStream();
    //Creates the input and output streams

    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    //Creates the reader to read what the client inputs
    final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    //Creates the reader to read what the server writes to the client, has to be final as used in innerclass
    writer = new BufferedWriter(new OutputStreamWriter(out));
    //Creates the writer so the client can write on the commandline

    Thread serverThread = new Thread(){
        //Modifies the Thread class
        public void run(){
        boolean quit = false;
        while (!quit){
            String line = "";
            try{
            line = reader.readLine();
            //Tries to read what the server has sent
            }
            catch(IOException e){
            System.out.println("Error" + e.getMessage());
            quit = true;
            //If it is unable to read what the server sent, it quits the loop
            }
            if (line != "null"){
                System.out.println(line);
            //So long as the line sent is not "null" it prints the line to the client
            }
        }
        }           
    };
    serverThread.start();
    //Starts the Thread

    String input = stdin.readLine();
    while (input != null) {
    writer.write(input);
    writer.newLine();
    writer.flush();
    input = stdin.readLine();
    //Reads what the client writes
    }
    System.exit(1);
    server.close();
} 
catch (IOException e) {
    System.out.println("error" + e.getMessage());
    e.printStackTrace();
    //Catches any errors with reading and writing to and from the server
}
}

Plus some extra swing bits that netbeans does by default.
Any help would be appreciated, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:13:51+00:00Added an answer on June 2, 2026 at 1:13 am

    Your problem may be here:

    setVisible(true);
    initComponents();
    

    You should reverse the order of this:

    initComponents();
    setVisible(true);
    

    Also, you appear to be doing Socket work. If so, hopefully you are taking care to do this in a background thread, and not in the main Swing event thread, the EDT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a GUI from Hell, and I'm trying to make the JFrame flash
I'm trying to make a small Flash game that has a GUI, which is
I am trying to make a gui with Glade 3 (gtk) and ruby but
I'm trying to make a GUI program with the Android SDK, using their Lunar
Hey guys I'm trying to make a GUI which can navigate through JTextAreas when
I am trying to learn to use the wx packages to make GUI programs
im currently trying to make a simple IRC Gui Client. Im using the SmartIrc4net
I am trying make long screen to vertical direction. So, I need a screen
i'm trying to make a simple GUI with QT 4.6. i made a separete
I'm currently trying to make a TextBox for my GUI with XNA, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.