import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 {

Similar documents
// autor igre Ivan Programerska sekcija package mine;

SampleApp.java. Page 1

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

FirstSwingFrame.java Page 1 of 1

H212 Introduction to Software Systems Honors

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Based on slides by Prof. Burton Ma

Answer on question #61311, Programming & Computer Science / Java

JLayeredPane. Depth Constants in JLayeredPane

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

Graphical User Interfaces in Java - SWING

Building Java Programs Bonus Slides

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

import javax.swing.*; import java.awt.*; import java.awt.event.*;

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

COMP16121 Sample Code Lecture 1

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

User interfaces and Swing

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Graphical User Interfaces 2

Graphic User Interfaces. - GUI concepts - Swing - AWT

package As7BattleShip;

Dr. Hikmat A. M. AbdelJaber

Final Examination Semester 2 / Year 2011

Building Graphical User Interfaces. GUI Principles

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

University of Cape Town Department of Computer Science Computer Science CSC1017F

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split

PART 23. Java GUI Advanced JList Component. more items.

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Final Examination Semester 2 / Year 2010

Building Graphical User Interfaces. Overview

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

Dr. Hikmat A. M. AbdelJaber

encompass a group of features for building Graphical User Interfaces (GUI).

Layouts and Components Exam

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

GUI Applications. Let s start with a simple Swing application in Java, and then we will look at the same application in Jython. See Listing 16-1.

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

AP CS Unit 11: Graphics and Events

Final Examination Semester 2 / Year 2012

Introduction to the JAVA UI classes Advanced HCI IAT351

/* Write a Program implementing GUI based Calculator using Swing */

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

// Class fully inheritance and Person immutable GUI nun and Gridbag Layout import java.awt.*; import java.awt.event.*; import javax.swing.

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Attempt FOUR questions Marking Scheme Time: 120 mins

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Example: Building a Java GUI

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

Example: Building a Java GUI

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Chapter 12 GUI Basics

RAIK 183H Examination 2 Solution. November 10, 2014

Graphical User Interfaces. Comp 152

Part 3: Graphical User Interface (GUI) & Java Applets

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Swing - JButton. Adding buttons to the main window

Using Several Components

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

PlaniSphere. Creating a plug-in for PlaniSphere.

Chapter 9 Designing Graphical User Interfaces (GUIs)

Graphical User Interface

Programming Languages and Techniques (CIS120)

Programmierpraktikum

RobotPlanning.java Page 1

AnimatedImage.java. Page 1

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Window Interfaces Using Swing Objects

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Swing - JLabel. Adding a text (and HTML) labels to a GUI

Transcription:

import java.awt.color; import java.awt.flowlayout; import java.awt.font; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.joptionpane; import javax.swing.jpanel; import javax.swing.jtextfield; import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 { JFrame frame; JButton d1,d2,d3; JTextField polje, polje2, polje3; JPanel panel,panel2,panel3, panel4,panel5; JMenuBar mb; JMenu menu; JMenuItem uputstva; JMenuItem o_igri; JOptionPane pane ; boolean flag = false; boolean pobeda = false; String urec; String rec_crt=""; String pslova=""; String font=""; char zdrec[]; char crtrec[]; char [] abc = new char[40]; char slovo; public int greske=0; public int k; int o = 0; int poklapanja = 0; Font f = new Font(font,Font.BOLD,20); Peach peach = new Peach();

public static Vjesala2 igra; URL url1 = Vjesala2.class.getResource("u_toku_igre.wav"); AudioClip clip1 = Applet.newAudioClip(url1); URL url2 = Vjesala2.class.getResource("kraj_igre.wav"); AudioClip clip2 = Applet.newAudioClip(url2); URL url3 = Vjesala2.class.getResource("hangingman.wav"); AudioClip clip3 = Applet.newAudioClip(url3); URL url4 = Vjesala2.class.getResource("pobjeda.wav"); AudioClip clip4 = Applet.newAudioClip(url4); public Vjesala2(){ clip1.play(); clip1.loop(); JFrame frame = new JFrame("Vjesala"); frame.setsize(700,500); frame.setresizable(false); pane = new JOptionPane(); mb = new JMenuBar(); mb.setbackground(new Color(245,245,245)); menu = new JMenu("Opcije"); mb.add(menu); uputstva = new JMenuItem("Uputstva"); o_igri = new JMenuItem("O igri"); menu.add(uputstva); menu.add(o_igri); d1 = new JButton("Pogadjaj"); d1.setfont(f); d2 = new JButton("Zadaj"); d2.setfont(f); d3=new JButton("Nova igra"); d3.setfont(f); polje = new JTextField(20); // Tekstualno polje u kojem igrac zadaje rec polje.setfont(f); polje2 = new JTextField(1); // Tekstualno polje u kojem 2igrac unosi slovo koje trazi u zadatoj reci polje2.setfont(f);

polje3 = new JTextField(13); // Tekstualno polje u kojem iznosim poruke igracima polje3.seteditable(false); polje3.setfont(f); panel = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel(new GridLayout(3,2)); panel5 = new JPanel(new GridLayout(0,2)); polje3.settext("iskoristena slova"); d1.addactionlistener(new ActionListener(){ public void actionperformed(actionevent a) { String st = polje2.gettext(); String s = polje.gettext(); st=st.tolowercase(); String d = ""; String pogslova=""; char p [] = st.tochararray(); int brojact = 0; int x = 0; int h=0; pogslova="pokusajte drugo slovo"; if(st.equals("")){ if(s.equals("")){ polje3.settext("prvo zadajte rec"); else // Ispitujem da li se igra po pravilima, da li je zadao rec, // pre nego je pogadjao slovo polje3.settext("unesite neko slovo"); else if(s.equals("")!flag){ polje3.settext("prvo zadajte rec"); else{ for(int i = 0; i < abc.length;i++){ // Ispitujem da li se ponavljaju slova if(abc[i]==p[0]){ h++; x++; greske=greske-k; break; if(h==0){

abc[o]=p[0]; o++; crtrec[i]+ p[0]); poklapanja++; brojact++; x++; //Sta se desava kada pogodi slovo if(brojact==1) greske = greske - (kbrojact); for(int i = 0; i<urec.length();i++){ if(zdrec[i]==p[0]){ crtrec[i*2]=(char) (crtrec[i]- if(brojact>1) greske=greske+1; if(x>brojact){ greske=greske+k; h++; poklapanja=poklapanja-brojact; //Ispitujem da li je ponovljeno slovo bilo u reci if(brojact==0){ greske=greske-k; h++; brojact=0; for(int m = 0; m<rec_crt.length();m++){ d=d+crtrec[m]; //Ispisujem slova na svoje mesto u zadatoj reci polje.settext(d); slovo for(int i = 0; i<urec.length();i++){ if(zdrec[i]!=p[0] ){ //Sta se desava kada pormasi greske++; slovo=p[0]; peach.broj=greske/k; peach.repaint(); if(h>0) polje3.settext(pogslova); // h je indikator da je igrac ponovio slovo, ispisujem to igracu porukum

else{ pslova=pslova+slovo+" "; polje3.settext(pslova); //Detekcija pobede if(poklapanja==k){ pobeda=true; clip1.stop(); clip4.play(); clip4.loop(); polje3.settext("izvukli ste se!"); d1.setenabled(false); d1.settext(""); polje2.seteditable(false); if(greske==k*6){ clip1.stop(); clip2.play(); clip2.loop(); clip3.play(); clip3.loop(); polje3.settext("obeseni ste"); polje2.seteditable(false); //Detekcija poraza polje.settext(urec); d1.setenabled(false); d1.settext(""); polje2.settext(""); ); d2.addactionlistener(new ActionListener(){ public void actionperformed(actionevent a) { String s = polje.gettext(); s= s.tolowercase(); urec = s; rec_crt="";

pslova = ""; k = s.length(); char q = ' '; greske=0; poklapanja=0; abc=new char[40]; flag=true; if(s.equals("")){ polje3.settext("niste zadali rec"); else{ String underline [] = new String[k]; String blank [] = new String [k]; for(int m = 0; m<k;m++){ underline[m]="_"; //zadatu rec ispisujem u _ obliku blank[m]=" "; rec_crt = rec_crt + underline[m] + blank[m]; zdrec = urec.tochararray(); crtrec = rec_crt.tochararray(); for(int i = 0; i<urec.length();i++){ if(zdrec[i]==q){ //Ukoliko to nije 1 rec, ispisujem razmake da bi dobio oblik poklapanja++; // crtrec[i*2]=(char) (crtrec[i]- crtrec[i]+ q); rec_crt = new String(crtrec); polje.settext(rec_crt); polje.setenabled(false); d2.setenabled(false); d2.settext(""); ); d3.addactionlistener(new ActionListener(){ public void actionperformed(actionevent a) { frame.dispose(); igra=new Vjesala2(); // Resetujem igru tako sto otvaram prozor igre iznova peach.tm.stop(); if(!pobeda){ clip1.stop(); clip2.stop();

clip3.stop(); else clip4.stop(); ); o_igri.addactionlistener(new ActionListener(){ public void actionperformed(actionevent arg0) { Programska sekcija :) "); pane.showmessagedialog(null, "Igru napravio: Ivan Bauk @ ); uputstva.addactionlistener(new ActionListener(){ public void actionperformed(actionevent arg0) { pane.showmessagedialog(null, "Igrica osmisljena za 2 igraca, tako sto prvi igrac zadaje rec a drugi pogadja"); ); panel.setlayout(new FlowLayout()); panel2.setlayout(new FlowLayout()); panel.add(d1); panel.add(polje2); panel3.add(polje3); panel2.add(d2); panel2.add(polje); panel2.add(d3); panel4.add(panel); panel4.add(panel3); panel4.add(panel2); panel5.add(peach); panel5.add(panel4); frame.setjmenubar(mb); frame.add(panel5); frame.setvisible(true); frame.setlocationrelativeto(null); frame.setdefaultcloseoperation(jframe.exit_on_close); public static void main(string[] args) { igra = new Vjesala2();

import java.awt.image.bufferedimage; import java.io.ioexception; import javax.imageio.imageio; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Peach extends JPanel implements ActionListener{ Timer tm = new Timer(200,this); BufferedImage image; boolean smjer=false; public int broj=0; private BufferedImage background; private BufferedImage gr1; private BufferedImage gr2; private BufferedImage gr3; private BufferedImage gr4; private BufferedImage gr5; private BufferedImage gr6; private BufferedImage ob1; private BufferedImage ob2; public void paintcomponent(graphics g){ super.paintcomponent(g); try{ gr1 = this.loadimage("/1 greska.png"); gr2 = this.loadimage("/2 greska.png"); gr3 = this.loadimage("/3 greska.png"); gr4 = this.loadimage("/4 greska.png"); gr5 = this.loadimage("/5 greska.png"); gr6 = this.loadimage("/6 greska.png"); ob1 = this.loadimage("/obesen 1.png"); ob2 = this.loadimage("/obesen 2.png"); background = this.loadimage("/pocetak.png"); catch(ioexception e){ e.printstacktrace(); switch (broj){ case 1:g.drawImage(gr1, 0, 0, this); break; case 2: g.drawimage(gr2, 0, 0, this); break; case 3: g.drawimage(gr3, 0, 0, this); break; case 4: g.drawimage(gr4, 0, 0, this); break; case 5: g.drawimage(gr5, 0, 0, this); break; case 6: g.drawimage(gr6, 0, 0, this); tm.start(); break; case 7: g.drawimage(ob1, 0, 0, this); break; case 8:g.drawImage(gr6, 0, 0, this); break; case 9:g.drawImage(ob2, 0, 0, this); break;

default: g.drawimage(background, 0, 0, this); g.dispose(); public void actionperformed(actionevent a) { slike if(broj>=6){ repaint(); tm.start(); broj++; if(broj==10) broj=6; public BufferedImage loadimage(string path) throws IOException{ image = ImageIO.read(getClass().getResource(path)); return image; //putanja do