Kura_kai
08-21-2006, 03:22 PM
Ok since no one answered me in my other thread i decided to scrap my whole code and start over. But I am having a problem with getting my new code out of a loop issue...
The first class does a basic window with a menu up at the top.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.WindowConstants;
import java.util.regex.Pattern;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Client extends javax.swing.JFrame {
private JMenuBar menu;
private JMenu jMenu1;
private JMenuItem jMenuItem1;
private JMenuItem jMenuItem10;
private JMenuItem jMenuItem9;
private JMenuItem jMenuItem8;
private JMenuItem jMenuItem7;
private JMenuItem jMenuItem6;
private JMenu jMenu3;
private JMenuItem jMenuItem5;
private JMenu jMenu2;
private JMenuItem jMenuItem4;
private JSeparator jSeparator1;
private JMenuItem jMenuItem3;
private JMenuItem jMenuItem2;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
Client inst = new Client();
inst.setVisible(true);
}
public Client() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Client");
{
menu = new JMenuBar();
setJMenuBar(menu);
menu.setPreferredSize(new java.awt.Dimension(392, 17));
menu.setSize(392, 20);
{
jMenu1 = new JMenu();
menu.add(jMenu1);
jMenu1.setText("File");
{
jMenuItem1 = new JMenuItem();
jMenu1.add(jMenuItem1);
jMenuItem1.setText("Connect");
jMenuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Login inst = new Login();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
});
}
{
jMenuItem2 = new JMenuItem();
jMenu1.add(jMenuItem2);
jMenuItem2.setText("Disconnect");
}
{
jMenuItem3 = new JMenuItem();
jMenu1.add(jMenuItem3);
jMenuItem3.setText("Register");
jMenuItem3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Register inst = new Register();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
});
}
{
jSeparator1 = new JSeparator();
jMenu1.add(jSeparator1);
}
{
jMenuItem4 = new JMenuItem();
jMenu1.add(jMenuItem4);
jMenuItem4.setText("Exit");
jMenuItem4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
}
}
{
jMenu2 = new JMenu();
menu.add(jMenu2);
jMenu2.setText("Options");
{
jMenuItem5 = new JMenuItem();
jMenu2.add(jMenuItem5);
jMenuItem5.setText("Preferences");
}
{
jMenu3 = new JMenu();
jMenu2.add(jMenu3);
jMenu3.setText("Away Mode");
{
jMenuItem6 = new JMenuItem();
jMenu3.add(jMenuItem6);
jMenuItem6.setText("Busy");
}
{
jMenuItem7 = new JMenuItem();
jMenu3.add(jMenuItem7);
jMenuItem7.setText("Bathroom Break");
}
{
jMenuItem8 = new JMenuItem();
jMenu3.add(jMenuItem8);
jMenuItem8.setText("Be Right Back");
}
{
jMenuItem9 = new JMenuItem();
jMenu3.add(jMenuItem9);
jMenuItem9.setText("Do Not Disturb");
}
{
jMenuItem10 = new JMenuItem();
jMenu3.add(jMenuItem10);
jMenuItem10.setText("Phone Call");
}
}
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
When you click connect it uses the Login class and when you click Register it uses the register class. There both the same pretty much except the different titles of the window. Here is the Login code.
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
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.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import java.util.regex.Pattern;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Login extends javax.swing.JFrame {
private JTextField jTextField1;
private JLabel jLabel1;
private JLabel jLabel2;
private JButton jButton1;
private JPasswordField jPasswordField1;
private boolean done = false;
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) {
Login inst = new Login();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
public Login() {
super();
initGUI();
}
private void initGUI() {
try {
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7};
thisLayout.columnWeights = new double[] {0.0, 0.1};
thisLayout.columnWidths = new int[] {55, 7};
getContentPane().setLayout(thisLayout);
this.setMaximumSize(new java.awt.Dimension(150, 70));
this.setTitle("Login");
this.setDefaultLookAndFeelDecorated(true);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
done = true;
}
});
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jLabel1.setText("Username:");
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jLabel2.setText("Password:");
}
{
jPasswordField1 = new JPasswordField();
getContentPane().add(jPasswordField1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
{
jButton1 = new JButton();
getContentPane().add(
jButton1,
new GridBagConstraints(
0,
2,
2,
1,
0.0,
0.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0,
0));
jButton1.setText("Ok");
jButton1.setSize(40, 20);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
done = true;
}
});
}
this.setSize(150, 105);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getUserName() {
return jTextField1.getText();
}
public String getPassword() {
return new String(jPasswordField1.getPassword());
}
public boolean isDone() {
return done;
}
}
The issue i am having is that it never draws the Login window by using the client since it is getting stuck in a loop. When I run it by itself it works... Is there a way to fix this or something?
The first class does a basic window with a menu up at the top.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.WindowConstants;
import java.util.regex.Pattern;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Client extends javax.swing.JFrame {
private JMenuBar menu;
private JMenu jMenu1;
private JMenuItem jMenuItem1;
private JMenuItem jMenuItem10;
private JMenuItem jMenuItem9;
private JMenuItem jMenuItem8;
private JMenuItem jMenuItem7;
private JMenuItem jMenuItem6;
private JMenu jMenu3;
private JMenuItem jMenuItem5;
private JMenu jMenu2;
private JMenuItem jMenuItem4;
private JSeparator jSeparator1;
private JMenuItem jMenuItem3;
private JMenuItem jMenuItem2;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
Client inst = new Client();
inst.setVisible(true);
}
public Client() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Client");
{
menu = new JMenuBar();
setJMenuBar(menu);
menu.setPreferredSize(new java.awt.Dimension(392, 17));
menu.setSize(392, 20);
{
jMenu1 = new JMenu();
menu.add(jMenu1);
jMenu1.setText("File");
{
jMenuItem1 = new JMenuItem();
jMenu1.add(jMenuItem1);
jMenuItem1.setText("Connect");
jMenuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Login inst = new Login();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
});
}
{
jMenuItem2 = new JMenuItem();
jMenu1.add(jMenuItem2);
jMenuItem2.setText("Disconnect");
}
{
jMenuItem3 = new JMenuItem();
jMenu1.add(jMenuItem3);
jMenuItem3.setText("Register");
jMenuItem3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Register inst = new Register();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
});
}
{
jSeparator1 = new JSeparator();
jMenu1.add(jSeparator1);
}
{
jMenuItem4 = new JMenuItem();
jMenu1.add(jMenuItem4);
jMenuItem4.setText("Exit");
jMenuItem4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
}
}
{
jMenu2 = new JMenu();
menu.add(jMenu2);
jMenu2.setText("Options");
{
jMenuItem5 = new JMenuItem();
jMenu2.add(jMenuItem5);
jMenuItem5.setText("Preferences");
}
{
jMenu3 = new JMenu();
jMenu2.add(jMenu3);
jMenu3.setText("Away Mode");
{
jMenuItem6 = new JMenuItem();
jMenu3.add(jMenuItem6);
jMenuItem6.setText("Busy");
}
{
jMenuItem7 = new JMenuItem();
jMenu3.add(jMenuItem7);
jMenuItem7.setText("Bathroom Break");
}
{
jMenuItem8 = new JMenuItem();
jMenu3.add(jMenuItem8);
jMenuItem8.setText("Be Right Back");
}
{
jMenuItem9 = new JMenuItem();
jMenu3.add(jMenuItem9);
jMenuItem9.setText("Do Not Disturb");
}
{
jMenuItem10 = new JMenuItem();
jMenu3.add(jMenuItem10);
jMenuItem10.setText("Phone Call");
}
}
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
When you click connect it uses the Login class and when you click Register it uses the register class. There both the same pretty much except the different titles of the window. Here is the Login code.
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
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.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import java.util.regex.Pattern;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Login extends javax.swing.JFrame {
private JTextField jTextField1;
private JLabel jLabel1;
private JLabel jLabel2;
private JButton jButton1;
private JPasswordField jPasswordField1;
private boolean done = false;
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) {
Login inst = new Login();
inst.setVisible(true);
while(!inst.isDone()) {
}
if(inst.getUserName().equals("")) {
System.out.println("Error: Invalid UserName");
inst.dispose();
}
else if((Pattern.matches("\\w",inst.getUserName())) && (Pattern.matches("\\w",inst.getPassword()))) {
System.out.println("UserName:" + inst.getUserName() + " Password:"+inst.getPassword());
inst.dispose();
}
else {
System.out.println("Error:Invalid UserName or Password");
inst.dispose();
}
}
public Login() {
super();
initGUI();
}
private void initGUI() {
try {
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7};
thisLayout.columnWeights = new double[] {0.0, 0.1};
thisLayout.columnWidths = new int[] {55, 7};
getContentPane().setLayout(thisLayout);
this.setMaximumSize(new java.awt.Dimension(150, 70));
this.setTitle("Login");
this.setDefaultLookAndFeelDecorated(true);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
done = true;
}
});
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jLabel1.setText("Username:");
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jLabel2.setText("Password:");
}
{
jPasswordField1 = new JPasswordField();
getContentPane().add(jPasswordField1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
{
jButton1 = new JButton();
getContentPane().add(
jButton1,
new GridBagConstraints(
0,
2,
2,
1,
0.0,
0.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0,
0));
jButton1.setText("Ok");
jButton1.setSize(40, 20);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
done = true;
}
});
}
this.setSize(150, 105);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getUserName() {
return jTextField1.getText();
}
public String getPassword() {
return new String(jPasswordField1.getPassword());
}
public boolean isDone() {
return done;
}
}
The issue i am having is that it never draws the Login window by using the client since it is getting stuck in a loop. When I run it by itself it works... Is there a way to fix this or something?