Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. package com.company;
  2. import org.eclipse.swt.SWT;
  3. import org.eclipse.swt.events.SelectionAdapter;
  4. import org.eclipse.swt.events.SelectionEvent;
  5. import org.eclipse.swt.layout.GridData;
  6. import org.eclipse.swt.layout.GridLayout;
  7. import org.eclipse.swt.layout.RowLayout;
  8. import org.eclipse.swt.widgets.Button;
  9. import org.eclipse.swt.widgets.Composite;
  10. import org.eclipse.swt.widgets.DateTime;
  11. import org.eclipse.swt.widgets.Display;
  12. import org.eclipse.swt.widgets.Label;
  13. import org.eclipse.swt.widgets.List;
  14. import org.eclipse.swt.widgets.Shell;
  15. import org.eclipse.swt.widgets.Text;
  16.  
  17.  
  18. public class Main {
  19.  
  20. public static void main(String[] args) {
  21.  
  22. Display display = new Display();
  23. Shell shell = new Shell(display);
  24. shell.setSize(1000,500) ;
  25. shell.setText("SWTSample");
  26.  
  27. //ustawienia layout managera
  28. GridLayout layout = new GridLayout();
  29. layout.numColumns = 2;
  30. layout.horizontalSpacing=0;
  31. layout.verticalSpacing=0;
  32. layout.marginHeight=0;
  33. layout.marginWidth=0;
  34. layout.makeColumnsEqualWidth = true;
  35. shell.setLayout(layout);
  36.  
  37. //PANEL 1
  38. GridData dat = new GridData(GridData.FILL_BOTH);
  39. Composite composite = new Composite(shell, SWT.NONE);
  40. composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
  41.  
  42. DateTime calendar = new DateTime (composite, SWT.CALENDAR | SWT.BORDER);
  43. DateTime time = new DateTime (composite, SWT.TIME | SWT.SHORT);
  44. Button ok = new Button(composite,0);
  45. ok.setText("Dodaj wyjazd");
  46.  
  47.  
  48. List lis = new List(composite,SWT.MULTI);
  49.  
  50.  
  51. //Label lb = new Label(composite,SWT.SHADOW_IN);
  52. //lb.setText(" ");
  53.  
  54.  
  55. composite.setLayout(new RowLayout(SWT.VERTICAL));
  56. composite.setLayoutData(dat);
  57.  
  58. //lis.addSelectionListener(new SelectionListener() { //wyswietlanie z list boxa nr wyjazdu
  59.  
  60. // public void widgetSelected(SelectionEvent event) {
  61. // int[] selections = lis.getSelectionIndices();
  62. // String outText = "";
  63. // for (int loopIndex = 0; loopIndex < selections.length; loopIndex++)
  64. // outText += selections[loopIndex] + 1 + " ";
  65. // lb.setText("Wyjazd numer: " + outText);
  66. // }
  67.  
  68. // public void widgetDefaultSelected(SelectionEvent event) {
  69. //int[] selections = lis.getSelectionIndices();
  70. //String outText = "";
  71. //for (int loopIndex = 0; loopIndex < selections.length; loopIndex++)
  72. //outText += selections[loopIndex] + " ";
  73. //lb.setText("Wyjazd numer: " + outText);
  74. // }
  75. //});
  76.  
  77. ok.addSelectionListener (new SelectionAdapter () {
  78. public void widgetSelected (SelectionEvent e) {
  79. lis.add("Wyjazd data: " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ()+"Godzina: " + time.getHours () + ":" + time.getMinutes ());
  80. lis.pack();
  81. }
  82. });
  83.  
  84.  
  85. //PANEL 2
  86. dat = new GridData(GridData.FILL_BOTH);
  87. Composite composite2 = new Composite(shell, SWT.NONE);
  88. composite2.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
  89.  
  90.  
  91. Label label1 = new Label(composite2,SWT.NONE);
  92. label1.setText("Podaj rozmiar rybki w cm");
  93.  
  94. Text text = new Text(composite2, SWT.BORDER);
  95.  
  96. Button radioButton1 = new Button(composite2, SWT.RADIO);
  97. radioButton1.setText("Karp osiecki (królewski)");
  98. Button radioButton2 = new Button(composite2, SWT.RADIO);
  99. radioButton2.setText("Amur");
  100. Button radioButton3 = new Button(composite2, SWT.RADIO);
  101. radioButton3.setText("Karaś");
  102. Button radioButton4 = new Button(composite2, SWT.RADIO);
  103. radioButton4.setText("Lin");
  104. Button radioButton5 = new Button(composite2, SWT.RADIO);
  105. radioButton5.setText("Tołpyga");
  106. Button radioButton6 = new Button(composite2, SWT.RADIO);
  107. radioButton6.setText("Sum");
  108. Button radioButton7 = new Button(composite2, SWT.RADIO);
  109. radioButton7.setText("Szczupak");
  110.  
  111.  
  112. //Wyswietlanie informacji o możliwości zabrania rybki
  113. Label labelRyba = new Label(composite2,SWT.BORDER);
  114. labelRyba.setText(" ");
  115. composite2.setLayout(new RowLayout(SWT.VERTICAL));
  116. composite2.setLayoutData(dat);
  117.  
  118. //labele , przyciski, textboxy odpowiadające za cene rybki
  119. Label label2 = new Label(composite2,SWT.NONE);
  120. label2.setText(" Podaj wagę rybki ");
  121. Text text2 = new Text(composite2, SWT.BORDER);
  122. Button rybka = new Button(composite2,0);
  123. rybka.setText(" Cena rybki ");
  124. Label rybkaCena = new Label(composite2,SWT.BORDER);
  125. rybkaCena.setText(" ");
  126.  
  127.  
  128. rybka.addSelectionListener(new SelectionAdapter() {
  129.  
  130. public void widgetSelected(SelectionEvent e) //wyswietlanie ceny ryby
  131. {
  132. if (radioButton1.getSelection())
  133. {
  134. double rybka = Double.parseDouble(text2.getText());
  135. double wynik = rybka * 13;
  136. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  137. }
  138. else if (radioButton2.getSelection())
  139. {
  140. double rybka = Double.parseDouble(text2.getText());
  141. double wynik = rybka * 10;
  142. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  143. }
  144. else if (radioButton3.getSelection())
  145. {
  146. double rybka = Double.parseDouble(text2.getText());
  147. double wynik = rybka * 6;
  148. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  149. }
  150. else if (radioButton4.getSelection())
  151. {
  152. double rybka = Double.parseDouble(text2.getText());
  153. double wynik = rybka * 15;
  154. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  155. }
  156. else if (radioButton5.getSelection())
  157. {
  158. double rybka = Double.parseDouble(text2.getText());
  159. double wynik = rybka * 6;
  160. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  161. }
  162. else if (radioButton6.getSelection())
  163. {
  164. double rybka = Double.parseDouble(text2.getText());
  165. double wynik = rybka * 32;
  166. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  167. }
  168. else if (radioButton7.getSelection())
  169. {
  170. double rybka = Double.parseDouble(text2.getText());
  171. double wynik = rybka * 32;
  172. rybkaCena.setText(String.valueOf(wynik) + " Zł");
  173. }
  174. }
  175. });
  176.  
  177. radioButton1.addSelectionListener(new SelectionAdapter() { // wyświetlanie wymiarowosci ryby
  178.  
  179. @Override
  180. public void widgetSelected(SelectionEvent e) {
  181.  
  182. if(Integer.parseInt(text.getText()) <= 30)
  183. {
  184. labelRyba.setText("Nie można zabrać rybki");
  185. }
  186. else {
  187.  
  188. labelRyba.setText("Można zabrać rybke");
  189. }
  190. }
  191.  
  192. });
  193.  
  194. radioButton2.addSelectionListener(new SelectionAdapter() {
  195.  
  196. @Override
  197. public void widgetSelected(SelectionEvent e) {
  198.  
  199. labelRyba.setText("Można zabrać rybke");
  200. }
  201.  
  202. });
  203. radioButton3.addSelectionListener(new SelectionAdapter() {
  204.  
  205. @Override
  206. public void widgetSelected(SelectionEvent e) {
  207.  
  208. if(Integer.parseInt(text.getText()) <= 30)
  209. {
  210. labelRyba.setText("Nie można zabrać rybki");
  211. }
  212. else {
  213.  
  214. labelRyba.setText("Można zabrać rybke");
  215. }
  216. }
  217.  
  218. });
  219.  
  220. radioButton4.addSelectionListener(new SelectionAdapter() {
  221.  
  222.  
  223. public void widgetSelected(SelectionEvent e) {
  224.  
  225. if(Integer.parseInt(text.getText()) <= 35)
  226. {
  227. labelRyba.setText("Nie można zabrać rybki");
  228. }
  229. else {
  230.  
  231. labelRyba.setText("Można zabrać rybke");
  232. }
  233. }
  234.  
  235. });
  236.  
  237. radioButton5.addSelectionListener(new SelectionAdapter() {
  238.  
  239.  
  240. public void widgetSelected(SelectionEvent e) {
  241.  
  242. labelRyba.setText("Można zabrać rybke");
  243. }
  244.  
  245. });
  246.  
  247. radioButton6.addSelectionListener(new SelectionAdapter() {
  248.  
  249.  
  250. public void widgetSelected(SelectionEvent e) {
  251.  
  252. if(Integer.parseInt(text.getText()) <= 70)
  253. {
  254. labelRyba.setText("Nie można zabrać rybki");
  255. }
  256. else {
  257.  
  258. labelRyba.setText("Można zabrać rybke");
  259. }
  260. }
  261.  
  262. });
  263.  
  264. radioButton7.addSelectionListener(new SelectionAdapter() {
  265.  
  266.  
  267. public void widgetSelected(SelectionEvent e) {
  268.  
  269. if(Integer.parseInt(text.getText()) <= 50)
  270. {
  271. labelRyba.setText("Nie można zabrać rybki");
  272. }
  273. else {
  274.  
  275. labelRyba.setText("Można zabrać rybke");
  276. }
  277. }
  278.  
  279. });
  280.  
  281.  
  282.  
  283. shell.open ();
  284. while (!shell.isDisposed ()) {
  285. if (!display.readAndDispatch ()) display.sleep ();
  286. }
  287. display.dispose ();
  288.  
  289. }
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement