Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] New to Java and SWT

Title: Message
Hi,
I'm taking a java class and one of the things i need to do for a final project is create a program that has 3 or 4 queries over a database file.  For extra Credit we can turn this into a GUI.  We haven't gone over GUI at all and when we do it will be SWING.  However, i would like to do this in SWT.  I've been looking at some samples, and have created my first screen.  This screen allows the user to enter a Id and Password to connect to the database.  Conceptually this is what i would like to do
 
Display  Signon Screen.  Connect to database when button is pressed.
Then display a second screen that has the available options.  ie list team info by owner id, etc, etc.   As i press  a button for each query  on the same panel, i would like to display instructions and the corresponding text fields etc for enter my search criteria..
After entering search criteria, i would like to display a new window showing results. 
 
Now the problem is that i don't have a clue how to create a new window.  When i try to do this, i get a 'Thread exception'.  I think it has to do with needing to use syncExec and runnable, but i can't really figure out how to take what i have currently and implement this. 
 
Can someone provide me a simple example of a 2 window application. 
 
here is what i have currently.  keep in mind it doesn't really do anything yet, i'm just trying to figure out the GUI part.  
 
Thanks
 
Mike
 

import org.eclipse.swt.graphics.*;

import org.eclipse.swt.custom.*;

import org.eclipse.swt.events.*;

import org.eclipse.swt.widgets.*;

import org.eclipse.swt.*;

public class MainScreen

{

public static void main(String[] args)

{

Display display = new Display();

Shell shell = new Shell(display);

shell.setSize(300,300);

shell.open();

Label label1 = new Label(shell, SWT.NONE);

label1.setText("Enter User Id");

label1.setSize(100,20);

label1.setLocation(30,30);

Label label2 = new Label(shell, SWT.NONE);

label2.setText("Enter PassWord");

label2.setSize(100,20);

label2.setLocation(30,50);

Text text1 = new Text(shell, SWT.BORDER);

text1.setText("");

text1.setBounds(10,10,100,20);

text1.setTextLimit(30);

text1.setLocation(130,30);

text1.setFocus();

Text text2 = new Text(shell, SWT.BORDER);

text2.setEchoChar('*');

text2.setBounds(10,50,100,20);

text2.setLocation(130,50);

Button button1 = new Button(shell,SWT.PUSH|SWT.CENTER);

button1.setText("Press Enter To Log On");

button1.setLocation(70,150);

button1.setSize(150,20);

button1.addSelectionListener(new SelectionAdapter() {

public void widgetSelected(SelectionEvent e) {

System.out.println("Button1 was clicked");

window2();

}

});

while(!shell.isDisposed())

if(!display.readAndDispatch())

display.sleep();

display.dispose();

label1.dispose();

label2.dispose();

text1.dispose();

text2.dispose();

button1.dispose();

}

public static void window2()

{

Display display = new Display();

Shell shell = new Shell(display);

shell.setSize(300,300);

shell.open();

Label label1 = new Label(shell, SWT.NONE);

label1.setText("Enter User Id");

while(!shell.isDisposed())

if(!display.readAndDispatch())

display.sleep();

display.dispose();

label1.dispose();

}

}


Back to the top