Docsity

221387033 java programiranje, Vodiči, Projekti, Istraživanja od Informacioni sistemi

Toggle sidebar
bg1
Projektni rad
Predmet: Objektno orijentisano programiranje
Tema: Aplikacija-Kalkulator pisana u Javi
Profesor: dr Daragan Mišić
Asistent:
Studenti:
Maja Nikolić 126
Vesna Stojanović 104
Sadržaj:
1. Uvod u Java programskom jeziku...................................................3
2.
[Type
text]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Delimični pregled teksta

Preuzmite 221387033 java programiranje i više Vodiči, Projekti, Istraživanja u PDF od Informacioni sistemi samo na Docsity!

Projektni rad

Predmet: Objektno orijentisano programiranje

Tema: Aplikacija-Kalkulator pisana u Javi

Profesor: dr Daragan Mišić

Asistent:

Studenti:

Maja Nikolić 126

Vesna Stojanović 104

Sadržaj:

1. Uvod u Java programskom jeziku...................................................

[Type

Softversko okruženje -Pisanje Aplikacije

kalkulator ....................................................................................

Uvod u Java programskom jeziku

Java (engl. Java , izgovor: java, 2 21 7džava) je objektno-orijentisani programski jezik, koji je razvila kompanija Sun Microsystems početkom devedesetih godina. Mnogi koncepti Jave su zasnovani na jeziku Oberon Niklausa Virta, tvorca Paskala, Module i drugih jezika, i Hanspetera Mesenbeka. Izbacili su koncept modula i uveli pakete kakve danas znamo, koji se oslanjaju na

[Type

int , interface , long , native , new , package , private , protected , public , return , short , static , strictfp , super , switch , synchronized , this , throw , throws , transient , try , void , volatile i while. Osim ovih, rezervisane su i vrednosti: true , false i null. Izgovor Programski jezik Java je dobio naziv po ostrvu u Indoneziji, sa koga SAD uvoze velike količine kafe. Drugim rečima, Java je u SAD pojam koji se vezuje za kafu na sličan način kao što je to u Srbiji Brazil. Amerikanci ime ovog ostrva (pa samim tim i ime programskog jezika) izgovaraju Džava ili Đava, što je pogrešno, jer Indonežani, svoje ostrvo nazivaju upravo tako - Java. U srpskom govornom području je ustaljeno da se ime programskog jezika izgovara isto kao i ime ostrva, dakle, Java, iako se ponegde praktikuje američki izgovor.

[Type

[Type

sl.

Koraci za kreiranje izvorne datoteke (programa) su:

  1. Da bi se kreirao Java fajl iz glavnog menija treba izabrati File -> New -> Class.
  2. Uneti ime klase, u našem slučaju calculater_main.
  3. Izabrati public static void main(String[] args)
  4. Pritisnite dugme Finish sl.

sl.

Kreiramo drugu klasu, u našem slučaju calculater_ui. sl.

sl.

Class: calculater_main public class calculater_main extends calculater_ui { /**

  • @Vesna_Maja */ public static void main(String[] args) { calculater_ui n = new calculater_ui(); n.ui(); }

[Type

Class: calculater_ui import java.awt.FlowLayout; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent;

public class calculater_ui implements ActionListener { JFrame frame = new JFrame("Calculater"); JPanel panel = new JPanel( new FlowLayout()); JTextArea text = new JTextArea(1,20); JButton but1 = new JButton("1"); JButton but2 = new JButton("2"); JButton but3 = new JButton("3"); JButton but4 = new JButton("4"); JButton but5 = new JButton("5"); JButton but6 = new JButton("6"); JButton but7 = new JButton("7"); JButton but8 = new JButton("8"); JButton but9 = new JButton("9"); JButton but0 = new JButton("0");

JButton butadd = new JButton("+"); JButton butsub = new JButton("-"); JButton butmulti = new JButton("*"); JButton butdiv = new JButton("/"); JButton buteq = new JButton("="); JButton butclear = new JButton("C"); Double number1,number2,result; int add =0,sub=0,multi=0,dive=0;

public void ui()

[Type

but6.addActionListener( this ); but7.addActionListener( this ); but8.addActionListener( this ); but9.addActionListener( this ); but0.addActionListener( this ); butadd.addActionListener( this ); butsub.addActionListener( this ); butmulti.addActionListener( this ); butdiv.addActionListener( this ); buteq.addActionListener( this ); butclear.addActionListener( this );} @Override public void actionPerformed(ActionEvent e) {

Object source = e.getSource();

if (source==butclear) { number1=0.0; number2=0.0; text.setText("");

if (source==but1) { text.append("1"); }

if (source==but2) { text.append("2");

[Type

if (source==but3) { text.append("3");

if (source==but4) { text.append("4");

if (source==but5) { text.append("5");

if (source==but6) { text.append("6");

if (source==but7) { text.append("7");

if (source==but8) { text.append("8");

if (source==but9)

[Type

text.setText(""); add=0; sub=0; multi=1; dive=0;

if (source==butdiv) { number1=number_reader(); text.setText(""); add=0; sub=0; multi=0; dive=1;

if (source==buteq) { number2=number_reader(); if (add>0) { result=number1+number2; text.setText(Double. toString (result));

if (sub>0) { result=number1-number2; text.setText(Double. toString (result));

[Type

if (multi>0) { result=number1*number2; text.setText(Double. toString (result));

if (dive>0) { result=number1/number2; text.setText(Double. toString (result));

public double number_reader() {

Double num1; String s; s=text.getText(); num1=Double. valueOf (s);

return num1;

Na kraju dobijemo završnu aplikaciju. sl.

[Type