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.ActionListe ner;
import java.awt.event.WindowAdapt er;
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.ProgramAct ionListene r;
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().setL ayout(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.setPreferredSi ze(new Dimension(80, 21));
jTextField1.setBounds(new Rectangle(144, 161, 382, 23));
jTextField2.setPreferredSi ze(new Dimension(80, 21));
jTextField2.setBounds(new Rectangle(144, 218, 112, 21));
jPasswordField1.setPreferr edSize(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("Availa ble Memory");
jCheckBox1.setBounds(new Rectangle(44, 185, 118, 24));
jCheckBox2.setText("Load Percentage");
jCheckBox2.setBounds(new Rectangle(44, 210, 118, 24));
jCheckBox3.setText("Availa ble Disk Space");
jCheckBox3.setBounds(new Rectangle(44, 235, 118, 24));
jButton1.setBounds(new Rectangle(94, 277, 128, 30));
jButton1.setText("Connect" );
jButton1.addActionListener (my_action Listener);
jButton1.setActionCommand( "CONNECT_C LICK");
jButton2.setBounds(new Rectangle(255, 277, 128, 30));
jButton2.setText("Cancel") ;
jButton2.addActionListener (my_action Listener);
jButton2.setActionCommand( "CANCEL_CL ICK");
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(jPasswordFie ld1, null);
this.getContentPane().add( buttonPane l, 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.addWindowListen er(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
// ----------------- ACTION LISTENER --------------------
class Window_actionAdapter implements ActionListener
{
Window_actionAdapter()
{
}
public void actionPerformed(ActionEven t e)
{
if(e.getActionCommand().eq uals("CANC EL_CLICK") )
{
// do the button stuff
System.out.println("David says go home");
System.exit(0);
}
else if(e.getActionCommand().eq uals("CONN ECT_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("guiney d");
}
catch(java.lang.Unsatisfie dLinkError 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
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.ActionListe
import java.awt.event.WindowAdapt
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.ProgramAct
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().setL
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.setPreferredSi
jTextField1.setBounds(new Rectangle(144, 161, 382, 23));
jTextField2.setPreferredSi
jTextField2.setBounds(new Rectangle(144, 218, 112, 21));
jPasswordField1.setPreferr
jPasswordField1.setBounds(
jTextPane1.setText("Please
jTextPane1.setBounds(new Rectangle(44, 160, 238, 24));
jCheckBox1.setText("Availa
jCheckBox1.setBounds(new Rectangle(44, 185, 118, 24));
jCheckBox2.setText("Load Percentage");
jCheckBox2.setBounds(new Rectangle(44, 210, 118, 24));
jCheckBox3.setText("Availa
jCheckBox3.setBounds(new Rectangle(44, 235, 118, 24));
jButton1.setBounds(new Rectangle(94, 277, 128, 30));
jButton1.setText("Connect"
jButton1.addActionListener
jButton1.setActionCommand(
jButton2.setBounds(new Rectangle(255, 277, 128, 30));
jButton2.setText("Cancel")
jButton2.addActionListener
jButton2.setActionCommand(
buttonPanel.add(jButton1, null);
buttonPanel.add(jButton2, null);
checkPanel.setLayout(new BorderLayout());
checkPanel.setBounds(new Rectangle(100, 300, 250, 120));
checkPanel.add(jTextPane1,
checkPanel.add(jCheckBox1,
checkPanel.add(jCheckBox2,
checkPanel.add(jCheckBox3,
textPanel.setBounds(new Rectangle(100, 100, 471, 180));
textPanel.add(jLabel1, null);
textPanel.add(jTextField1,
textPanel.add(jLabel2, null);
textPanel.add(jTextField2,
textPanel.add(jLabel3, null);
textPanel.add(jPasswordFie
this.getContentPane().add(
this.getContentPane().add(
this.getContentPane().add(
}
public static void main (String [] args)
{
ProgramStartup thisWindow = new ProgramStartup();
thisWindow.setVisible(true
thisWindow.addWindowListen
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
// ----------------- ACTION LISTENER --------------------
class Window_actionAdapter implements ActionListener
{
Window_actionAdapter()
{
}
public void actionPerformed(ActionEven
{
if(e.getActionCommand().eq
{
// do the button stuff
System.out.println("David says go home");
System.exit(0);
}
else if(e.getActionCommand().eq
{
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("guiney
}
catch(java.lang.Unsatisfie
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think I love you!!!!!!