Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.events.SelectionAdapter;
- import org.eclipse.swt.events.SelectionEvent;
- import org.eclipse.swt.layout.GridData;
- import org.eclipse.swt.layout.GridLayout;
- import org.eclipse.swt.layout.RowLayout;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.widgets.Composite;
- import org.eclipse.swt.widgets.DateTime;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Label;
- import org.eclipse.swt.widgets.List;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Text;
- public class Main {
- public static void main(String[] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setSize(1000,500) ;
- shell.setText("SWTSample");
- //ustawienia layout managera
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.horizontalSpacing=0;
- layout.verticalSpacing=0;
- layout.marginHeight=0;
- layout.marginWidth=0;
- layout.makeColumnsEqualWidth = true;
- shell.setLayout(layout);
- //PANEL 1
- GridData dat = new GridData(GridData.FILL_BOTH);
- Composite composite = new Composite(shell, SWT.NONE);
- composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
- DateTime calendar = new DateTime (composite, SWT.CALENDAR | SWT.BORDER);
- DateTime time = new DateTime (composite, SWT.TIME | SWT.SHORT);
- Button ok = new Button(composite,0);
- ok.setText("Dodaj wyjazd");
- List lis = new List(composite,SWT.MULTI);
- //Label lb = new Label(composite,SWT.SHADOW_IN);
- //lb.setText(" ");
- composite.setLayout(new RowLayout(SWT.VERTICAL));
- composite.setLayoutData(dat);
- //lis.addSelectionListener(new SelectionListener() { //wyswietlanie z list boxa nr wyjazdu
- // public void widgetSelected(SelectionEvent event) {
- // int[] selections = lis.getSelectionIndices();
- // String outText = "";
- // for (int loopIndex = 0; loopIndex < selections.length; loopIndex++)
- // outText += selections[loopIndex] + 1 + " ";
- // lb.setText("Wyjazd numer: " + outText);
- // }
- // public void widgetDefaultSelected(SelectionEvent event) {
- //int[] selections = lis.getSelectionIndices();
- //String outText = "";
- //for (int loopIndex = 0; loopIndex < selections.length; loopIndex++)
- //outText += selections[loopIndex] + " ";
- //lb.setText("Wyjazd numer: " + outText);
- // }
- //});
- ok.addSelectionListener (new SelectionAdapter () {
- public void widgetSelected (SelectionEvent e) {
- lis.add("Wyjazd data: " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ()+"Godzina: " + time.getHours () + ":" + time.getMinutes ());
- lis.pack();
- }
- });
- //PANEL 2
- dat = new GridData(GridData.FILL_BOTH);
- Composite composite2 = new Composite(shell, SWT.NONE);
- composite2.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- Label label1 = new Label(composite2,SWT.NONE);
- label1.setText("Podaj rozmiar rybki w cm");
- Text text = new Text(composite2, SWT.BORDER);
- Button radioButton1 = new Button(composite2, SWT.RADIO);
- radioButton1.setText("Karp osiecki (królewski)");
- Button radioButton2 = new Button(composite2, SWT.RADIO);
- radioButton2.setText("Amur");
- Button radioButton3 = new Button(composite2, SWT.RADIO);
- radioButton3.setText("Karaś");
- Button radioButton4 = new Button(composite2, SWT.RADIO);
- radioButton4.setText("Lin");
- Button radioButton5 = new Button(composite2, SWT.RADIO);
- radioButton5.setText("Tołpyga");
- Button radioButton6 = new Button(composite2, SWT.RADIO);
- radioButton6.setText("Sum");
- Button radioButton7 = new Button(composite2, SWT.RADIO);
- radioButton7.setText("Szczupak");
- //Wyswietlanie informacji o możliwości zabrania rybki
- Label labelRyba = new Label(composite2,SWT.BORDER);
- labelRyba.setText(" ");
- composite2.setLayout(new RowLayout(SWT.VERTICAL));
- composite2.setLayoutData(dat);
- //labele , przyciski, textboxy odpowiadające za cene rybki
- Label label2 = new Label(composite2,SWT.NONE);
- label2.setText(" Podaj wagę rybki ");
- Text text2 = new Text(composite2, SWT.BORDER);
- Button rybka = new Button(composite2,0);
- rybka.setText(" Cena rybki ");
- Label rybkaCena = new Label(composite2,SWT.BORDER);
- rybkaCena.setText(" ");
- rybka.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) //wyswietlanie ceny ryby
- {
- if (radioButton1.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 13;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton2.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 10;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton3.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 6;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton4.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 15;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton5.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 6;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton6.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 32;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- else if (radioButton7.getSelection())
- {
- double rybka = Double.parseDouble(text2.getText());
- double wynik = rybka * 32;
- rybkaCena.setText(String.valueOf(wynik) + " Zł");
- }
- }
- });
- radioButton1.addSelectionListener(new SelectionAdapter() { // wyświetlanie wymiarowosci ryby
- @Override
- public void widgetSelected(SelectionEvent e) {
- if(Integer.parseInt(text.getText()) <= 30)
- {
- labelRyba.setText("Nie można zabrać rybki");
- }
- else {
- labelRyba.setText("Można zabrać rybke");
- }
- }
- });
- radioButton2.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- labelRyba.setText("Można zabrać rybke");
- }
- });
- radioButton3.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if(Integer.parseInt(text.getText()) <= 30)
- {
- labelRyba.setText("Nie można zabrać rybki");
- }
- else {
- labelRyba.setText("Można zabrać rybke");
- }
- }
- });
- radioButton4.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if(Integer.parseInt(text.getText()) <= 35)
- {
- labelRyba.setText("Nie można zabrać rybki");
- }
- else {
- labelRyba.setText("Można zabrać rybke");
- }
- }
- });
- radioButton5.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- labelRyba.setText("Można zabrać rybke");
- }
- });
- radioButton6.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if(Integer.parseInt(text.getText()) <= 70)
- {
- labelRyba.setText("Nie można zabrać rybki");
- }
- else {
- labelRyba.setText("Można zabrać rybke");
- }
- }
- });
- radioButton7.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if(Integer.parseInt(text.getText()) <= 50)
- {
- labelRyba.setText("Nie można zabrać rybki");
- }
- else {
- labelRyba.setText("Można zabrać rybke");
- }
- }
- });
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement