1 / 11

Beispiele zum Vortrag JavaSWTSS06

Beispiele zum Vortrag JavaSWTSS06. Start-Klasse. public class start { public static void main(String[] args) { new beispiel1(); } }. Beispiel 1. import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class beispiel1 { beispiel1() {

Download Presentation

Beispiele zum Vortrag JavaSWTSS06

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Beispiele zum Vortrag JavaSWTSS06

  2. Start-Klasse public class start { public static void main(String[] args) { new beispiel1(); } }

  3. Beispiel 1 import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class beispiel1 { beispiel1() { //Initialisieren des Displays und der Shell Display display = new Display(); Shell shell = new Shell(display); shell.setSize(300,300); shell.setText("SWT Beispiel 1"); //Haupt-Schleife shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

  4. Beispiel 2 import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class beispiel2 { beispiel2() { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(300,300); shell.setText("SWT Beispiel 2"); //Hinzufügen eines Labels Label label1 = new Label(shell, SWT.NONE); label1.setText("Ein Label"); label1.setSize(200,20); label1.setLocation(30,30); //Hinzufügen eines Textfelds Text text1 = new Text(shell, SWT.BORDER); text1.setTextLimit(30); text1.setText("Ein Textfeld"); text1.setBounds(30,60,200,90); text1.setTextLimit(30);

  5. //Hinzufügen einer Combobox Combo combo1 = new Combo(shell,SWT.DROP_DOWN | SWT.READ_ONLY); combo1.setItems(new String[] {"Eins","Zwei","Drei"}); combo1.select(1); combo1.setLocation(30,160); combo1.setSize(200,20); //Hinzufügen eines Buttons Button button1 = new Button(shell,SWT.PUSH); button1.setText("Ein Button"); button1.setLocation(30,220); button1.setSize(100,20); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

  6. Beispiel 3 import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.layout.FillLayout; public class beispiel3 { //Ein einfacher Browser beispiel3() { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(900,500); shell.setText("SWT Beispiel 4"); shell.setLayout(new FillLayout()); // FillLyaout verwenden //Browser initialisieren Browser browser = new Browser(shell, SWT.BORDER); browser.setSize(800, 400); browser.setUrl("http://www.google.de"); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

  7. Beispiel 4 import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.events.*; //Für die Listener public class beispiel4 { Text text1; Combo combo1; beispiel4() { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(300,300); shell.setText("SWT Beispiel 3"); Label label1 = new Label(shell, SWT.NONE); label1.setText("Bitte einen Text eingeben:"); label1.setSize(200,20); label1.setLocation(30,30); Label seperator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); seperator.setBounds(30,60,200,20);

  8. text1 = new Text(shell, SWT.BORDER); text1.setTextLimit(30); text1.setText("Ihr Text..."); text1.setBounds(30,90,200,60); combo1 = new Combo(shell,SWT.DROP_DOWN | SWT.READ_ONLY); combo1.setItems(new String[] {"Eintrag eins","Eintrag zwei","Eintrag drei"}); combo1.select(1); combo1.setLocation(30,160); combo1.setSize(200,20); //Hinzufügen eines Menüs //Menüleiste Menu menu = new Menu(shell, SWT.BAR); shell.setMenuBar(menu); //Datei-Menü Menu filemenu = new Menu(shell, SWT.DROP_DOWN); MenuItem mi = new MenuItem(menu, SWT.CASCADE); mi.setText("Datei"); mi.setMenu(filemenu); //Menüeintrag hinzufügen MenuItem me = new MenuItem(filemenu, SWT.PUSH); me.setText("Datei öffnen..."); //Filechooser final FileDialog fileChooser = new FileDialog(shell, SWT.OPEN|SWT.MULTI); fileChooser.setText("Open movie files"); fileChooser.setFilterExtensions(new String[] { "*.avi; *.mov; *.mpg", "*.*"}); fileChooser.setFilterNames(new String[] {"movie files (*.avi; *.mov; *.mpg)", "all (*.*)"});

  9. //Listener für das Menü SelectionListener menulistener = new SelectionListener(){ public void widgetSelected(SelectionEvent e) { String filename = fileChooser.open(); text1.setText(filename); } public void widgetDefaultSelected(SelectionEvent e){} }; me.addSelectionListener(menulistener); Button button1 = new Button(shell,SWT.PUSH); button1.setText("Dialog anzeigen"); button1.setLocation(30,220); button1.setSize(100,20); //Listener für den Button button1.addSelectionListener(new SelectionListener(){ public void widgetSelected(SelectionEvent e) { showMessageBox(shell); } public void widgetDefaultSelected(SelectionEvent e) {} }); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } display.dispose(); }

  10. public void showMessageBox(Shell shell) { MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION); mb.setMessage(text1.getText()); mb.setText("Auswahl war:" + combo1.getText()); mb.open(); } }

  11. Beispiel 5

More Related