Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.channels.InterruptibleChannel;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Text;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.widgets.Combo;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.widgets.Label;
- import org.eclipse.swt.events.SelectionAdapter;
- import org.eclipse.swt.events.SelectionEvent;
- public class App0207 {
- protected Shell shlNasKalkulator;
- private Text txtPrviBroj;
- private Text txtDrugiBroj;
- /**
- * Launch the application.
- * @param args
- */
- public static void main(String[] args) {
- try {
- App0207 window = new App0207();
- window.open();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Open the window.
- */
- public void open() {
- Display display = Display.getDefault();
- createContents();
- shlNasKalkulator.open();
- shlNasKalkulator.layout();
- while (!shlNasKalkulator.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
- /**
- * Create contents of the window.
- */
- protected void createContents() {
- shlNasKalkulator = new Shell();
- shlNasKalkulator.setSize(222, 241);
- shlNasKalkulator.setText("Nas kalkulator");
- txtPrviBroj = new Text(shlNasKalkulator, SWT.BORDER);
- txtPrviBroj.setBounds(53, 37, 91, 21);
- txtDrugiBroj = new Text(shlNasKalkulator, SWT.BORDER);
- txtDrugiBroj.setBounds(52, 64, 92, 21);
- final Combo cmbOperacija = new Combo(shlNasKalkulator, SWT.READ_ONLY);
- cmbOperacija.setItems(new String[] {"Sabiranje", "Oduzimanje", "Mnozenje", "Deljenje"});
- cmbOperacija.setBounds(53, 91, 91, 23);
- cmbOperacija.select(0);
- Button btnIzracunaj = new Button(shlNasKalkulator, SWT.NONE);
- final Label lblRezultat = new Label(shlNasKalkulator, SWT.NONE);
- lblRezultat.setBounds(53, 161, 55, 15);
- lblRezultat.setText("New Label");
- btnIzracunaj.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- //System.out.println(txtPrviBroj.getText());
- //System.out.println(txtDrugiBroj.getText());
- try {
- int prviBroj = Integer.parseInt(txtPrviBroj.getText());
- int drugiBroj = Integer
- .parseInt(txtDrugiBroj.getText());
- int rezultat = 0;
- if (cmbOperacija.getSelectionIndex() == 0) {
- rezultat = prviBroj + drugiBroj;
- } else if (cmbOperacija.getSelectionIndex() == 1) {
- rezultat = prviBroj - drugiBroj;
- } else if (cmbOperacija.getSelectionIndex() == 2) {
- rezultat = prviBroj * drugiBroj;
- } else {
- rezultat = prviBroj / drugiBroj;
- }
- //System.out.println(rezultat);
- lblRezultat.setText(Integer.toString(rezultat));
- } catch (NumberFormatException textGreske1) {
- lblRezultat.setText("Greska! Ispravite unos!");
- } catch (Exception textGreske) {
- lblRezultat.setText("Greska! Deljenje sa nulom!");
- }
- }
- });
- btnIzracunaj.setBounds(53, 120, 75, 25);
- btnIzracunaj.setText("Izra\u010Dunaj");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement