How to halt a method while a GUI completes it's task...

Does anyone know how to stall a calling method which is calling a GUI, until the GUI is done w/ it's task?
[114 byte] By [ponchoa] at [2007-11-27 9:11:51]
# 1
Quit multi-posting. You already got an answer when you posted this question in the Swing forum.
camickra at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 2
I was hoping to not have to completely revamp my project! Is DoModal the only way? Do you know of a way to use DoModal w/ JFrame? Everything I see online is using JDialogs...
ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 3

> Everything I see online is using JDialogs...

Because thats the proper way of designing an application. An application is meant to operate independently of other applications, which is why a button is added to the task bar, so you can select which application you want to work on. If the application needs additional information a dialog is displayed. It can be modal if the application needs to wait for the information to be entered, or non-modal if the dialog can stay open while using the rest of the application. When you close an application all dialogs related to the application are also closed.

camickra at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 4

It's easy enough to make the thread of the calling method wait for an ordinary frame to close (using wait, notify and a flag which indicates the completion).

You can write a couple of methods into the frame like:

[code]

private boolean completed = false;

private void finish() {

synchronized(this) {

completed = true;

notifyAll();

}

setVisible(false);

}

public sychronized synchronized waitForCompletion() throws InterruptedException {

while(!completed)

wait();

}

malcolmmca at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 5
Cool, I'll try that now... Thanks, Joe
ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 6
Would that actually go in the calling class or in the GUI class?
ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 7

I see what you mean, but for some reason my while(! completed loop) is never entered. Any idea why, this is my code...

import java.lang.Integer;

import java.lang.String;

import java.io.*;

import java.util.*;

import javax.swing.JOptionPane;

import java.lang.Object;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

import java.lang.String.*;

import java.util.*;

//import java.util.*;

import java.awt.Container;

import javax.swing.JOptionPane;

public class test

{

public static boolean completed = false;

public static String[][] tempElements1= new String[25000][20];

public static String[] tempElements2= new String[20];

public static String[] tempElements3= new String[20];

public static String[] tempElements4= new String[20];

public static String[] tempElements5= new String[20];

public static String[] tempElements6= new String[20];

public static String[] tempElements7= new String[20];

public static String[] tempElements8= new String[20];

public static String[] tempElements9= new String[20];

public static String[] tempElements10= new String[20];

public static String[] tempElements11= new String[20];

public static String[] tempElements12= new String[20];

/*

public static void readFile2(String lnames[], String fnames[], String mnames[],

String facs[], String sdates[], String scores[],

String scrambles[], String filename)

*/

public static synchronized void readFile2(String lnames[], String fnames[], String mnames[],

String facs[], String sdates[], String scores[],

String scrambles[], String filename) throws InterruptedException

{

test t = new test();;

String tempTitle = "JR";

System.out.println("Inside ReadFile");

try

{

System.out.println("Inside Try");

BufferedReader in = new BufferedReader(new FileReader( filename ));

//"C:/Documents and Settings/Joe/JavaApplication1/src/test.txt"));

String tempElement = "";

//String tempElements[15];

String tempElement1 = "";

String tempElement2 = "";

String tempElement3 = "";

String tempElement4 = "";

String tempElement5 = "";

String tempElement6 = "";

String tempElement7 = "";

String tempElement8 = "";

String tempElement9 = "";

String tempElement10 = "";

String tempElement11 = "";

String tempElement12 = "";

StringTokenizer data;

String S;

int numberOfTokens = 0;

int numberOfWords = 0;

int numberOfLines = 0;

S = in.readLine();

data = new StringTokenizer(S);

numberOfTokens = data.countTokens();

//System.out.println("Next Token " + data.nextToken());

//System.out.println(data);

//array[row][col]

System.out.println("Ready to Tokenize");

int i = 0;

int q = 0;

int lineCount = 0;

while( ( ! S.equals("") ) && (data.hasMoreTokens() )

&& (S.trim().length() != 0))//in.readLine()

{

int col = 0;

int j = 0;

//while( i < SenListHelpers.getArrayLength(tempElements2) )

while( data.hasMoreTokens() )

{

tempElements1[i][j] = data.nextToken();//get LName

System.out.println(" Getting tempElements1[ " + i + " ]" + "[ " + j + " ]" + tempElements1[i][j]);

//System.out.println("tempElements [" + i + "] "+ tempElements1[i][j]);

j ++;

}

i ++;

System.out.println(" i = " + i );

int p = 0;

System.out.println("tempElements [" + q + "] "+ tempElements1[q][p]

+ " " + tempElements1[q][p+1]

+ " " + tempElements1[q][p+2]

+ " " + tempElements1[q][p+3]

+ " " + tempElements1[q][p+4]

+ " " + tempElements1[q][p+5]

+ " " + tempElements1[q][p+6]);

q ++;

//#2

/*

( compareStringByCase(tempElements1[lineCount][0], "DE") ) ||

( compareStringByCase(tempElements1[lineCount][0], "LE") ) ||

( compareStringByCase(tempElements1[lineCount][0], "LA") ) ||

( compareStringByCase(tempElements1[lineCount][0], "MC") ) ||

( compareStringByCase(tempElements1[lineCount][0], "ST") ) ||

( compareStringByCase(tempElements1[lineCount][0], "ST.") ) ||

( compareStringByCase(tempElements1[lineCount][0], "VAN") ) ||

( compareStringByCase(tempElements1[lineCount][0], "EL") )

*/

if( ( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "ABBO") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "DE") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "LE") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "LA") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "MC") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "ST") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "ST.") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "VAN") ) ||

( SenListHelpers.compareStringByCase(tempElements1[lineCount][0], "EL") ) )

{

System.out.println("");

correctOfficerGUI test = new correctOfficerGUI(tempElements1, lineCount);

test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

System.out.println("Just Inside if DE");

//try

//{

//**********************************************************************

while(! completed )

{

System.out.println("About to HOLD");

t.wait();

System.out.println("Done HOLDING");

}

System.out.println("Just After While");

//**********************************************************************

//}

//catch (InterruptedException e) {}

return;// from this method;

}

else if((( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ) )||

(( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][6]) ) )||

(( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][7]) ) ) )

{

System.out.println("1 5 1 6 1 7");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0] + " " +

tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] = tempElements1[lineCount][3];

SenListHelpers.setArray(tempElements1, lineCount);

}

//#3

//#4

else if((( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][4]) ) )||

(( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ) )||

(( SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][6]) ) ) )

{

System.out.println("1 4 1 5 1 6");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0] + " " +

tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] = "_";//tempElements1[lineCount][3];

SenListHelpers.setArray(tempElements1, lineCount);

}

//#5

//#6

else if((( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ) )||

(( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][6]) )) ||

(( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][7]) ) ) )

{

System.out.println("2 5 2 6 2 7");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0];// + " " +

//tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][1] + " " +

tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] = tempElements1[lineCount][3];

SenListHelpers.setArray(tempElements1, lineCount);

}

//#7

//#8

else if((( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][4]) ))||

(( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ))||

(( SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][6]) ) ) )

{

System.out.println("2 4 2 5 2 6");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0];// + " " +

//tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][1] + " " +

tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] = "_";

SenListHelpers.setArray(tempElements1, lineCount);

}

//#9

//#10

else if(((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][4]) ))||

((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ) )||

((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][6]) ) ) )

{

System.out.println("1 2 4 1 2 5 1 2 6");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0];// + " " +

//tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][1];// + " " +

//tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] = tempElements1[lineCount][2];

SenListHelpers.setArray(tempElements1, lineCount);

}

//#11

//#12

else if(((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isSingleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][3]) ))||

((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isDoubleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][4]) ) )||

((!SenListHelpers.isTitle (tempElements1[lineCount][1]) ) &&

(!SenListHelpers.isTitle (tempElements1[lineCount][2]) ) &&

( SenListHelpers.isTripleFacility2(tempElements1, lineCount) ) &&

( SenListHelpers.isSenDate(tempElements1[lineCount][5]) ) ) )

