Results 1 to 2 of 2
Thread: help with java swt :)
- 06-23-2012, 11:23 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
help with java swt :)
I wrote Gui code in java, using the lib of swt.
1. How can I insert user value to my variable?
For example, user inset his age, and I want to restore this data. How can I do it?
2. How can I organize the groups to be one under the other?
3. When I execute the program the window is very small and I don’t see the buttons, how can I change it?
4. How the button of "about" can be in the left corner?
5. I have "exit" function how I can connect it to the X button on the up-right corner of the window?
this is my code..
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class GUI2
{
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("my progream");
shell.open();
/**************************group1****************** *****************************/
Group group1 = new Group(shell, SWT.SHADOW_OUT);
group1.setText("Step 1: Choose:");
group1.setLayout(new GridLayout(1, true));
//buttonCsv
final Button button1=new Button(group1, SWT.RADIO);
button1.setText("choice 1 ");
//buttonTxt
final Button button2=new Button(group1, SWT.RADIO);
button2.setText("choice 2 ");
Listener listener1 = new Listener()
{
public void handleEvent(Event event)
{
int user_choice;
if(event.widget==button1)
{
user_choice=1;
System.out.println(user_choice);
}
else if(event.widget==button2)
{
user_choice=2;
System.out.println(user_choice);
}
}
};
button1.addListener(SWT.Selection, listener1);
button2.addListener(SWT.Selection, listener1);
/**********************group2********************** *****************************/
Group group2 = new Group(shell, SWT.SHADOW_OUT);
group2.setText("Step 2: Insert your age ");
group2.setLayout(new GridLayout(1, true));
Text textRow=new Text(group2, SWT.BORDER);
textRow.setText(" ");
/************************group3******************** *****************************/
Group group3 = new Group(shell, SWT.SHADOW_OUT);
group3.setText("Step 3: Insert your id ");
group3.setLayout(new GridLayout(1, true));
new Text(group3, SWT.BORDER).setText(" ");
/************************group4******************** *****************************/
Group group4 = new Group(shell, SWT.SHADOW_OUT);
group4.setText("Step 4:");
group4.setLayout(new GridLayout(1, true));
final Button buttonGen=new Button(group4, SWT.PUSH);
buttonGen.setText("Generate Data");
Listener listener3 = new Listener()
{
public void handleEvent(Event event)
{
if(event.widget==buttonGen)
{
int user_choice=1;
System.out.println("user_choice " + user_choice);
}
}
};
buttonGen.addListener(SWT.Selection, listener3);
/************************buttonAbout*************** **********************************/
final Button buttonAbout=new Button(shell, SWT.PUSH);
buttonAbout.setText("About");
/************************************************** ***********************/
shell.setSize(600, 300);
shell.pack();
shell.setLayout(new GridLayout(2,true));
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
{
// If no more entries in the event queue
display.sleep();
}
}
display.dispose();
}
/************************************************** ********/
public void saveFileLocation(Shell shell)
{
FileDialog fd=new FileDialog(shell,SWT.OPEN);
fd.setText("open");
fd.setFilterPath("E:/workspace/89210 part3");
String[] filterExt = { "*.txt", "*.java", ".xml", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
}
/************************************************** ********/
public void exit(Shell shell)
{
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION| SWT.YES | SWT.NO);
messageBox.setMessage("Do you really want to exit?");
messageBox.setText("Exiting Application");
int response = messageBox.open();
if (response == SWT.YES)
System.exit(0);
}
}
- 06-24-2012, 05:13 AM #2
Re: help with java swt :)
Forum Rules -- particularly the third paragraph
http://www.java-forums.org/forum-gui...w-members.html
BB Code List - Java Programming Forum
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Bookmarks