Advertisement
Guest User

priprema za test

a guest
Mar 26th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 KB | None | 0 0
  1. //film
  2.  
  3. public class Film {
  4.  
  5. public String nazivFilma;
  6. public int godIzdavanja;
  7. public String imeIPrezimeRezisera;
  8. public String glumci[];
  9. public String zanr;
  10. public int brGlumaca;
  11. public int maxBrGlumaca;
  12.  
  13. public Film (String nazivFilma, int godIzdavanja, String imeIPrezimeRezisera, String zanr, int maxBrGlumaca) {
  14. this.nazivFilma=nazivFilma;
  15. this.godIzdavanja=godIzdavanja;
  16. this.imeIPrezimeRezisera=imeIPrezimeRezisera;
  17. this.zanr=zanr;
  18. this.brGlumaca=0;
  19. this.maxBrGlumaca=maxBrGlumaca;
  20. this.glumci=new String[this.maxBrGlumaca];
  21. }
  22.  
  23. public void dodajGlumca(String glumac) {
  24. if(this.brGlumaca<this.maxBrGlumaca) {
  25. this.glumci[this.brGlumaca]=glumac;
  26. this.brGlumaca++;
  27. }
  28. }
  29.  
  30. public void stampaj() {
  31. System.out.println(this.nazivFilma);
  32. System.out.println(this.godIzdavanja);
  33. System.out.println(this.imeIPrezimeRezisera);
  34. for (int i=0;i<brGlumaca;i++) {
  35. System.out.println(this.glumci[i]);
  36. }
  37. System.out.println(this.zanr);
  38.  
  39. }
  40.  
  41.  
  42. }
  43. //node
  44.  
  45.  
  46. public class Node {
  47.  
  48. Film info;
  49. Node next;
  50.  
  51. public Node() {
  52. next=null;
  53. }
  54.  
  55. public Node(Film i) {
  56. info=i;
  57. next=null;
  58. }
  59.  
  60. public Node(Film i, Node n) {
  61. info=i;
  62. next=n;
  63. }
  64.  
  65. public void print() {
  66. info.stampaj();
  67. }
  68.  
  69. public boolean isEqual(Film el) {
  70. return el==info;
  71. }
  72.  
  73.  
  74.  
  75.  
  76. }
  77. //glavna
  78. import javax.swing.JFrame;
  79.  
  80. public class Glavna {
  81.  
  82. public static void main(String[] args) {
  83. // TODO Auto-generated method stub
  84.  
  85. /*Film f=new Film ("Titanik", 1996, "A", "Drama", 2);
  86. Film f1=new Film ("Avengers", 2018, "A", "Action", 2);
  87. f.dodajGlumca("B");
  88. f.dodajGlumca("C");
  89. f1.dodajGlumca("B");
  90. f1.dodajGlumca("C");
  91.  
  92. List l=new List();
  93. l.dodaj(f);
  94. l.dodaj(f1);
  95.  
  96.  
  97. l.prikaziSveFilmove();
  98. l.obrisiZadati("Titanik");
  99. l.prikaziSveFilmove();*/
  100.  
  101. Frejm f= new Frejm();
  102. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  103. f.setVisible(true);
  104.  
  105. }
  106.  
  107. }
  108. //panel dodaj
  109. import javax.swing.JButton;
  110. import javax.swing.JLabel;
  111. import javax.swing.JPanel;
  112. import javax.swing.JTextField;
  113.  
  114. public class PanelDodaj extends JPanel {
  115.  
  116. public JTextField nazivT, godinaT, reziserT, zanrT, brGlumacaT, glumacT;
  117. public JButton dodajD;
  118. public JButton nazadD;
  119. public JButton dodajGlumcaD;
  120. public JButton submitD;
  121.  
  122. public int compW=130;
  123. public int compH=30;
  124. public int offsetW=compW+20;
  125. public int offsetH=compH+10;
  126.  
  127. public PanelDodaj() {
  128. setLayout(null);
  129.  
  130. JLabel nazivL=new JLabel("Naziv filma");
  131. nazivL.setBounds(10, 10, compW, compH);
  132. this.add(nazivL);
  133.  
  134. nazivT=new JTextField();
  135. nazivT.setBounds(nazivL.getX()+offsetW, nazivL.getY(), compW, compH);
  136. this.add(nazivT);
  137.  
  138. JLabel godinaL=new JLabel("Godina izdavanja");
  139. godinaL.setBounds(nazivL.getX(), nazivL.getY()+offsetH, compW, compH);
  140. this.add(godinaL);
  141.  
  142. godinaT=new JTextField();
  143. godinaT.setBounds(godinaL.getX()+offsetW, godinaL.getY(), compW, compH);
  144. this.add(godinaT);
  145.  
  146. JLabel reziserL=new JLabel("Ime i prezime rezisera");
  147. reziserL.setBounds(godinaL.getX(), godinaL.getY()+offsetH, compW, compH);
  148. this.add(reziserL);
  149.  
  150. reziserT=new JTextField();
  151. reziserT.setBounds(reziserL.getX()+offsetW, reziserL.getY(), compW, compH);
  152. this.add(reziserT);
  153.  
  154. JLabel zanrL=new JLabel("Zanr");
  155. zanrL.setBounds(reziserL.getX(), reziserL.getY()+offsetH, compW, compH);
  156. this.add(zanrL);
  157.  
  158. zanrT=new JTextField();
  159. zanrT.setBounds(zanrL.getX()+offsetW, zanrL.getY(), compW, compH);
  160. this.add(zanrT);
  161.  
  162. JLabel brGlumacaL=new JLabel("Broj glumaca");
  163. brGlumacaL.setBounds(zanrL.getX(), zanrL.getY()+offsetH, compW, compH);
  164. this.add(brGlumacaL);
  165.  
  166. brGlumacaT=new JTextField();
  167. brGlumacaT.setBounds(brGlumacaL.getX()+offsetW, brGlumacaL.getY(), compW, compH);
  168. this.add(brGlumacaT);
  169.  
  170. dodajD=new JButton("Dodaj");
  171. dodajD.setBounds(brGlumacaT.getX(), brGlumacaT.getY()+offsetH, compW, compH);
  172. this.add(dodajD);
  173.  
  174. glumacT=new JTextField();
  175. glumacT.setBounds(dodajD.getX(), dodajD.getY()+offsetH, compW, compH);
  176. glumacT.setVisible(false);
  177. this.add(glumacT);
  178.  
  179. dodajGlumcaD=new JButton("Dodaj glumca");
  180. dodajGlumcaD.setBounds(glumacT.getX()+offsetW, glumacT.getY(), compW, compH);
  181. dodajGlumcaD.setVisible(false);
  182. this.add(dodajGlumcaD);
  183.  
  184. submitD=new JButton("Submit");
  185. submitD.setBounds(glumacT.getX()+offsetW, glumacT.getY()*2, compW, compH);
  186. submitD.setVisible(false);
  187. this.add(submitD);
  188.  
  189. nazadD=new JButton("Nazad");
  190. nazadD.setBounds(dodajD.getX(), dodajD.getY()+offsetH*3, compW, compH);
  191. this.add(nazadD);
  192.  
  193.  
  194. }
  195.  
  196. }
  197. //osluskivac menjaj
  198. import java.awt.event.ActionEvent;
  199. import java.awt.event.ActionListener;
  200.  
  201. import javax.swing.*;
  202.  
  203. public class OsluskivacMenjaj implements ActionListener {
  204.  
  205. JPanel prvi;
  206. JPanel drugi;
  207.  
  208. public OsluskivacMenjaj(JPanel prvi, JPanel drugi) {
  209. this.prvi=prvi;
  210. this.drugi=drugi;
  211. }
  212.  
  213. @Override
  214. public void actionPerformed(ActionEvent arg0) {
  215.  
  216. this.prvi.setVisible(false);
  217. this.drugi.setVisible(true);
  218. }
  219.  
  220. }
  221. //frejm
  222. import javax.swing.*;
  223.  
  224. public class Frejm extends JFrame {
  225.  
  226. public Frejm() {
  227. this.setLayout(null);
  228. this.setSize(800,700);
  229.  
  230. PanelPocetni pPocetni=new PanelPocetni();
  231. pPocetni.setVisible(true);
  232. this.add(pPocetni);
  233.  
  234. PanelDodaj pDodaj=new PanelDodaj();
  235. pDodaj.setBounds(0, 0, 800, 700);
  236. pDodaj.setVisible(false);
  237. this.add(pDodaj);
  238.  
  239. OsluskivacMenjaj oM=new OsluskivacMenjaj(pPocetni, pDodaj);
  240. pPocetni.dodajD.addActionListener(oM);
  241.  
  242. OsluskivacMenjaj oM1=new OsluskivacMenjaj(pDodaj, pPocetni);
  243. pDodaj.nazadD.addActionListener(oM1);
  244.  
  245. OsluskivacDodajFilm oDF= new OsluskivacDodajFilm(pDodaj.nazivT, pDodaj.godinaT, pDodaj.reziserT, pDodaj.zanrT, pDodaj.brGlumacaT, pDodaj);
  246. pDodaj.dodajD.addActionListener(oDF);
  247.  
  248.  
  249.  
  250.  
  251. }
  252.  
  253.  
  254.  
  255. }
  256. //osluskivac dodaj film
  257. import java.awt.event.ActionEvent;
  258. import java.awt.event.ActionListener;
  259.  
  260. import javax.swing.*;
  261.  
  262. public class OsluskivacDodajFilm implements ActionListener{
  263. private JTextField nazivT, godinaT, reziserT, zanrT, brGlumacaT;
  264. private PanelDodaj panel;
  265. int brojGlumaca;
  266.  
  267. public OsluskivacDodajFilm (JTextField nT, JTextField gT, JTextField rT, JTextField zT, JTextField bGT, PanelDodaj p) {
  268. nazivT=nT;
  269. godinaT=gT;
  270. reziserT=rT;
  271. zanrT=zT;
  272. brGlumacaT=bGT;
  273. panel=p;
  274. }
  275.  
  276. @Override
  277. public void actionPerformed(ActionEvent e) {
  278. Film f=new Film(nazivT.getText(), Integer.parseInt(godinaT.getText()), reziserT.getText(), zanrT.getText(), Integer.parseInt(brGlumacaT.getText()));
  279.  
  280. brojGlumaca=f.brGlumaca;
  281. f.glumci=new String[brojGlumaca];
  282. OsluskivacDodajGlumca oDG=new OsluskivacDodajGlumca(panel, f);
  283. for (int i=0;i<brojGlumaca;i++) {
  284. panel.dodajGlumcaD.addActionListener(oDG);
  285. }
  286.  
  287. panel.dodajGlumcaD.setVisible(false);
  288. panel.submitD.setVisible(true);
  289.  
  290. nazivT.setText("");
  291. godinaT.setText("");
  292. reziserT.setText("");
  293. zanrT.setText("");
  294. brGlumacaT.setText("");
  295.  
  296. }
  297.  
  298. }
  299. //osluskivac unosa
  300. import java.awt.event.ActionEvent;
  301. import java.awt.event.ActionListener;
  302.  
  303. import javax.swing.*;
  304.  
  305. public class OsluskivacUnosa implements ActionListener{
  306. private JTextField nazivF;
  307. private JTextField reziserF;
  308. private JTextField godF;
  309. private JTextField zanrF;
  310. private Lista l;
  311.  
  312. public OsluskivacUnosa(JTextField naz, JTextField rez, JTextField god, JTextField zan, Lista l) {
  313. nazivF=naz;
  314. reziserF=rez;
  315. godF=god;
  316. zanrF=zan;
  317. this.l=l;
  318. }
  319.  
  320.  
  321. @Override
  322. public void actionPerformed(ActionEvent e) {
  323. // TODO Auto-generated method stub
  324. Film f=new Film(nazivF.getText(), reziserF.getText(), Integer.parseInt(godF.getText()), zanrF.getText());
  325. l.addToHead(f);
  326. /*nazivF.setText("");
  327. reziserF.setText("");
  328. godF.setText("");
  329. zanrF.setText("");*/
  330.  
  331. }
  332.  
  333. }
  334. //osluskivac dodaj glumca
  335. import java.awt.event.ActionEvent;
  336. import java.awt.event.ActionListener;
  337.  
  338. public class OsluskivacDodajGlumca implements ActionListener{
  339.  
  340. PanelDodaj pDodaj;
  341. Film f;
  342. int brojGlumaca;
  343.  
  344. public OsluskivacDodajGlumca(PanelDodaj pD, Film f) {
  345. pDodaj=pD;
  346. this.f=f;
  347. }
  348.  
  349. @Override
  350. public void actionPerformed(ActionEvent e) {
  351.  
  352.  
  353. f.dodajGlumca(pDodaj.glumacT.getText());
  354.  
  355.  
  356.  
  357.  
  358.  
  359. }
  360.  
  361. }
  362. //interfejs
  363.  
  364. public interface Interfejs {
  365.  
  366. public void dodaj(Film f);
  367. public void obrisiZadati(String nazivF);
  368. public void prikaziSveFilmove();
  369.  
  370. }
  371. //list
  372.  
  373. public class List implements Interfejs{
  374.  
  375. Node head, tail;
  376.  
  377. public List() {
  378. head=tail=null;
  379. }
  380.  
  381. public boolean isEmpty() {
  382. return head==null;
  383. }
  384.  
  385. public void dodaj(Film i) {
  386. if (isEmpty()) {
  387. head=tail=new Node(i);
  388. }else {
  389. tail.next=new Node(i);
  390. tail=tail.next;
  391. }
  392. }
  393.  
  394. @Override
  395. public void obrisiZadati(String nazivF) {
  396. Node previous=null;
  397. for(Node tmp=head;tmp!=null;tmp=tmp.next) {
  398. if (tmp.info.nazivFilma==nazivF) {
  399. if(tmp==head) {
  400. head=head.next;
  401. }else {
  402. Node current=previous.next;
  403. previous.next=current.next;
  404. current.next=null;
  405. tmp=previous;
  406. }
  407. }else {
  408. previous=tmp;
  409. }
  410. }
  411. }
  412.  
  413.  
  414.  
  415. @Override
  416. public void prikaziSveFilmove() {
  417. for(Node tmp=head;tmp!=null;tmp=tmp.next) {
  418. tmp.print();
  419. }
  420.  
  421. }
  422.  
  423. public void deleteFromHead() {
  424.  
  425. if (isEmpty()) {
  426. System.out.println("Lista je prazna.");
  427. }else {
  428. if (head==tail) {
  429. head=tail=null;
  430. }else {
  431. head=head.next;
  432. }
  433.  
  434. }
  435. }
  436.  
  437. public void deleteFromTail() {
  438. if(isEmpty()) {
  439. System.out.println("Lista je prazna.");
  440. }else {
  441. if (head==tail) {
  442. head = tail = null;
  443. }else {
  444. for(Node tmp=head;tmp.next!=null;tmp=tmp.next) {
  445. tail=tmp;
  446. }
  447. tail.next=null;
  448. }
  449. }
  450. }
  451.  
  452. }
  453. //panel pocetni
  454. import javax.swing.*;
  455.  
  456. public class PanelPocetni extends JPanel{
  457.  
  458. public JButton dodajD;
  459. public JButton prikaziD;
  460.  
  461. public PanelPocetni() {
  462. setLayout(null);
  463. this.setBounds(0, 0, 800, 700);
  464.  
  465. dodajD=new JButton("Dodaj");
  466. dodajD.setBounds(350, 320, 100, 30);
  467. this.add(dodajD);
  468.  
  469. prikaziD=new JButton("Prikazi");
  470. prikaziD.setBounds(dodajD.getX(), dodajD.getY()+50, 100, 30);
  471. this.add(prikaziD);
  472. }
  473.  
  474. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement