Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Newcomer with SWT has no idea what to do...
Newcomer with SWT has no idea what to do... [message #1746853] Sun, 06 November 2016 14:00 Go to next message
Hayden Stites is currently offline Hayden StitesFriend
Messages: 1
Registered: November 2016
Junior Member
I am new to Eclipse and the SWT. I am trying to make a simple button chooser as a launch point for my software. What's wrong with this?

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainController {

public static void main(String[] args) {
MainController main = new MainController();
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello, World!");
shell.open();
chooseFeature(shell);

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

public static void chooseFeature(Composite shell) {
Button button = new Button(shell, SWT.RADIO);

button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("Called!");
}
});
}

}
Re: Newcomer with SWT has no idea what to do... [message #1747618 is a reply to message #1746853] Wed, 16 November 2016 14:31 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

Here is your code now working as expected :

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainController {

	public static void main(String[] args) {
		MainController main = new MainController();
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Hello, World!");
		chooseFeature(shell);
		shell.setLayout(new FillLayout());
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	public static void chooseFeature(Composite shell) {
		Button button = new Button(shell, SWT.PUSH);
		button.setText("Click me!");

		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Called!");
			}
		});
	}

}
Re: Newcomer with SWT has no idea what to do... [message #1747619 is a reply to message #1746853] Wed, 16 November 2016 14:32 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

Here is your code now working as expected :

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainController {

	public static void main(String[] args) {
		MainController main = new MainController();
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Hello, World!");
		chooseFeature(shell);
		shell.setLayout(new FillLayout());
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	public static void chooseFeature(Composite shell) {
		Button button = new Button(shell, SWT.PUSH);
		button.setText("Click me!");

		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Called!");
			}
		});
	}

}
Re: Newcomer with SWT has no idea what to do... [message #1747622 is a reply to message #1746853] Wed, 16 November 2016 14:47 Go to previous message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

Here is your code now working as expected :

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainController {

	public static void main(String[] args) {
		MainController main = new MainController();
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Hello, World!");
		chooseFeature(shell);
		shell.setLayout(new FillLayout());
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	public static void chooseFeature(Composite shell) {
		Button button = new Button(shell, SWT.PUSH);
		button.setText("Click me!");

		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Called!");
			}
		});
	}

}
Previous Topic:OLE Automation in Java does not send e-mail from all computers
Next Topic:Wrap Text on SWT Table Cell
Goto Forum:
  


Current Time: Mon Dec 18 07:22:28 GMT 2017

Powered by FUDForum. Page generated in 0.01740 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software