1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Java Structure Help!

Discussion in 'Programming & Webmastering' started by 3870x2, Apr 19, 2011.

  1. 3870x2

    3870x2

    Joined:
    Feb 26, 2008
    Messages:
    4,875 (1.98/day)
    Thanks Received:
    689
    Location:
    Joplin, Mo
    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.

    Code:
    
    //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.
     
  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.87/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    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 says thanks.
  3. 3870x2

    3870x2

    Joined:
    Feb 26, 2008
    Messages:
    4,875 (1.98/day)
    Thanks Received:
    689
    Location:
    Joplin, Mo
    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.
     
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.87/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    Hmmm ... not sure, and I don't have a machine set up here at work to test Java code on. :/
     
  5. Zyon

    Zyon New Member

    Joined:
    Mar 18, 2011
    Messages:
    264 (0.20/day)
    Thanks Received:
    29
    Location:
    Australia
    3870x2 says thanks.
  6. 3870x2

    3870x2

    Joined:
    Feb 26, 2008
    Messages:
    4,875 (1.98/day)
    Thanks Received:
    689
    Location:
    Joplin, Mo
    who wouldn't use Netbeans? my IDE of choice.

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

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.87/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    From today's Dr. Dobb's newsletter (in case you are interested) ...
     
  8. 3870x2

    3870x2

    Joined:
    Feb 26, 2008
    Messages:
    4,875 (1.98/day)
    Thanks Received:
    689
    Location:
    Joplin, Mo
    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 :p

    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. :D

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

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.87/day)
    Thanks Received:
    5,616
    Location:
    Cheeseland (Wisconsin, USA)
    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) :eek:
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page