Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 86,374 Java Programmers. There are 1,415 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Java Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

NetBeans question (proper programming practices)

 
Reply to this topicStart new topic

NetBeans question (proper programming practices)

blake11
post 9 May, 2008 - 04:51 AM
Post #1


New D.I.C Head

*
Joined: 20 Feb, 2008
Posts: 36



I am messing around making a small Server-Client application to send out popups to workstations on our network. I created the GUI in NetBeans, and I am not sure how to complete this in the proper fashion. I find myself making programs work, not really knowing if this is how the rest of the "real programmers" in the world would do it the same way.

So, anyone that uses Netbeans knows that the GUI layout is placed in a method

CODE

private void initComponents()


which is located under the No arg constructor of the GUI that you are making. So do I place my Socket constructors in the No arg constructor of my GUI, like so

CODE

try
        {
            //Create server socket//
            ServerSocket serverSocket = new ServerSocket(8001);
            jta.append("Server started at " + new Date() + "\n");
            
            //Listen for connection request//
            Socket socket = serverSocket.accept();
            
            //Create data input and output streams//
            DataInputStream inputFromClient = new DataInputStream(
                    socket.getInputStream());
            DataOutputStream outputToClient = new DataOutputStream(
                    socket.getOutputStream());
        }
        
        catch(IOException ex)
        {
            errorLabel.setText("Error connection to clients!");
        }


This is how I thought it was supposed to be done, since the jta.append() and errorLabel.setText() will both tell my I am trying to refrence a non-static variable if I was to put this in "main". But, by putting them under my GUI constructor, it does not even recognize jta(JTextArea) and errorLabel(JLabel) as existing. What is the proper way of doing this?

Thanks for any help guys.

This post has been edited by blake11: 9 May, 2008 - 04:52 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


blake11
post 9 May, 2008 - 04:56 AM
Post #2


New D.I.C Head

*
Joined: 20 Feb, 2008
Posts: 36

I think I had one to many "}" going on in there. Would still be helpful if someone could let me know if I am looking at this the right way.

Thanks
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

1lacca
post 9 May, 2008 - 05:32 AM
Post #3


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,192

I would suggest putting these things into a completely different class.
If you want to log to some GUI elements, then you could create an interface that consists of the logging functions, that can be implemented by the GUI class, and when you create the class that does the logic, you could pass the GUI class to it's constructor as the logger.
Search for 'MVC pattern' to learn more about why I would suggest it. (There might be an introduction to it here on DIC, but google should definitely show you plenty of results)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 02:51AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month