{

System.out.println("1 2 3 1 2 4 1 2 5");

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] = tempElements1[lineCount][0];// + " " +

//tempElements1[lineCount][1];

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] = tempElements1[lineCount][1];// + " " +

//tempElements1[lineCount][2];

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials [lineCount] = "_";

SenListHelpers.setArray(tempElements1, lineCount);

}

else if( SenListHelpers.isPageBreakInfo(tempElements1[lineCount][col]) )

{

System.out.println("in isPageBreakInfo(tempElement)" + tempElements1[lineCount][0]);

if( tempElements1[lineCount][0].equals("SENIORITY") )

{

System.out.println("Inside SENIORITY ");

System.out.println(SenListArraySetUp.SENIORITY + " " + SenListArraySetUp.LIST + " " +

SenListArraySetUp.BY+ " " + SenListArraySetUp.ALPHA);

SenListArraySetUp.SENIORITY = tempElements1[lineCount][0];

SenListArraySetUp.LIST= tempElements1[lineCount][1];

SenListArraySetUp.BY= tempElements1[lineCount][2];

SenListArraySetUp.ALPHA= tempElements1[lineCount][3];

}

else if( tempElements1[lineCount][0].equals("Last") )

{

SenListArraySetUp.Last = tempElements1[lineCount][0];

SenListArraySetUp.LName= tempElements1[lineCount][1];

SenListArraySetUp.First= tempElements1[lineCount][2];

SenListArraySetUp.FName= tempElements1[lineCount][3];

SenListArraySetUp.Initial= tempElements1[lineCount][3];

SenListArraySetUp.Facility= tempElements1[lineCount][4];

SenListArraySetUp.Seniority= tempElements1[lineCount][5];

SenListArraySetUp.Date = tempElements1[lineCount][6];

SenListArraySetUp.Test = tempElements1[lineCount][7];

SenListArraySetUp.Score= tempElements1[lineCount][8];

SenListArraySetUp.Scramble= tempElements1[lineCount][9];

}

else if( tempElements1[lineCount][0].substring(tempElements1[lineCount][0].length() - 4,

tempElements1[lineCount][0].length()).equals("day,") )

//(tempElement.substring(0, 2).equals("day") )

{

System.out.println("It's a DAY of the week!!!");

SenListArraySetUp.page_break_day = tempElements1[lineCount][0];

SenListArraySetUp.page_break_month= tempElements1[lineCount][1];

SenListArraySetUp.page_break_date = tempElements1[lineCount][2];

SenListArraySetUp.page_break_year = tempElements1[lineCount][3];

SenListArraySetUp.page_break_page = tempElements1[lineCount][4];

SenListArraySetUp.page_break_page_number = tempElements1[lineCount][5];

SenListArraySetUp.page_break_of= tempElements1[lineCount][6];

SenListArraySetUp.page_break_num_pages= tempElements1[lineCount][7];

}

}

else

