# Java Structure Help!



## 3870x2 (Apr 19, 2011)

I am setting up a program for our organization to automatically run installations and updates when a computer is first set up on a domain.

I want the best customization of the look, even if I have to set each object by the pixel using object.setBounds(x,y,width,height)

The problem is that if I use this without any particular layout, the final button using add() covers the whole window.

Let me know your thoughts (yes Kreij, lookin at you  )

I can show you the code, but because of it being a small program , but you might get sick and throw up at the amount of terrible organization and lack of notation.


```
//Directions for each task:
//COMPLETED Windows Date/Time: Control.exe TIMEDATE.CPL,,/Z (GMT-06:00) Central Time (US & Canada)
//Wired Autoconfig: net start "wired autoconfig"
//802.1x: ncpa.cpl

package arsocapp;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class buttons extends JFrame{

    JButton setTime, mapBat, openNetFolders, pushIt, set802, windowsUpdate;
    JButton wsusUpdate, socomFrame, cmdagent, gpupdateRegister;
    public buttons() {
        //Container Panel;
        //LayoutManager Layout;
        //Layout = new GridLayout();

        //Panel = getContentPane ();
        //Panel.setLayout (Layout);

        setTime = new JButton("Set Time to Central", null);
        mapBat = new JButton("Map your network drives", null);
        openNetFolders = new JButton(" Time to Central", null);
        pushIt = new JButton("Set Time to Central", null);
        set802 = new JButton("Set Time to Central", null);
        windowsUpdate = new JButton("Set Time to Central", null);
        wsusUpdate = new JButton("Set Time to Central", null);
        socomFrame = new JButton("Set Time to Central", null);
        cmdagent = new JButton("Set Time to Central", null);
        gpupdateRegister = new JButton("Set Time to Central", null);
        setTime.setBounds(0, 0, 150, 25);
        mapBat.setBounds(200,1,199,49);
        add (setTime);
        add (mapBat);
        add (openNetFolders);
        /*add (pushIt);
        add (set802);
        add (windowsUpdate);
        add (wsusUpdate);
        add (socomFrame);
        add (cmdagent);
        add (gpupdateRegister);*/

        


        mapBat.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e){
                mapBat.setEnabled(false);
                try{
        String command = "C:\\Windows\\system32\\net.exe use j: \\\\campuua-napp-01\\25b_adm";
        Runtime.getRuntime().exec(command);
                    }
                    catch (Exception err) {
                        err.printStackTrace();
                        
                }
            }
        });
        setTime.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e){
                setTime.setEnabled(false);
                try{
        String command = "Control.exe TIMEDATE.CPL,,/Z (GMT-06:00) Central Time (US & Canada)";
        Runtime.getRuntime().exec(command);
                    }
                    catch (Exception err) {
                        err.printStackTrace();
                        setTime.setEnabled(false);
                }
            }
        });
    }

}
```

Just a reminder, the program is far from done, so it is shabby.  If you want to run it create your main method and call buttons.


----------



## Kreij (Apr 19, 2011)

So you are saying that the last button (in the above it would be openNetFolders stretches to the size of the whole window if you don't set it's bounds?


----------



## 3870x2 (Apr 19, 2011)

even if you do set it's bounds, it will fill the rest of the screen.  This happens not matter how many buttons there are.


----------



## Kreij (Apr 19, 2011)

Hmmm ... not sure, and I don't have a machine set up here at work to test Java code on. :/


----------



## Zyon (Apr 20, 2011)

Instead of setBounds() try setLocation(x, y) and setSize(width, height).

Source: http://www.programmersheaven.com/mb/java/138138/138138/swing-jbutton---setbounds/

Also, try NetBeans for Java, it has GUI which makes designing the buttons a lot less hassle.


----------



## 3870x2 (Apr 20, 2011)

who wouldn't use Netbeans? my IDE of choice.

Unless I am programming for Android, in which case I will use eclipse.


----------



## Kreij (Apr 20, 2011)

From today's Dr. Dobb's newsletter (in case you are interested) ...


> *Java 7 and NetBeans 7*
> 
> The Javasphere is settling into two recent announcements by Oracle: The feature list for Java EE 7 has been finalized and version 7.0 of the NetBeans IDE ships this week. (The identical release numbers are purely a coincidence. Despite that, the numbers are meaningful. I'll take this up in a moment.)
> 
> ...


----------



## 3870x2 (Apr 20, 2011)

aww, I tried that thinking it would work, but it still had the same issue.  This is not your fault, it is mine because I am too lazy to create a layout 

What I did do to resolve is make the final button do nothing called fillFrame(), and did the following:

fillFrame = new JButton();
add (fillFrame);
fillFrame.setVisible(false);

This proves that I am a terrible and messy programmer, but it works for me.  To be fair, I will never release anything open source. 

Thank you all for your help, and if you can think of something to write it clean, let me know.


----------



## Kreij (Apr 20, 2011)

I'm going to set up Java development on both my home and work rigs so I can be of some use for the Java programmers.
Will take me a week or two to relearn the syntax as there is a lot new in Java since I last worked with it. (plus I'm working on a little C# project ATM)


----------

