Another question on refactoring my NetBeans generated GUI code

Hello all:

It has been a few months since my last question.  Had a lot of other projects taking up my time, but I am back to fighting with my Planetarium lighting controller.  I have it working, but I am sure it could be more efficient and prettier to look at.

Since my last post, I finally figured out how to create an object and was able to remove the global variables I had previously created.  My application now has two files and not just the long single one primarily generated by NetBeans.  This cleaned up my messy code a little, but I know that there is still more I can do.  I have been trying to pull some of the functions I created out of the single file, but I am still not getting something right and I get errors.  The IDE tells me that it cannot find the function if it is located in a separate file.

I want to have the establishConnection() and sendCommand() functions separated because I can actually use them in other programs that access the lighting control without going through the GUI.

I wanted to have the updateControlPanelLampOn() function separated because it would be easier for me to make changes if I did not have to constantly scroll down to where it starts in the long block of code.  When I take this block out, the IDE tells me it cannot find the various controls.

Just not sure what I am doing wrong.

I pasted a portion of the code here and attached it to the post.  There is also a screen capture of what the GUI looks like when it is running.  If anyone can help, I would appreciate it.

Paul

import ECCS.eccsLampDevice;
import java.io.*;
import java.net.*;
import javax.swing.UIManager.*;

public class BasicRGBWCoveGUIWithOOP extends javax.swing.JFrame {
    eccsLampDevice redCove = new eccsLampDevice();
    eccsLampDevice grnCove = new eccsLampDevice();
    eccsLampDevice bluCove = new eccsLampDevice();
    eccsLampDevice rgb0Cove = new eccsLampDevice();

    // IO streams.
    private DataOutputStream toServer;
    private DataInputStream fromServer;    
    
    /** Creates new form AdvancedRGBCoveGUI */
    public BasicRGBWCoveGUIWithOOP() {
        initComponents();
        establishConnection();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
        // Lots of code generated by NetBeans.
    }// </editor-fold>                        

 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

    // More code here.
        
    }
    

   public final void establishConnection() {
        try {
            // Create a socket to connect to the server.
            Socket socket = new Socket("192.168.10.250", 4760);

            // Create an input stream to receive data from the server.
            fromServer = new DataInputStream(socket.getInputStream());

            // Create an output stream to send data to the server.
            toServer = new DataOutputStream(socket.getOutputStream());
        }
        catch (IOException ex) {
                System.err.println(ex);
        }
    }
    
    public void sendCommand(String eccsCommand) {
        try {
            toServer.writeBytes(eccsCommand + "\r");
            
            toServer.flush();
        }
        catch (IOException ex) {
            System.err.println(ex);
        }
    }

    public void updateControlPanelLampOn(String deviceCommand, String deviceName) {
        if ("A".equals(deviceName)) {
            jSliderREDCOVE.setValue(redCove.lampLevel);
            jTextFieldREDCOVE.setText(String.valueOf(redCove.lampLevel));
            jSliderRGBCOVE.setValue(rgb0Cove.lampLevel);
            jTextFieldRGBCOVE.setText(String.valueOf(rgb0Cove.lampLevel));
        }
        else if ("B".equals(deviceName)) {
            jSliderGRNCOVE.setValue(grnCove.lampLevel);
            jTextFieldGRNCOVE.setText(String.valueOf(grnCove.lampLevel));
            jSliderRGBCOVE.setValue(rgb0Cove.lampLevel);
            jTextFieldRGBCOVE.setText(String.valueOf(rgb0Cove.lampLevel));
        }
        else if ("C".equals(deviceName)) {
            jSliderBLUCOVE.setValue(bluCove.lampLevel);
            jTextFieldBLUCOVE.setText(String.valueOf(bluCove.lampLevel));
            jSliderRGBCOVE.setValue(rgb0Cove.lampLevel);
            jTextFieldRGBCOVE.setText(String.valueOf(rgb0Cove.lampLevel));
        }
        else if ("ABC".equals(deviceName)) {
            jSliderREDCOVE.setValue(redCove.lampLevel);
            jTextFieldREDCOVE.setText(String.valueOf(redCove.lampLevel));
            jSliderGRNCOVE.setValue(grnCove.lampLevel);
            jTextFieldGRNCOVE.setText(String.valueOf(grnCove.lampLevel));
            jSliderBLUCOVE.setValue(bluCove.lampLevel);
            jTextFieldBLUCOVE.setText(String.valueOf(bluCove.lampLevel));
            jSliderRGBCOVE.setValue(rgb0Cove.lampLevel);
            jTextFieldRGBCOVE.setText(String.valueOf(rgb0Cove.lampLevel));
        }
        sendCommand(deviceCommand + ":100:" + deviceName);
    }
}

Views: 124

Attachments:

Reply to This

Happy 10th year, JCertif!

Notes

Welcome to Codetown!

Codetown is a social network. It's got blogs, forums, groups, personal pages and more! You might think of Codetown as a funky camper van with lots of compartments for your stuff and a great multimedia system, too! Best of all, Codetown has room for all of your friends.

When you create a profile for yourself you get a personal page automatically. That's where you can be creative and do your own thing. People who want to get to know you will click on your name or picture and…
Continue

Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.

Looking for Jobs or Staff?

Check out the Codetown Jobs group.

 

Enjoy the site? Support Codetown with your donation.



InfoQ Reading List

KubeCon EU: Backstage, Crossplane and Others Preparing for CNCF Graduation

More projects from the CNCF incubated level are preparing to graduate for an ever-widening cloud native ecosystem. The Backstage community has worked on a more robust architecture, and Crossplane aimed to improve its developer DX. KubeFlow and Volcano, both tools promising to improve AI adoption within the Kubernetes ecosystem, are working on easier installation and more features, respectively.

By Olimpiu Pop

How to Tame Technical Debt in Software Development

According to Marijn Huizenveld, discipline is key to preventing accumulating technical debt. In order to be disciplined you should make it difficult to ignore the debt. Heuristics like fixing small issues immediately, agreeing on a timebox for improvement, and making messy things look messy, can help tame technical debt.

By Ben Linders

xAI Opens Grok as an Open-Source Model

Elon Musk announced that xAI would make its AI chatbot Grok open source, and now the release is accessible on GitHub and Hugging Face. This move enables researchers and developers to expand upon the model, influencing how xAI evolves Grok in the face of competition from tech giants like OpenAI, Meta, Google, Microsoft, and others.

By Daniel Dominguez

Presentation: Portfolio Analysis at Scale: Running Risk and Analytics on 15+ Million Portfolios Every Day

William Chen discusses the importance of trimming your computational graph, storing data in multiple formats, leveraging open source, and considering multiple dimensions of modularization.

By William Chen

Redis Switches to SSPLv1: Restrictive License Sparks Fork by Former Maintainers

Redis has recently announced a change in their license by transitioning from the open-source BSD to the more restrictive Server Side Public License (SSPLv1). The move has promptly led to a fork initiated by former maintainers and reignited discussions surrounding the sustainability of open-source initiatives.

By Renato Losio

© 2024   Created by Michael Levin.   Powered by

Badges  |  Report an Issue  |  Terms of Service