{

System.out.println("ELSE");

correctOfficerGUI test = new correctOfficerGUI(tempElements1, lineCount);

test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

System.out.println("After Everything");

//System.out.println("Substring " + tempElements1[lineCount][0].substring(tempElements1[lineCount][0].length() - 4));

/*

int count = 0;

while( count < SenListHelpers.getArrayColLength(tempElements1, lineCount) )

{

if( SenListHelpers.isSingleFacility(tempElements1[lineCount][count] ) )

{

SenListArraySetUp.NYSDOCS_Alpha_List_Facilities[lineCount] = tempElements1[lineCount][count];

break;

}

else if( SenListHelpers.isDoubleFacility(tempElements1[lineCount][count] ) )

{

SenListArraySetUp.NYSDOCS_Alpha_List_Facilities[lineCount] = tempElements1[lineCount][count] + " " +

tempElements1[lineCount][count + 1];

break;

}

else if( SenListHelpers.isTripleFacility(tempElements1[lineCount][count] ) )

{

SenListArraySetUp.NYSDOCS_Alpha_List_Facilities[lineCount] = tempElements1[lineCount][count]+ " " +

tempElements1[lineCount][count + 1] + " " +

tempElements1[lineCount][count + 2];

break;

}

count ++;

}

*/

System.out.println("getArrayColLength(tempElements1)");

System.out.println(SenListHelpers.getArrayColLength(tempElements1, lineCount) );

System.out.println("getArrayColLength(tempElements1, lineCount ) -3");

System.out.println(SenListHelpers.getArrayColLength(tempElements1, lineCount) - 3 );

/*

SenListArraySetUp.NYSDOCS_Alpha_List_Facilities [lineCount] = SenListHelpers.getFacility (tempElements1, lineCount);

System.out.println("X");

SenListArraySetUp.NYSDOCS_Alpha_List_SenDates[lineCount] = tempElements1[lineCount][ SenListHelpers.getSenDateIndex(tempElements1, lineCount) ];

System.out.println("XX");

SenListArraySetUp.NYSDOCS_Alpha_List_Scores[lineCount] = tempElements1[lineCount][ SenListHelpers.getArrayColLength(tempElements1, lineCount) - 2 ];

System.out.println("XXX");

SenListArraySetUp.NYSDOCS_Alpha_List_Scrambles [lineCount] = Integer.toString(

SenListHelpers.getScramble(

tempElements1[lineCount][0]));

*/

System.out.println("***********************************************************");

System.out.println("Officer: " +

SenListArraySetUp.NYSDOCS_Alpha_List_LastNames[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_FirstNames[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_MiddleInitials[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_Facilities[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_SenDates[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_Scores[lineCount] + " " +

SenListArraySetUp.NYSDOCS_Alpha_List_Scrambles[lineCount]);

System.out.println("***********************************************************");

System.out.println("Trying to Print");

System.out.println("SenDateIndex " + SenListHelpers.getSenDateIndex(tempElements1, lineCount));

System.out.println("Done Trying to Print");

System.out.println("Facility Index " + SenListHelpers.getFacilityIndex(tempElements1, lineCount));

System.out.println("Facility" + SenListHelpers.getFacility(tempElements1, lineCount));

System.out.println("lineCount" + lineCount);

lineCount ++;

col ++;

tempElement = "";

S = in.readLine();

data = new StringTokenizer(S);

}//end while

}// end try

catch (Exception e)

{

}

}

public void hold() throws InterruptedException

{

//System.out.println("About to wait");

try

{

System.out.println("About to wait");

wait();

System.out.println("Done waiting");

}

catch (InterruptedException e) {}

//wait();

}

/*

private boolean completed = false;

public void finish()

{

synchronized(this)

{

completed = true;

notifyAll();

}

setVisible(false);

}

public synchronized void waitForCompletion() throws InterruptedException

{

while(!completed)

{

wait();

}

}

*/

}//end class test

//*************************************************************************

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

import java.awt.Container;

import javax.swing.JOptionPane;

import java.lang.Object;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

import java.awt.Container;

import javax.swing.JOptionPane;

import java.awt.BorderLayout;

//import java.awt.Container;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionListener;

import javax.swing.event.ListSelectionEvent;

import javax.swing.event.ListSelectionListener;

//import javax.media.jai.JAI;

//import javax.media.jai.PlanarImage;

import javax.swing.BorderFactory;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.SpringLayout;

import javax.swing.border.BevelBorder;

/**

* Simple applications for demonstrating the use of FormUtility

* to hide the details of creating a form layout with

* GridBagLayout.

* <P>

* Philip Isenhour - 060628 - http://javatechniques.com/

*/

public class correctOfficerGUI extends JFrame

{

private final JTextField nameInfo, lname, fname, mname, sdate, score, scramble;

private JPanel form;

private final JFrame f;

//EASTERN NY

public static String nameInfoString= new String();

String facilities[] = {

"ADIRONDACK","ALBION","ALTONA", "ARTHUR KILL", "ATTICA",

"AUBURN CORR", "BARE HILL", "BAYVIEW","BEACON", "BEDFRD HILL",

"BUFFALO","BUTLER","BUTLER ASAT", "GABRIELS","GEORGETOWN",

"PHARSALIA","CAPE VINCEN", "CAYUGA", "CHATEAUGAY", "CLINTON COR",

"COLLINS","COXSACKIE", "DOWNSTATE", "EASTERN NY", "EDGECOMBE",

"ELMIRA CNTR", "FISHKILL", "FIVE POINTS", "FRANKLIN", "FULTON FAC",

"GOUVERNEUR","GOWANDA", "GREAT MEADW", "GREEN HAVEN", "GREENE",

"GROVELAND","HALE CREEK", "HUDSON", "LAKEVIEW", "LAKEVIEW ASA",

"LINCOLN FAC","LIVINGSTON", "LYON MTN", "MARCY", "MID-ORANGE",

"MID STATE","MOHAWK","MONTEREY", "MORIAH SICF", "MT MCGREGOR",

"NYC CTL ADM", "OGDENSBURG", "ONEIDA", "ORLEANS", "OTISVILLE",

"QUEENSBORO","RIVERVIEW", "ROCHESTER", "SHAWANGUNK", "SING SING",

"SOUTHPORT","SULLIVAN","SUMMIT","TACONIC C F", "ULSTER",

"UPSTATE","WALLKILL", "WASHINGTON", "WATERTOWN", "WENDE",

"WILLARD","WOODBOURNE", "WYOMING"};

public correctOfficerGUI(String[][] array, int lineCount)

{

//JFrame

f = new JFrame("Add Officer");

//int x = f.DoModal();

// Make a panel to hold the demo 揻orm", then

// add it to the top of the frame抯 content pane

//JPanel

form = new JPanel();

f.getContentPane().setLayout(new BorderLayout());

f.getContentPane().add(form, BorderLayout.NORTH);

// Set the form panel抯 layout to GridBagLayout

// and create a FormUtility to add things to it.

form.setLayout(new GridBagLayout());

FormUtility formUtility = new FormUtility();

// Add some sample fields

System.out.println(array[lineCount][0] + " " + array[lineCount][1] + " " +

array[lineCount][2] + " " + array[lineCount][3] + " " +

array[lineCount][4] + " " + array[lineCount][5] + " " +

array[lineCount][6] + " " + array[lineCount][7] );

formUtility.addLabel("Name Info: ", form);

//JTextField

nameInfo = new JTextField();

Dimension nameInfoSize = nameInfo.getPreferredSize();

nameInfoSize.width = 180;

nameInfo.setPreferredSize(nameInfoSize);

JPanel nameInfoPanel = new JPanel();

nameInfoPanel.setLayout(new BorderLayout());

nameInfoPanel.add(nameInfo, BorderLayout.WEST);

formUtility.addLastField(nameInfoPanel, form);

nameInfo.setText(getNameInfo(array, lineCount));

formUtility.addLabel("Last Name: ", form);

//JTextField

lname = new JTextField();

Dimension lnameSize = lname.getPreferredSize();

lnameSize.width = 150;

lname.setPreferredSize(lnameSize);

JPanel lnamePanel = new JPanel();

lnamePanel.setLayout(new BorderLayout());

lnamePanel.add(lname, BorderLayout.WEST);

formUtility.addLastField(lnamePanel, form);

//lname.setText("xxx");

formUtility.addLabel("First Name: ", form);

//JTextField

fname = new JTextField();

Dimension fnameSize = lname.getPreferredSize();

fnameSize.width = 150;

fname.setPreferredSize(fnameSize);

JPanel fnamePanel = new JPanel();

fnamePanel.setLayout(new BorderLayout());

fnamePanel.add(fname, BorderLayout.WEST);

formUtility.addLastField(fnamePanel, form);

formUtility.addLabel("Middle Initial: ", form);

//JTextField

mname = new JTextField();

Dimension mnameSize = mname.getPreferredSize();

mnameSize.width = 20;

mname.setPreferredSize(mnameSize);

JPanel mnamePanel = new JPanel();

mnamePanel.setLayout(new BorderLayout());

mnamePanel.add(mname, BorderLayout.WEST);

formUtility.addLastField(mnamePanel, form);

formUtility.addLabel("Facility: ", form);

//JTextField spacer = new JTextField();

//Dimension spacerSize = spacer.getPreferredSize();

//spacerSize.width = 20;

//spacer.setPreferredSize(spacerSize);

JPanel spacerPanel = new JPanel();

spacerPanel.setLayout(new BorderLayout());

//spacerPanel.add(spacer, BorderLayout.WEST);

formUtility.addLastField(spacerPanel, form);

//Container contentpane;

//contentpane = getContentPane();

//contentpane.setLayout(new FlowLayout());

final JList list = new JList(SenListArraySetUp.facilities);

/* getFacilityIndex( SenListHelpers.getFacility(array, lineCount), facilities ) */

System.out.println("getFacility" + SenListHelpers.getFacility(array, lineCount) );

System.out.println("*******");

//System.out.println("getFacility" + getFacilityIndex( SenListHelpers.getFacility(array, lineCount), SenListArraySetUp.facilities ) );

//getFacilityIndex( SenListHelpers.getFacility(array, lineCount), facilities );

System.out.println(" ");

int index = getFacilityIndex( SenListHelpers.getFacility(array, lineCount), SenListArraySetUp.facilities );

System.out.println("Index" + index);

list.setSelectedIndex(0);

list.setVisibleRowCount(1);

list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

//contentpane

spacerPanel.add(new JScrollPane(list));

formUtility.addLabel("Seniority Date: ", form);

//JTextField

sdate = new JTextField();

Dimension sdateSize = sdate.getPreferredSize();

sdateSize.width = 70;

sdate.setPreferredSize(sdateSize);

JPanel sdatePanel = new JPanel();

sdatePanel.setLayout(new BorderLayout());

sdatePanel.add(sdate, BorderLayout.WEST);

formUtility.addLastField(sdatePanel, form);

sdate.setText(array[lineCount][SenListHelpers.getSenDateIndex(array, lineCount)]);

/*

formUtility.addLabel("Score: ", form);

JTextField score = new JTextField();

Dimension scoreSize = score.getPreferredSize();

scoreSize.width = 20;

score.setPreferredSize(scoreSize);

JPanel scorePanel = new JPanel();

scorePanel.setLayout(new BorderLayout());

scorePanel.add(score, BorderLayout.WEST);

formUtility.addLastField(scorePanel, form);

*/

formUtility.addLabel("Score: ", form);

//JTextField

score = new JTextField();

Dimension scoreSize = score.getPreferredSize();

scoreSize.width = 30;

score.setPreferredSize(scoreSize);

JPanel scorePanel = new JPanel();

scorePanel.setLayout(new BorderLayout());

scorePanel.add(score, BorderLayout.WEST);

formUtility.addLastField(scorePanel, form);

score.setText(array[lineCount][SenListHelpers.getArrayColLength(array, lineCount)]);

formUtility.addLabel("Scramble: ", form);

//JTextField

scramble = new JTextField();

Dimension scrambleSize = scramble.getPreferredSize();

scrambleSize.width = 30;

scramble.setPreferredSize(scrambleSize);

JPanel scramblePanel = new JPanel();

scramblePanel.setLayout(new BorderLayout());

scramblePanel.add(scramble, BorderLayout.WEST);

formUtility.addLastField(scramblePanel, form);

JButton addButton = new JButton("Add");

form.add(addButton);

//addButton.add(

addButton.addActionListener(

new ActionListener()

{

public void actionPerformed( ActionEvent actionEvent )//valueChanged(ListSelectionEvent e)

{

//f.DoModal();

System.out.println("********************************************");

System.out.println("********************************************");

System.out.println("LName is:" + lname.getText());

System.out.println("FName is:" + fname.getText());

System.out.println("MName is:" + mname.getText());

System.out.println("Facility is: " + SenListArraySetUp.facilities[list.getSelectedIndex()]);

System.out.println("SenDate is: " + sdate.getText());

System.out.println("Score is:" + score.getText(/*SenListHelpers.getArrayColLength(array, lineCount - 1)*/));

System.out.println("Scramble is: " + scramble.getText(/*SenListHelpers.getArrayColLength(array, lineCount)*/));

System.out.println("********************************************");

System.out.println("********************************************");

nameInfoString = lname.getText()+ " " + fname.getText() + " " + mname.getText() + " " +

SenListArraySetUp.facilities[list.getSelectedIndex()]

+ " " + sdate.getText() + " " + score.getText() + " " +

scramble.getText();

//System.out.println("Size is: " + SenListHelpers.getArrayLength(SenListArraySetUp.NYSDOCS_Alpha_List_LastNames));

/*

insertMethods.insertIntoNYSDOCSAlphaHelper(

lname.getText(), fname.getText(), mname.getText(),

facilities[list.getSelectedIndex()],

sdate.getText(), score.getText(), scramble.getText() );

*/

//form.cl

f.dispose();

JOptionPane.showMessageDialog(null, "The Officer has been Added.");

//return;

//System.exit(0);

//System.out.println("Facility is:" + facilities[list.getSelectedIndex()]);

/**/ //System.out.println("Facility is:" + facilities[list.getSelectedIndex()]);

//contentpane.setBackground(listColorValues

//[list.getSelectedIndex()]);

}

}

);

// Add an little padding around the form

form.setBorder(new EmptyBorder(2, 2, 2, 2));

//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//original close operation

// Note that we don抰 use pack() here, since that

// may shrink the 搇ast" column more than we want.

f.setSize(300, 300);//230);

f.setVisible(true);

finish();

//int x = form.DoModal();

//return;

}

public static String getNameInfo(String[][] array, int lineCount)

{

String[][] tempArray= new String[10][20];

String str = new String();

//BURLEY KEVIN R WYOMING 1996-03-04 85.0 094

int i = 0;

while( i < SenListHelpers.getFacilityIndex(array, lineCount) )

{

str = str + array[lineCount][i];

if( (SenListHelpers.getFacilityIndex(array, lineCount) - i) > 0)

str = str + " ";

System.out.println("str is" + str);

i ++;

}

return str;

}

public int getFacilityIndex(String facility, String[] facilities)

{

int i = 0;

while( i < SenListHelpers.getArrayLength(facilities) )

{

if( SenListHelpers.compareStringByCase(facilities[i], facility) )

break;

i ++;

}

System.out.println("i is" + i);

return i;

}

public String getLName()

{

String LName = "";

LName = lname.getText();

return LName;

}

public String getFName()

{

String FName = "";

FName = fname.getText();

return FName;

}

public String getMName()

{

String MName = "";

MName = mname.getText();

return MName;

}

public String getFacility()

{

String Facility = "";

Facility = facilities[0];

//Facility = facilities[list.getSelectedIndex()];

//facilities[list.getSelectedIndex()]

return Facility;

}

public String getSenDate()

{

String SenDate = "";

SenDate = sdate.getText();

return SenDate;

}

public String getScore()

{

String Score = "";

Score = score.getText();

return Score;

}

public String getScramble()

{

String Scramble = "";

Scramble = scramble.getText();

return Scramble;

}

public void finish()

{

synchronized(this)

{

test.completed = true;

notifyAll();

}

setVisible(false);

}

public static void main(String[] args)

{

//correctOfficerGUI test = new correctOfficerGUI();

//test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 8
Aiyo! That's too much code! Post a small (< 1 page) example program to demonstrate your problem.
BigDaddyLoveHandlesa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 9

This is the crux of the problem. When I call the GUI class I want the calling class to halt until the GUI gets it's info...

read_in_employees_from_file();

if( employee info is odd type )

{

call GUI class to open GUI

stop this method until GUI is finished

do stuff;

do more stuff

}

//in GUI class

open GUI to request user to rearrange info

Message was edited by:

poncho

ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 10
> Aiyo! That's too much code! Post a small (< 1 page)> example program to demonstrate your problem.Aiyo? Anyway, back to the OP: Why not use a JDialog? They were born to do this kind of thing. Why make things too difficult for yourself?
petes1234a at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 11

Ah, I remember this code. I was one who said earlier to use a JDialog (among others).

http://forum.java.sun.com/thread.jspa?threadID=5189368&start=15&tstart=0

Frankly, your code really needs a lot of work. You're still not using the JFrame capabilities of the JFrame class (or JDialog capabilities, were it a JDialog). I'm again talking about the your having a class, correctOfficerGUI that extends JFrame but also has a JFrame variable "f" that is the frame that is displayed by the program. I recommended previously against doing this, and I continue to recommend against doing it.

I think that a total revamp would actually do the code a lot of good. This would force you to think about the program structure before committing code to compiler. I know that sometimes when I'm stuck on a basic problem that lies at the foundation of a project, I have sometimes had to do just this. Chuck out the old code and restart from afresh.

Good luck.

Message was edited by:

petes1234

petes1234a at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 12
The issue w/ this is that I need multiple text fields in the GUI, thus I can not go w/ a JOptionPane...
ponchoa at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 13

> The issue w/ this is that I need multiple text fields

> in the GUI, thus I can not go w/ a JOptionPane...

I / we never said anything about JOptionPane. I said JDialog. Please look into the JDialog API in greater detail. I get the feeling that you really don't understand this component yet. This is not a simple JOptionPane (though they can get somewhat complex) but a fully functioning root pane and can do most anything a JFrame can do.

petes1234a at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 14

Always put your design "on paper" first. Learn UML and use it. Take a look at how your program is going to flow ... never jump into a project and just start coding. Work your way through it first, writing the process down. You'll see that a lot of the ideas you had floating around in your head won't work ... sometimes very fundamental things to your application. Work it through on paper first - once you get a result that flows cleanly, then you can start having fun ;-)

Navy_Codera at 2007-7-12 21:57:48 > top of Java-index,Java Essentials,Java Programming...
# 15

I figured out the halting GUI problem. This is what I did...

Thread t = Thread.currentThread();

if( name is of odd type )

{

correctOfficerGUI test = new correctOfficerGUI(tempElements1, lineCount, thrd);//launch GUI

test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

synchronized (t)

{

t.wait();

//Make Thread Wait....It will be released in NameGUI

}

}//end if

//then in GUI class

synchronized (curThread)

{

t.notify();

//Notify our thread that it may resume executing!

//Destroy the GUI.....

}

...and it works as I wanted...

ponchoa at 2007-7-21 22:57:11 > top of Java-index,Java Essentials,Java Programming...
# 16

I figured out the halting GUI problem. This is what I did...

Thread t = Thread.currentThread();

if( name is of odd type )

{

correctOfficerGUI test = new correctOfficerGUI(tempElements1, lineCount, thrd); //launch GUI

test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

synchronized (t)

{

t.wait();

//Make Thread Wait....It will be released in NameGUI

}

}//end if

//then in GUI class

synchronized (curThread)

{

t.notify();

//Notify our thread that it may resume executing!

//Destroy the GUI.....

}

...and it works as I wanted...

ponchoa at 2007-7-21 22:57:11 > top of Java-index,Java Essentials,Java Programming...
# 17
You can also use a laptap computer as a garden spade. Sure you can use it to dig up your garden, but is it the right tool for the job? Are you a computer sciences major by the way?
petes1234a at 2007-7-21 22:57:11 > top of Java-index,Java Essentials,Java Programming...
# 18

It's a different kind of modality from JDialog, I call it "Thread modal" as opposed to "system modal". It's useful in somewhat different circumstances, e.g. a background thread needs to ask for information, and you might want to do something else before supplying it.

But, personally, I think it's asking for future problems to use wait and notify without an accompanying flag.

malcolmmca at 2007-7-21 22:57:11 > top of Java-index,Java Essentials,Java Programming...