Link to home
Start Free TrialLog in
Avatar of vassim
vassim

asked on

Java Swing is going everywhere but where its supposed to

I can seem to get my GUI to look the way I want it to, here is a pic of the GUI Im getting
http://www.81x.com/Authors/roadragedave/badgui.jpg

and here is a pic of what I want it to look like
http://www.81x.com/Authors/roadragedave/wanted%20gui.jpg

Here is the code::

***************************************************************
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.*;
import java.beans.*;
import java.awt.BorderLayout;
import java.awt.GridLayout;

//import com.college.attempt.cpp;

//import com.emc.college.ProgramActionListener;

public class ProgramStartup extends JFrame
{
    private Window_actionAdapter my_actionListener = null;

    JPanel jPanel1             = new JPanel();
      JPanel buttonPanel       = new JPanel();
      JPanel checkPanel       = new JPanel();
      JPanel textPanel       = new JPanel();

    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();

    JTextField jTextField1             = new JTextField();
    JTextField jTextField2             = new JTextField();
    JTextField jPasswordField1       = new JPasswordField();

    JLabel jTextPane1 = new JLabel();
    JCheckBox jCheckBox1 = new JCheckBox();
      JCheckBox jCheckBox2 = new JCheckBox();
      JCheckBox jCheckBox3 = new JCheckBox();
      JButton jButton1        = new JButton();
      JButton jButton2        = new JButton();

      public ProgramStartup ()
    {
        my_actionListener = new Window_actionAdapter();
        createGui();
    }

    private void createGui()
    {

        jPanel1.setBounds(new Rectangle());
        this.getContentPane().setLayout(new BorderLayout());
        this.setTitle("Guineyd WMI Application");
        this.setBounds(100, 100, 600, 400);
        this.setResizable(false);

        jLabel1.setText("Machine Name");
        jLabel1.setBounds(new Rectangle(144, 137, 89, 25));

        jLabel2.setText("Username");
        jLabel2.setBounds(new Rectangle(144, 196, 63, 23));
 
        jLabel3.setText("Password");
        jLabel3.setBounds(new Rectangle(425, 196, 66, 23));

        jTextField1.setPreferredSize(new Dimension(80, 21));
        jTextField1.setBounds(new Rectangle(144, 161, 382, 23));

        jTextField2.setPreferredSize(new Dimension(80, 21));
        jTextField2.setBounds(new Rectangle(144, 218, 112, 21));

        jPasswordField1.setPreferredSize(new Dimension(70, 21));
        jPasswordField1.setBounds(new Rectangle(425, 216, 98, 21));

        jTextPane1.setText("Please tick the values you wish to display");
        jTextPane1.setBounds(new Rectangle(44, 160, 238, 24));

        jCheckBox1.setText("Available Memory");
        jCheckBox1.setBounds(new Rectangle(44, 185, 118, 24));

        jCheckBox2.setText("Load Percentage");
        jCheckBox2.setBounds(new Rectangle(44, 210, 118, 24));

      jCheckBox3.setText("Available Disk Space");
      jCheckBox3.setBounds(new Rectangle(44, 235, 118, 24));

      jButton1.setBounds(new Rectangle(94, 277, 128, 30));
      jButton1.setText("Connect");
      jButton1.addActionListener(my_actionListener);
      jButton1.setActionCommand("CONNECT_CLICK");

      jButton2.setBounds(new Rectangle(255, 277, 128, 30));
      jButton2.setText("Cancel");
      jButton2.addActionListener(my_actionListener);
      jButton2.setActionCommand("CANCEL_CLICK");

      buttonPanel.add(jButton1, null);
      buttonPanel.add(jButton2, null);

      checkPanel.setLayout(new BorderLayout());
      checkPanel.setBounds(new Rectangle(100, 300, 250, 120));
      checkPanel.add(jTextPane1, BorderLayout.NORTH);
      checkPanel.add(jCheckBox1, BorderLayout.WEST);
      checkPanel.add(jCheckBox2, BorderLayout.WEST);
      checkPanel.add(jCheckBox3, BorderLayout.WEST);

      textPanel.setBounds(new Rectangle(100, 100, 471, 180));
      textPanel.add(jLabel1,                      null);
      textPanel.add(jTextField1,             null);
      textPanel.add(jLabel2,                      null);
      textPanel.add(jTextField2,             null);
      textPanel.add(jLabel3,                 null);
      textPanel.add(jPasswordField1,       null);

      this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
      this.getContentPane().add(checkPanel,  BorderLayout.CENTER);
      this.getContentPane().add(textPanel,   BorderLayout.NORTH);
    }

    public static void main (String [] args)
    {
        ProgramStartup thisWindow = new ProgramStartup();
        thisWindow.setVisible(true);

        thisWindow.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
    }

    // ----------------- ACTION LISTENER --------------------

    class Window_actionAdapter implements ActionListener
    {
        Window_actionAdapter()
        {
        }

        public void actionPerformed(ActionEvent e)
        {
            if(e.getActionCommand().equals("CANCEL_CLICK"))
            {
                // do the button stuff
                System.out.println("David says go home");
                System.exit(0);
            }
            else if(e.getActionCommand().equals("CONNECT_CLICK"))
            {
      JNIConnect jniConn = new JNIConnect();
      System.out.println("David is Cool");
      Login();

            }
        }
    }

    //------------------ CLASS OF VARIABLES -----------------

   class MachineDetails {
      String BSTRMachineName;
      String UserName;
      String PassWd;
      boolean AvailMemory;
      boolean LoadPercentage;
      boolean DiskSpaceFree;

   public MachineDetails(){
      String BSTRMachineName = null;
      String UserName = null;
      String PassWd   = null;
      boolean AvailMemory = false;
      boolean LoadPercentage = false;
      boolean DiskSpaceFree = false;
      }
   }

   public void Login(){
      MachineDetails dClass = new MachineDetails();
      //JNIConnect jniConn = new JNIConnect();

      dClass.BSTRMachineName = jTextField1.getText();
      dClass.UserName          = jTextField2.getText();
      dClass.PassWd                = jPasswordField1.getText();

      dClass.AvailMemory     = jCheckBox1.isSelected();
      dClass.LoadPercentage  = jCheckBox2.isSelected();
      dClass.DiskSpaceFree   = jCheckBox3.isSelected();

      driver(dClass);
    }

    public class JNIConnect{
      public JNIConnect()
      {
      try{
                                System.loadLibrary("guineyd");
      }
            catch(java.lang.UnsatisfiedLinkError e){
            System.out.println(e);
      }
      }

      }
       public native void driver(MachineDetails dClass) throws UnsatisfiedLinkError;;
}

*******************************************************************

Im looking at the co-ordinates for each of the checkBoxes and I can understand why its ending up that way

ASKER CERTIFIED SOLUTION
Avatar of keteracel
keteracel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vassim
vassim

ASKER

All I have to say is...............


I think I love you!!!!!!