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

  • Home
  • SEARCH
  • 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 8907639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:58:09+00:00 2026-06-15T02:58:09+00:00

I have an if statement that is only evaluated when in debug mode MyStuff

  • 0

I have an if statement that is only evaluated when in debug mode

MyStuff class (the “main” class);

package com.lorenjz.jambii;

import java.io.IOException;

public class MyStuff {

   public static void main(String[] args)throws IOException {
      ControlGack gack = new ControlGack();
      gack.setVisible(true);
      new Thread() {
         public void run() {
            MainWindow mW = new MainWindow();
            mW.run();
        }}.start();
      Client c = new Client();
      try {
         c.run(null);
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}

A window that extracts RGB color averages for the screen that it resides in:

package com.lorenjz.jambii;

import java.awt.AWTException;

public class MainWindow extends JFrame implements ComponentListener, Runnable{

    static int currentPixel;
    static int red;
    static int blue;
    static int green;
    private JPanel contentPane;
    static JPanel panel;
    static myPrefs mP;
    static Boolean serverState = false;

    public static class Globals{
        static int screenWidth = 1366;
        static int screenHeight = 768;
        static int RedforSend = 0;
    }

    public void run() {
EventQueue.invokeLater(new Runnable() {
       public void run() {
          try {
             MainWindow frame = new MainWindow();
             frame.addComponentListener(frame);
             frame.setLocation(mP.getMWXPos(), mP.getMWYPos());
             frame.setVisible(true);
          } catch (Exception e) {
             e.printStackTrace();
          }
       }});
       while (true){
          Robot robot;
          try {
             robot = new Robot();
             BufferedImage screenShot =
                robot.createScreenCapture(
                   new Rectangle(
                      new Dimension( Globals.screenWidth,Globals.screenHeight )));
             for (int xPosition = 0; xPosition < Globals.screenWidth; xPosition ++) {
                for (int yPosition = 0; yPosition < Globals.screenHeight; yPosition++){
                   currentPixel = screenShot.getRGB(xPosition, yPosition);
                   red = red +(int) (255 & (currentPixel >> 16));
                   green = green + (int) (255 & (currentPixel >> 8));
                   blue = blue + (int) (255 & (currentPixel));
                }
             }
             int numberOfSidePixels = Globals.screenWidth * Globals.screenHeight;
             red = red /numberOfSidePixels;
             green = green /numberOfSidePixels;
             blue = blue /numberOfSidePixels;
             Globals.RedforSend = red;
             if(serverState==true){
                Client.sendToServer(red,green,blue);
                Client.newMessage();
             }
             Color background = new Color(red, green, blue);
             panel.setBackground(background);
          } catch (AWTException e) {
             e.printStackTrace();
          }
       }
    }

   public MainWindow() {
      mP = new myPrefs();
      mP.init();
      setBounds(100, 100, 175, 165);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
      panel = new JPanel();
      panel.setBounds(20, 15, 135, 115);
      contentPane.add(panel);
   }

   void saveFrame(JFrame frame) throws IOException {
      String X = String.valueOf(frame.getX());
      String Y = String.valueOf(frame.getY());
      int xPos = frame.getX();
      mP.setMWXPos(xPos);
      int yPos = frame.getY();
      mP.setMWYPos(yPos);
    }

    @Override
    public void componentHidden(ComponentEvent e) {
    }

    @Override
    public void componentMoved(ComponentEvent e) {
      System.out.println(
         "componentMoved event from " + e.getComponent().getClass().getName());
      try {
         saveFrame((JFrame) e.getComponent());
      } catch (IOException e1) {
         e1.printStackTrace();
      }
    }

    @Override
    public void componentResized(ComponentEvent e) {
    }

    @Override
    public void componentShown(ComponentEvent e) {
      System.out.println(
         "shown event from " + e.getComponent().getClass().getName());
    }

    public static void switchServerState(){
      serverState = true;
    }
}

And Finally the client class that I would like to forward the RGB Data onto a server:

package com.lorenjz.jambii;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {
    static String fromUser;
    static Boolean nm = false;
    //static PrintWriter out;
    public void run(String[] args) throws IOException {

        Socket kkSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            kkSocket = new Socket("LorensMBA.local", 4444);
            // TODO code server for pref from controlGack text input
            out = new PrintWriter(kkSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: LorensMBA.");
            //System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: LorensMBA.");
            //System.exit(1);
        }

        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String fromServer;


        while ((fromServer = in.readLine()) != null) {
            System.out.println("Server: " + fromServer);

            if(fromServer.equals("Ready to Go")){
                System.out.print("Rockin");
                out.print("myStuff");
                MainWindow.switchServerState();
                }

            if (fromServer.equals("Bye."))
                break;

            //fromUser = stdIn.readLine();


            //if (nm = true){
            if (fromUser != null) {
                System.out.println("Client: " + fromUser);
                out.println(fromUser);


            }
            nm = false;
            //}
        }

        out.close();
        in.close();
        stdIn.close();
        kkSocket.close();
    }

    public static void sendToServer(int redV, int greenV, int blueV){
        //out.println("Stupid");
        fromUser = "@R"+ redV+",G"+greenV+",B"+blueV;
    }
    public static void newMessage(){
        nm = true;
    }
}


'

“if (fromUser != null)” in the client class only seems to be evaluated when I set a breakpoint. I must be missing something here. The way that I intend for this to all work out is that the MainWindow will send an RGB value to the client class every time that a screenshot. Can someone point me in the direction of where I have gone wrong?

Thanks,
Loren

  • 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-15T02:58:10+00:00Added an answer on June 15, 2026 at 2:58 am

    fromUser will be not null only after sendToServer has been called. And sendToServer is called asynchronously in a thread.

    My guess is that when you run the code normally, sendToServer has not run yet when your if statement is executed and fromUser is still null.

    In debug mode, the thread has more time to do its stuff and manages to call sendToServer before you reach the if statement.

    Also I noticed that you have 2 instances of MainWindow – not sure if that is what you want.

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

Sidebar

Related Questions

I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in
I'm trying to set up an XSL:IF statement that only shows entries that have
I have a series of PHP statements that I only want to run if
I have a case statement that returns a date; case when (ma.first_active_date is not
I have a sql statement that concatenates two columns, ItemNumber and Name, into one
I have an UPDATE statement that's intended to update a status field for a
I have an IF statement that consists of two separate function calls passing values
I have a LINQ statement that returns an anonymous type. I need to get
I have an SQL statement that I'm executing through OleDb, the statement is something
I have a switch statement that has over 300 case statements. case 'hello': {

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.