// autor igre Ivan Programerska sekcija package mine;

Size: px
Start display at page:

Download "// autor igre Ivan Programerska sekcija package mine;"

Transcription

1 // autor igre Ivan Programerska sekcija package mine; import java.awt.color; import java.awt.flowlayout; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.mouseadapter; import java.awt.event.mouseevent; import java.util.random; import javax.swing.jbutton; import javax.swing.jpanel; import javax.swing.swingutilities; import javax.swing.jframe; import javax.swing.jlabel; public class MineSweeper { boolean flag[][]; boolean iskorisceno[][]; int pobeda=0; int situacija [][]; int koordinate [][]; int randomx; int randomy; int bomba=-1; Slike [][] dugme; JButton restart, izlaz; JPanel panel, popup_panel, panel1,panel2,panel3; JFrame frame, popupframe; JLabel poruka; Slike sl = new Slike(); Random r = new Random(); public static MineSweeper igra; public MineSweeper(){ dugme = new Slike[10][10]; koordinate = new int[11][11]; situacija = new int[10][10]; flag = new boolean[10][10]; iskorisceno = new boolean[10][10]; frame=new JFrame("Minesweeper"); frame.setsize(600, 600); frame.setresizable(false); popupframe = new JFrame(); popupframe.setsize(350, 150);

2 popupframe.setdefaultcloseoperation(jframe.do_nothing_on_close); popupframe.setresizable(false); panel = new JPanel(new GridLayout(9,9)); popup_panel = new JPanel(new GridLayout(3,1)); panel1 = new JPanel(new FlowLayout()); panel2 = new JPanel(new FlowLayout()); panel3 = new JPanel(new FlowLayout()); poruka=new JLabel(); izlaz=new JButton("Izlaz"); restart=new JButton("Restart"); izlaz.addactionlistener(new ActionListener(){ frame.dispose(); popupframe.dispose(); ); restart.addactionlistener(new ActionListener(){ frame.dispose(); popupframe.dispose(); igra = new MineSweeper(); ); panel2.add(poruka); panel3.add(restart); panel3.add(izlaz); popup_panel.add(panel1); popup_panel.add(panel2); popup_panel.add(panel3); popupframe.add(popup_panel); popupframe.setlocationrelativeto(null); for(int y = 1;y<10;y++){ for(int x = 1; x<10;x++){ iskorisceno[x][y]=false; koordinate[x][y]=0; situacija[x][y]=0; flag[x][y]=false; dugme[x][y]=new Slike(); dugmica u igricu panel.add(dugme[x][y]); //ubacivanje polja for(int i = 1; i<10;i++){ randomx=1+r.nextint(9); randomy=1+r.nextint(9); if(!flag[randomx][randomy]){ koordinate[randomx][randomy]=bomba; flag[randomx][randomy]=true; //Definisanje

3 if(koordinate[randomx-1][randomy-1]!=bomba){ koordinate[randomx-1][randomy-1]++; if(koordinate[randomx][randomy-1]!=bomba){ koordinate[randomx][randomy-1]++; if(koordinate[randomx+1][randomy-1]!=bomba){ koordinate[randomx+1][randomy-1]++; if(koordinate[randomx-1][randomy]!=bomba){ koordinate[randomx-1][randomy]++; // odredjivanje koliko je bombi u radiusu if(koordinate[randomx+1][randomy]!=bomba){ koordinate[randomx+1][randomy]++; if(koordinate[randomx-1][randomy+1]!=bomba){ koordinate[randomx-1][randomy+1]++; if(koordinate[randomx][randomy+1]!=bomba){ koordinate[randomx][randomy+1]++; if(koordinate[randomx+1][randomy+1]!=bomba){ koordinate[randomx+1][randomy+1]++; else i--; dugme[1][1].addmouselistener(new MouseAdapter(){ Desniklik(1,1); ); dugme[1][1].addactionlistener(new ActionListener(){ if(situacija[1][1]==1 situacija[1][1]==2){ else{ if(koordinate[1][1]==bomba){ else{ rek(1,1);detekcijapobede(); ); dugme[1][2].addmouselistener(new MouseAdapter(){ Desniklik(1,2); ); dugme[1][2].addactionlistener(new ActionListener(){ if(situacija[1][2]==1 situacija[1][2]==2){

4 else{ if(koordinate[1][2]==bomba){ else { rek(1,2);detekcijapobede(); ); dugme[1][3].addmouselistener(new MouseAdapter(){ Desniklik(1,3); ); dugme[1][3].addactionlistener(new ActionListener(){ if(situacija[1][3]==1 situacija[1][3]==2){ else{ if(koordinate[1][3]==bomba){ else { rek(1,3);detekcijapobede(); ); dugme[1][4].addmouselistener(new MouseAdapter(){ Desniklik(1,4); ); dugme[1][4].addactionlistener(new ActionListener(){ if(situacija[1][4]==1 situacija[1][4]==2){ else{ if(koordinate[1][4]==bomba){ else { rek(1,4);detekcijapobede(); ); dugme[1][5].addmouselistener(new MouseAdapter(){ Desniklik(1,5); ); dugme[1][5].addactionlistener(new ActionListener(){ if(situacija[1][5]==1 situacija[1][5]==2){ else{

5 if(koordinate[1][5]==bomba){ else { rek(1,5);detekcijapobede(); ); dugme[1][6].addmouselistener(new MouseAdapter(){ Desniklik(1,6); ); dugme[1][6].addactionlistener(new ActionListener(){ if(situacija[1][6]==1 situacija[1][6]==2){ else{ if(koordinate[1][6]==bomba){ else { rek(1,6);detekcijapobede(); ); dugme[1][7].addmouselistener(new MouseAdapter(){ Desniklik(1,7); ); dugme[1][7].addactionlistener(new ActionListener(){ if(situacija[1][7]==1 situacija[1][7]==2){ else{ if(koordinate[1][7]==bomba){ else { rek(1,7);detekcijapobede(); ); dugme[1][8].addmouselistener(new MouseAdapter(){ Desniklik(1,8); ); dugme[1][8].addactionlistener(new ActionListener(){ if(situacija[1][8]==1 situacija[1][8]==2){ else{ if(koordinate[1][8]==bomba){

6 else { rek(1,8);detekcijapobede(); ); dugme[1][9].addmouselistener(new MouseAdapter(){ Desniklik(1,9); ); dugme[1][9].addactionlistener(new ActionListener(){ if(situacija[1][9]==1 situacija[1][9]==2){ else{ if(koordinate[1][9]==bomba){ else { rek(1,9);detekcijapobede(); ); dugme[2][1].addmouselistener(new MouseAdapter(){ Desniklik(2,1); ); dugme[2][1].addactionlistener(new ActionListener(){ if(situacija[2][1]==1 situacija[2][1]==2){ else{ if(koordinate[2][1]==bomba){ else { rek(2,1);detekcijapobede(); ); dugme[2][2].addmouselistener(new MouseAdapter(){ Desniklik(2,2); ); dugme[2][2].addactionlistener(new ActionListener(){ if(situacija[2][2]==1 situacija[2][2]==2){ else{ if(koordinate[2][2]==bomba){

7 else { rek(2,2);detekcijapobede(); ); dugme[2][3].addmouselistener(new MouseAdapter(){ Desniklik(2,3); ); dugme[2][3].addactionlistener(new ActionListener(){ if(situacija[2][3]==1 situacija[2][3]==2){ else{ if(koordinate[2][3]==bomba){ else { rek(2,3);detekcijapobede(); ); dugme[2][4].addmouselistener(new MouseAdapter(){ Desniklik(2,4); ); dugme[2][4].addactionlistener(new ActionListener(){ if(situacija[2][4]==1 situacija[2][4]==2){ else{ if(koordinate[2][4]==bomba){ else { rek(2,4);detekcijapobede(); ); dugme[2][5].addmouselistener(new MouseAdapter(){ Desniklik(2,5); ); dugme[2][5].addactionlistener(new ActionListener(){ if(situacija[2][5]==1 situacija[2][5]==2){ else{ if(koordinate[2][5]==bomba){ else {

8 rek(2,5);detekcijapobede(); ); dugme[2][6].addmouselistener(new MouseAdapter(){ Desniklik(2,6); ); dugme[2][6].addactionlistener(new ActionListener(){ if(situacija[2][6]==1 situacija[2][6]==2){ else{ if(koordinate[2][6]==bomba){ else { rek(2,6);detekcijapobede(); ); dugme[2][7].addmouselistener(new MouseAdapter(){ Desniklik(2,7); ); dugme[2][7].addactionlistener(new ActionListener(){ if(situacija[2][7]==1 situacija[2][7]==2){ else{ if(koordinate[2][7]==bomba){ else { rek(2,7);detekcijapobede(); ); dugme[2][8].addmouselistener(new MouseAdapter(){ Desniklik(2,8); ); dugme[2][8].addactionlistener(new ActionListener(){ if(situacija[2][8]==1 situacija[2][8]==2){ else{ if(koordinate[2][8]==bomba){ else { rek(2,8);detekcijapobede();

9 ); dugme[2][9].addmouselistener(new MouseAdapter(){ Desniklik(2,9); ); dugme[2][9].addactionlistener(new ActionListener(){ if(situacija[2][9]==1 situacija[2][9]==2){ else{ if(koordinate[2][9]==bomba){ else { rek(2,9);detekcijapobede(); ); dugme[3][1].addmouselistener(new MouseAdapter(){ Desniklik(3,1); ); dugme[3][1].addactionlistener(new ActionListener(){ if(situacija[3][1]==1 situacija[3][1]==2){ else{ if(koordinate[3][1]==bomba){ else { rek(3,1);detekcijapobede(); ); dugme[3][2].addmouselistener(new MouseAdapter(){ Desniklik(3,2); ); dugme[3][2].addactionlistener(new ActionListener(){ if(situacija[3][2]==1 situacija[3][2]==2){ else{ if(koordinate[3][2]==bomba){ else { rek(3,2);detekcijapobede();

10 ); dugme[3][3].addmouselistener(new MouseAdapter(){ Desniklik(3,3); ); dugme[3][3].addactionlistener(new ActionListener(){ if(situacija[3][3]==1 situacija[3][3]==2){ else{ if(koordinate[3][3]==bomba){ else { rek(3,3);detekcijapobede(); ); dugme[3][4].addmouselistener(new MouseAdapter(){ Desniklik(3,4); ); dugme[3][4].addactionlistener(new ActionListener(){ if(situacija[3][4]==1 situacija[3][4]==2){ else{ if(koordinate[3][4]==bomba){ else { rek(3,4);detekcijapobede(); ); dugme[3][5].addmouselistener(new MouseAdapter(){ Desniklik(3,5); ); dugme[3][5].addactionlistener(new ActionListener(){ if(situacija[3][5]==1 situacija[3][5]==2){ ); else{ if(koordinate[3][5]==bomba){ else { rek(3,5);detekcijapobede();

11 dugme[3][6].addmouselistener(new MouseAdapter(){ Desniklik(3,6); ); dugme[3][6].addactionlistener(new ActionListener(){ if(situacija[3][6]==1 situacija[3][6]==2){ else{ if(koordinate[3][6]==bomba){ else { rek(3,6);detekcijapobede(); ); dugme[3][7].addmouselistener(new MouseAdapter(){ Desniklik(3,7); ); dugme[3][7].addactionlistener(new ActionListener(){ if(situacija[3][7]==1 situacija[3][7]==2){ else{ if(koordinate[3][7]==bomba){ else { rek(3,7);detekcijapobede(); ); dugme[3][8].addmouselistener(new MouseAdapter(){ Desniklik(3,8); ); dugme[3][8].addactionlistener(new ActionListener(){ if(situacija[3][8]==1 situacija[3][8]==2){ else{ if(koordinate[3][8]==bomba){ else { rek(3,8);detekcijapobede(); ); dugme[3][9].addmouselistener(new MouseAdapter(){

12 Desniklik(3,9); ); dugme[3][9].addactionlistener(new ActionListener(){ if(situacija[3][9]==1 situacija[3][9]==2){ else{ if(koordinate[3][9]==bomba){ else { rek(3,9);detekcijapobede(); ); dugme[4][1].addmouselistener(new MouseAdapter(){ Desniklik(4,1); ); dugme[4][1].addactionlistener(new ActionListener(){ if(situacija[4][1]==1 situacija[4][1]==2){ else{ if(koordinate[4][1]==bomba){ else { rek(4,1);detekcijapobede(); ); dugme[4][2].addmouselistener(new MouseAdapter(){ Desniklik(4,2); ); dugme[4][2].addactionlistener(new ActionListener(){ if(situacija[4][2]==1 situacija[4][2]==2){ else{ if(koordinate[4][2]==bomba){ else { rek(4,2);detekcijapobede(); ); dugme[4][3].addmouselistener(new MouseAdapter(){

13 Desniklik(4,3); ); dugme[4][3].addactionlistener(new ActionListener(){ if(situacija[4][3]==1 situacija[4][3]==2){ else{ if(koordinate[4][3]==bomba){ else { rek(4,3);detekcijapobede(); ); dugme[4][4].addmouselistener(new MouseAdapter(){ Desniklik(4,4); ); dugme[4][4].addactionlistener(new ActionListener(){ if(situacija[4][4]==1 situacija[4][4]==2){ else{ if(koordinate[4][4]==bomba){ else { rek(4,4);detekcijapobede(); ); dugme[4][5].addmouselistener(new MouseAdapter(){ Desniklik(4,5); ); dugme[4][5].addactionlistener(new ActionListener(){ if(situacija[4][5]==1 situacija[4][5]==2){ else{ if(koordinate[4][5]==bomba){ else { rek(4,5);detekcijapobede(); ); dugme[4][6].addmouselistener(new MouseAdapter(){

14 Desniklik(4,6); ); dugme[4][6].addactionlistener(new ActionListener(){ if(situacija[4][6]==1 situacija[4][6]==2){ else{ if(koordinate[4][6]==bomba){ else { rek(4,6);detekcijapobede(); ); dugme[4][7].addmouselistener(new MouseAdapter(){ Desniklik(4,7); ); dugme[4][7].addactionlistener(new ActionListener(){ if(situacija[4][7]==1 situacija[4][7]==2){ else{ if(koordinate[4][7]==bomba){ else { rek(4,7);detekcijapobede(); ); dugme[4][8].addmouselistener(new MouseAdapter(){ Desniklik(4,8); ); dugme[4][8].addactionlistener(new ActionListener(){ if(situacija[4][8]==1 situacija[4][8]==2){ else{ if(koordinate[4][8]==bomba){ else { rek(4,8);detekcijapobede(); ); dugme[4][9].addmouselistener(new MouseAdapter(){

15 Desniklik(4,9); ); dugme[4][9].addactionlistener(new ActionListener(){ if(situacija[4][9]==1 situacija[4][9]==2){ else{ if(koordinate[4][9]==bomba){ else { rek(4,9);detekcijapobede(); ); dugme[5][1].addmouselistener(new MouseAdapter(){ Desniklik(5,1); ); dugme[5][1].addactionlistener(new ActionListener(){ if(situacija[5][1]==1 situacija[5][1]==2){ else{ if(koordinate[5][1]==bomba){ else { rek(5,1);detekcijapobede(); ); dugme[5][2].addmouselistener(new MouseAdapter(){ Desniklik(5,2); ); dugme[5][2].addactionlistener(new ActionListener(){ if(situacija[5][2]==1 situacija[5][2]==2){ else{ if(koordinate[5][2]==bomba){ else { rek(5,2);detekcijapobede(); ); dugme[5][3].addmouselistener(new MouseAdapter(){ Desniklik(5,3);

16 ); dugme[5][3].addactionlistener(new ActionListener(){ if(situacija[5][3]==1 situacija[5][3]==2){ else{ if(koordinate[5][3]==bomba){ else { rek(5,3);detekcijapobede(); ); dugme[5][4].addmouselistener(new MouseAdapter(){ Desniklik(5,4); ); dugme[5][4].addactionlistener(new ActionListener(){ if(situacija[5][4]==1 situacija[5][4]==2){ else{ if(koordinate[5][4]==bomba){ else { rek(5,4);detekcijapobede(); ); dugme[5][5].addmouselistener(new MouseAdapter(){ Desniklik(5,5); ); dugme[5][5].addactionlistener(new ActionListener(){ if(situacija[5][5]==1 situacija[5][5]==2){ else{ if(koordinate[5][5]==bomba){ else { rek(5,5);detekcijapobede(); ); dugme[5][6].addmouselistener(new MouseAdapter(){ Desniklik(5,6);

17 ); dugme[5][6].addactionlistener(new ActionListener(){ if(situacija[5][6]==1 situacija[5][6]==2){ else{ if(koordinate[5][6]==bomba){ else { rek(5,6);detekcijapobede(); ); dugme[5][7].addmouselistener(new MouseAdapter(){ Desniklik(5,7); ); dugme[5][7].addactionlistener(new ActionListener(){ if(situacija[5][7]==1 situacija[5][7]==2){ else{ if(koordinate[5][7]==bomba){ else { rek(5,7);detekcijapobede(); ); dugme[5][8].addmouselistener(new MouseAdapter(){ Desniklik(5,8); ); dugme[5][8].addactionlistener(new ActionListener(){ if(situacija[5][8]==1 situacija[5][8]==2){ else{ if(koordinate[5][8]==bomba){ else { rek(5,8);detekcijapobede(); ); dugme[5][9].addmouselistener(new MouseAdapter(){ Desniklik(5,9);

18 ); dugme[5][9].addactionlistener(new ActionListener(){ if(situacija[5][9]==1 situacija[5][9]==2){ else{ if(koordinate[5][9]==bomba){ else { rek(5,9);detekcijapobede(); ); dugme[6][1].addmouselistener(new MouseAdapter(){ Desniklik(6,1); ); dugme[6][1].addactionlistener(new ActionListener(){ if(situacija[6][1]==1 situacija[6][1]==2){ else{ if(koordinate[6][1]==bomba){ else { rek(6,1);detekcijapobede(); ); dugme[6][2].addmouselistener(new MouseAdapter(){ Desniklik(6,2); ); dugme[6][2].addactionlistener(new ActionListener(){ if(situacija[6][2]==1 situacija[6][2]==2){ else{ if(koordinate[6][2]==bomba){ else { rek(6,2);detekcijapobede(); ); dugme[6][3].addmouselistener(new MouseAdapter(){ Desniklik(6,3); );

19 dugme[6][3].addactionlistener(new ActionListener(){ if(situacija[6][3]==1 situacija[6][3]==2){ else{ if(koordinate[6][3]==bomba){ else { rek(6,3);detekcijapobede(); ); dugme[6][4].addmouselistener(new MouseAdapter(){ Desniklik(6,4); ); dugme[6][4].addactionlistener(new ActionListener(){ if(situacija[6][4]==1 situacija[6][4]==2){ else{ if(koordinate[6][4]==bomba){ else { rek(6,4);detekcijapobede(); ); dugme[6][5].addmouselistener(new MouseAdapter(){ Desniklik(6,5); ); dugme[6][5].addactionlistener(new ActionListener(){ if(situacija[6][5]==1 situacija[6][5]==2){ else{ if(koordinate[6][5]==bomba){ else { rek(6,5);detekcijapobede(); ); dugme[6][6].addmouselistener(new MouseAdapter(){ Desniklik(6,6); ); dugme[6][6].addactionlistener(new ActionListener(){

20 if(situacija[6][6]==1 situacija[6][6]==2){ else{ if(koordinate[6][6]==bomba){ else { rek(6,6);detekcijapobede(); ); dugme[6][7].addmouselistener(new MouseAdapter(){ Desniklik(6,7); ); dugme[6][7].addactionlistener(new ActionListener(){ if(situacija[6][7]==1 situacija[6][7]==2){ else{ if(koordinate[6][7]==bomba){ else { rek(6,7);detekcijapobede(); ); dugme[6][8].addmouselistener(new MouseAdapter(){ Desniklik(6,8); ); dugme[6][8].addactionlistener(new ActionListener(){ if(situacija[6][8]==1 situacija[6][8]==2){ else{ if(koordinate[6][8]==bomba){ else { rek(6,8);detekcijapobede(); ); dugme[6][9].addmouselistener(new MouseAdapter(){ Desniklik(6,9); ); dugme[6][9].addactionlistener(new ActionListener(){

21 if(situacija[6][9]==1 situacija[6][9]==2){ else{ if(koordinate[6][9]==bomba){ else { rek(6,9);detekcijapobede(); ); dugme[7][1].addmouselistener(new MouseAdapter(){ Desniklik(7,1); ); dugme[7][1].addactionlistener(new ActionListener(){ if(situacija[7][1]==1 situacija[7][1]==2){ else{ if(koordinate[7][1]==bomba){ else { rek(7,1);detekcijapobede(); ); dugme[7][2].addmouselistener(new MouseAdapter(){ Desniklik(7,2); ); dugme[7][2].addactionlistener(new ActionListener(){ if(situacija[7][2]==1 situacija[7][2]==2){ else{ if(koordinate[7][2]==bomba){ else { rek(7,2);detekcijapobede(); ); dugme[7][3].addmouselistener(new MouseAdapter(){ Desniklik(7,3); ); dugme[7][3].addactionlistener(new ActionListener(){ if(situacija[7][3]==1 situacija[7][3]==2){

22 else{ if(koordinate[7][3]==bomba){ else { rek(7,3);detekcijapobede(); ); dugme[7][4].addmouselistener(new MouseAdapter(){ Desniklik(7,4); ); dugme[7][4].addactionlistener(new ActionListener(){ if(situacija[7][4]==1 situacija[7][4]==2){ else{ if(koordinate[7][4]==bomba){ else { rek(7,4);detekcijapobede(); ); dugme[7][5].addmouselistener(new MouseAdapter(){ Desniklik(7,5); ); dugme[7][5].addactionlistener(new ActionListener(){ if(situacija[7][5]==1 situacija[7][5]==2){ else{ if(koordinate[7][5]==bomba){ else { rek(7,5);detekcijapobede(); ); dugme[7][6].addmouselistener(new MouseAdapter(){ Desniklik(7,6); ); dugme[7][6].addactionlistener(new ActionListener(){ if(situacija[7][6]==1 situacija[7][6]==2){

23 else{ if(koordinate[7][6]==bomba){ else{ rek(7,6);detekcijapobede(); ); dugme[7][7].addmouselistener(new MouseAdapter(){ Desniklik(7,7); ); dugme[7][7].addactionlistener(new ActionListener(){ if(situacija[7][7]==1 situacija[7][7]==2){ else{ if(koordinate[7][7]==bomba){ else { rek(7,7);detekcijapobede(); ); dugme[7][8].addmouselistener(new MouseAdapter(){ Desniklik(7,8); ); dugme[7][8].addactionlistener(new ActionListener(){ if(situacija[7][8]==1 situacija[7][8]==2){ else{ if(koordinate[7][8]==bomba){ else { rek(7,8);detekcijapobede(); ); dugme[7][9].addmouselistener(new MouseAdapter(){ Desniklik(7,9); ); dugme[7][9].addactionlistener(new ActionListener(){ if(situacija[7][9]==1 situacija[7][9]==2){

24 else{ if(koordinate[7][9]==bomba){ else { rek(7,9);detekcijapobede(); ); dugme[8][1].addmouselistener(new MouseAdapter(){ Desniklik(8,1); ); dugme[8][1].addactionlistener(new ActionListener(){ if(situacija[8][1]==1 situacija[8][1]==2){ else{ if(koordinate[8][1]==bomba){ else { rek(8,1);detekcijapobede(); ); dugme[8][2].addmouselistener(new MouseAdapter(){ Desniklik(8,2); ); dugme[8][2].addactionlistener(new ActionListener(){ if(situacija[8][2]==1 situacija[8][2]==2){ else{ if(koordinate[8][2]==bomba){ else { rek(8,2);detekcijapobede(); ); dugme[8][3].addmouselistener(new MouseAdapter(){ Desniklik(8,3); ); dugme[8][3].addactionlistener(new ActionListener(){ if(situacija[8][3]==1 situacija[8][3]==2){

25 else{ if(koordinate[8][3]==bomba){ else { rek(8,3);detekcijapobede(); ); dugme[8][4].addmouselistener(new MouseAdapter(){ Desniklik(8,4); ); dugme[8][4].addactionlistener(new ActionListener(){ if(situacija[8][4]==1 situacija[8][4]==2){ else{ if(koordinate[8][4]==bomba){ else { rek(8,4);detekcijapobede(); ); dugme[8][5].addmouselistener(new MouseAdapter(){ Desniklik(8,5); ); dugme[8][5].addactionlistener(new ActionListener(){ if(situacija[8][5]==1 situacija[8][5]==2){ else{ if(koordinate[8][5]==bomba){ else { rek(8,5);detekcijapobede(); ); dugme[8][6].addmouselistener(new MouseAdapter(){ Desniklik(8,6); ); dugme[8][6].addactionlistener(new ActionListener(){ if(situacija[8][6]==1 situacija[8][6]==2){ else{ if(koordinate[8][6]==bomba){

26 else { rek(8,6);detekcijapobede(); ); dugme[8][7].addmouselistener(new MouseAdapter(){ Desniklik(8,7); ); dugme[8][7].addactionlistener(new ActionListener(){ if(situacija[8][7]==1 situacija[8][7]==2){ else{ if(koordinate[8][7]==bomba){ else { rek(8,7);detekcijapobede(); ); dugme[8][8].addmouselistener(new MouseAdapter(){ Desniklik(8,8); ); dugme[8][8].addactionlistener(new ActionListener(){ if(situacija[8][8]==1 situacija[8][8]==2){ else{ if(koordinate[8][8]==bomba){ else { rek(8,8);detekcijapobede(); ); dugme[8][9].addmouselistener(new MouseAdapter(){ Desniklik(8,9); ); dugme[8][9].addactionlistener(new ActionListener(){ if(situacija[8][9]==1 situacija[8][9]==2){ else{ if(koordinate[8][9]==bomba){

27 else { rek(8,9);detekcijapobede(); ); dugme[9][1].addmouselistener(new MouseAdapter(){ Desniklik(9,1); ); dugme[9][1].addactionlistener(new ActionListener(){ if(situacija[9][1]==1 situacija[9][1]==2){ else{ if(koordinate[9][1]==bomba){ else { rek(9,1);detekcijapobede(); ); dugme[9][2].addmouselistener(new MouseAdapter(){ Desniklik(9,2); ); dugme[9][2].addactionlistener(new ActionListener(){ if(situacija[9][2]==1 situacija[9][2]==2){ else{ if(koordinate[9][2]==bomba){ else { rek(9,2);detekcijapobede(); ); dugme[9][3].addmouselistener(new MouseAdapter(){ Desniklik(9,3); ); dugme[9][3].addactionlistener(new ActionListener(){ if(situacija[9][3]==1 situacija[9][3]==2){ else{ if(koordinate[9][3]==bomba){ else {

28 rek(9,3);detekcijapobede(); ); dugme[9][4].addmouselistener(new MouseAdapter(){ Desniklik(9,4); ); dugme[9][4].addactionlistener(new ActionListener(){ if(situacija[9][4]==1 situacija[9][4]==2){ else{ if(koordinate[9][4]==bomba){ else { rek(9,4);detekcijapobede(); ); dugme[9][5].addmouselistener(new MouseAdapter(){ Desniklik(9,5); ); dugme[9][5].addactionlistener(new ActionListener(){ if(situacija[9][5]==1 situacija[9][5]==2){ else{ if(koordinate[9][5]==bomba){ else { rek(9,5);detekcijapobede(); ); dugme[9][6].addmouselistener(new MouseAdapter(){ Desniklik(9,6); ); dugme[9][6].addactionlistener(new ActionListener(){ if(situacija[9][6]==1 situacija[9][6]==2){ else{ if(koordinate[9][6]==bomba){ else { rek(9,6);detekcijapobede();

29 ); dugme[9][7].addmouselistener(new MouseAdapter(){ Desniklik(9,7); ); dugme[9][7].addactionlistener(new ActionListener(){ if(situacija[9][7]==1 situacija[9][7]==2){ else{ if(koordinate[9][7]==bomba){ else { rek(9,7);detekcijapobede(); ); dugme[9][8].addmouselistener(new MouseAdapter(){ Desniklik(9,8); ); dugme[9][8].addactionlistener(new ActionListener(){ if(situacija[9][8]==1 situacija[9][8]==2){ else{ if(koordinate[9][8]==bomba){ else { rek(9,8);detekcijapobede(); ); dugme[9][9].addmouselistener(new MouseAdapter(){ Desniklik(9,9); ); dugme[9][9].addactionlistener(new ActionListener(){ if(situacija[9][9]==1 situacija[9][9]==2){ else{ if(koordinate[9][9]==bomba){ else { rek(9,9);detekcijapobede();

30 ); frame.add(panel); frame.setlocationrelativeto(null); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); public void DetekcijaPoraza(){ for(int y = 1;y<10;y++){ for(int x = 1; x<10;x++){ if(koordinate[x][y]==bomba){ if(dugme[x][y].broj==1){ dugme[x][y].broj=0; dugme[x][y].boom=true;dugme[x][y].repaint(); dugme[x][y].boom=true;dugme[x][y].repaint(); popupframe.setvisible(true);poruka.settext("naisli ste na bombu!"); frame.setenabled(false); public void DetekcijaPobede(){ if(pobeda==72){ popupframe.setvisible(true);poruka.settext("uspesno ste izbegli bombe!"); frame.setenabled(false); public void Desniklik(int x, int y){ situacija[x][y]++; dugme[x][y].broj=situacija[x][y]; if(!iskorisceno[x][y]){ switch(situacija[x][y]){ case 1:;break; case 2:dugme[x][y].setText("?");break; default : situacija[x][y]=0;dugme[x][y].settext("");break; public static void main(string [] args){ igra = new MineSweeper(); public void rek(int x, int y){ if(situacija[x][y]==1)return; iskorisceno[x][y]=true; pobeda++; if(koordinate[x][y]==bomba)return;

31 if(koordinate[x][y]>0){ String radiusbombi = Integer.toString(koordinate[x][y]); dugme[x][y].settext(radiusbombi); dugme[x][y].setenabled(false); return; if (koordinate[x][y]==0)dugme[x][y].setenabled(false); int i = x-1; int j; boolean flagx=false; boolean flagy=false; while (i>0 && i<10 && i<=x+1){ flagx=true; j = y-1; while (j>0 && j<10 && j<=y+1){ flagy=true; if(!(i==x && j==y)&&(!iskorisceno[i][j]))rek(i,j); j++; if (!flagy){ j=y+1; while (j>0 && j<10 && j>=y-1){ if(!(i==x && j==y)&&(!iskorisceno[i][j]))rek(i,j); j--; i++; i=x+1; while (!flagx && i>0 && i<10 && i>=x-1){ j = y-1; while (j>0 && j<10 && j<=y+1){ flagy=true; if(!(i==x && j==y)&&(!iskorisceno[i][j]))rek(i,j); j++; if (!flagy){ j=y+1; while (j>0 && j<10 && j>=y-1){ if(!(i==x && j==y)&&(!iskorisceno[i][j]))rek(i,j); j--; i--;

32 package mine; import java.awt.image.bufferedimage; import java.io.ioexception; import javax.imageio.imageio; import java.awt.*; import javax.swing.*; public class Slike extends JButton{ BufferedImage image; public int broj; public boolean BOOM=false; private BufferedImage zastavica; private BufferedImage kraj; public void paintcomponent(graphics g){ super.paintcomponent(g); try{ zastavica = this.loadimage("zastavica.png"); kraj = this.loadimage("boom.png"); catch(exception e){ e.printstacktrace(); switch (broj){ case 1 :g.drawimage(zastavica, 20, 20, null);break; case 2 :g.dispose();break; default:broj=0;;break; if(boom)g.drawimage(kraj,20,20,null); slike public BufferedImage loadimage(string path) throws IOException{ image = ImageIO.read(getClass().getResource(path)); return image; //putanja do

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

import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 { 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;

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

SampleApp.java. Page 1

SampleApp.java. Page 1 SampleApp.java 1 package msoe.se2030.sequence; 2 3 /** 4 * This app creates a UI and processes data 5 * @author hornick 6 */ 7 public class SampleApp { 8 private UserInterface ui; // the UI for this program

More information

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

Answer on question #61311, Programming & Computer Science / Java Answer on question #61311, Programming & Computer Science / Java JSP JSF for completion Once the user starts the thread by clicking a button, the program must choose a random image out of an image array,

More information

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

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

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

APPENDIX. public void cekroot() { System.out.println(nilai root : +root.data); } APPENDIX CLASS NODE AS TREE OBJECT public class Node public int data; public Node left; public Node right; public Node parent; public Node(int i) data=i; PROCEDURE BUILDING TREE public class Tree public

More information

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

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

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

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } } 9.12) public interface Filter boolean accept(object x); Describes any class whose objects can measure other objects. public interface Measurer double measure(object anobject); This program tests the use

More information

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.

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. Page 1 of 16 SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2005 FINAL EXAMINATION 9am to 12noon, 19 DECEMBER 2005 Instructor: Alan McLeod

More information

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. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod If the

More information

COMP16121 Sample Code Lecture 1

COMP16121 Sample Code Lecture 1 COMP16121 Sample Code Lecture 1 Sean Bechhofer, University of Manchester, Manchester, UK sean.bechhofer@manchester.ac.uk 1 SimpleFrame 1 import javax.swing.jframe; 2 3 public class SimpleFrame { 4 5 /*

More information

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

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the

More information

Final Examination Semester 2 / Year 2010

Final Examination Semester 2 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2010 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student

More information

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

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 List of Slides 1 Title 2 Chapter 13: Graphical user interfaces 3 Chapter aims 4 Section 2: Example:Hello world with a GUI 5 Aim 6 Hello world with a GUI 7 Hello world with a GUI 8 Package: java.awt and

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.

More information

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

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t; 1 AppBisect > PrBisect > class Punct public class Punct { double x,y; public Punct(double x, double y) { this.x = x; this.y = y; public void setx(double x) { this.x = x; public double getx() { return x;

More information

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. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod

More information

Final Examination Semester 2 / Year 2011

Final Examination Semester 2 / Year 2011 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE COURSE CODE TIME DEPARTMENT LECTURER : JAVA PROGRAMMING : PROG1114 : 2 1/2 HOURS : COMPUTER SCIENCE : LIM PEI GEOK Student

More information

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. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:

More information

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. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

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

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split DAFTAR LAMPIRAN Source Code Java Aplikasi Keyword to Image Renamer Split Source Code Menu Utama package spin_text; import java.awt.color; import java.awt.event.actionevent; import java.awt.event.actionlistener;

More information

AnimatedImage.java. Page 1

AnimatedImage.java. Page 1 1 import javax.swing.japplet; 2 import javax.swing.jbutton; 3 import javax.swing.jpanel; 4 import javax.swing.jcombobox; 5 import javax.swing.jlabel; 6 import javax.swing.imageicon; 7 import javax.swing.swingutilities;

More information

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. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2007 FINAL EXAMINATION 7pm to 10pm, 10 DECEMBER 2007, Jeffery Hall Instructor: Alan McLeod If the

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

Building Java Programs Bonus Slides

Building Java Programs Bonus Slides Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog

More information

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

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

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

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components

More information

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. Solution HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2007 FINAL EXAMINATION 7pm to 10pm, 10 DECEMBER 2007, Jeffery Hall Instructor: Alan McLeod

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

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

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like: OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too

More information

package As7BattleShip;

package As7BattleShip; package As7BattleShip; Program: BattleshipBoard.java Author: Kevin Nider Date: 11/18/12 Description: Assignment 7: Runs the battleship game Input: ship placement board files and computer player type Output:

More information

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

Swing - JTextField. Adding a text field to the main window (with tooltips and all) Swing - JTextField Adding a text field to the main window (with tooltips and all) Prerequisites - before this lecture You should have seen: The lecture on JFrame The lecture on JButton Including having

More information

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.

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. Page 1 of 16 HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2005 FINAL EXAMINATION 9am to 12noon, 19 DECEMBER 2005 Instructor: Alan McLeod If

More information

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. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2008 FINAL EXAMINATION 7pm to 10pm, 17 DECEMBER 2008, Grant Hall Instructor: Alan McLeod

More information

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

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

More information

PlaniSphere. Creating a plug-in for PlaniSphere.

PlaniSphere. Creating a plug-in for PlaniSphere. Creating a plug-in for PlaniSphere Creating a plug-in requires a developer to implement SpatialPlugin and SpatialPluginFrame interfaces (see Figure 1). The SpatialPlugin interface defines methods that

More information

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.

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. GUI Applications The C implementation of Python comes with Tkinter for writing Graphical User Interfaces (GUIs). The GUI toolkit that you get automatically with Jython is Swing, which is included with

More information

JFrame & JLabel. By Iqtidar Ali

JFrame & JLabel. By Iqtidar Ali JFrame & JLabel By Iqtidar Ali JFrame & its Features JFrame is a window with border, title and buttons. The component added to frame are referred to as its contents & are managed by the content pane. To

More information

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. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2010 FINAL EXAMINATION 11 DECEMBER 2010, 9am SOLUTION HAND IN Answers Are Recorded on Question Paper Instructor: Alan McLeod If the instructor

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

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. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2009 FINAL EXAMINATION 14 DECEMBER 2009 Instructor: Alan McLeod If the instructor is unavailable

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 25 17/01/13 11:45 Swing Graphical User Interface (GUI) 2 of 25 17/01/13 11:45 Graphical

More information

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

Swing - JLabel. Adding a text (and HTML) labels to a GUI Swing - JLabel Adding a text (and HTML) labels to a GUI Prerequisites - before this lecture You should have seen: The lecture on JFrame The lecture on JButton The lectuer on JTextField Including having

More information

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) TTTK1143 - Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) Topic: JApplet and ContentPane. 1. Complete the following class to create a Java Applet whose pane s background color is

More information

Graphical User Interfaces in Java - SWING

Graphical User Interfaces in Java - SWING Graphical User Interfaces in Java - SWING Graphical User Interfaces (GUI) Each graphical component that the user can see on the screen corresponds to an object of a class Component: Window Button Menu...

More information

Final Examination Semester 2 / Year 2012

Final Examination Semester 2 / Year 2012 Final Examination Semester 2 / Year 2012 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student s ID : Batch No. : Notes to candidates:

More information

Java Programming Summer 2008 LAB. Thursday 8/21/2008

Java Programming Summer 2008 LAB. Thursday 8/21/2008 LAB Thursday 8/21/2008 Design and implement the program that contains a timer. When the program starts, the timer shows 00:00:00. When we click the Start button, the timer starts. When we click the Stop

More information

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

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

More information

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

encompass a group of features for building Graphical User Interfaces (GUI). Java GUI (intro) JFC Java Foundation Classes encompass a group of features for building Graphical User Interfaces (GUI). javax.swing.* used for building GUIs. Some basic functionality is already there

More information

Clasa frsin.java: import java.awt.*; import javax.swing.*;

Clasa frsin.java: import java.awt.*; import javax.swing.*; 1 Clasa frsin.java: import java.awt.*; import javax.swing.*; public class frsin extends JFrame { private sin2d jpanel1 = new sin2d(); private JCheckBox cbcreion = new JCheckBox(); private JCheckBox cbfond

More information

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

protected void printserial() { System.out.println(> NO. + this.serialno); this.serialno++; } NumberedTicketGenerator.java package j2.exam.ex01; public abstract class NumberedTicketGenerator { protected int serialno; public NumberedTicketGenerator() { super(); this.serialno = 1000; public void

More information

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/

More information

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides

More information

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. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CMPE212, FALL TERM, 2012 FINAL EXAMINATION 18 December 2012, 2pm Instructor: Alan McLeod If the instructor is unavailable

More information

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

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); } A Calculator Project This will be our first exposure to building a Graphical User Interface (GUI) in Java The functions of the calculator are self-evident The Calculator class creates a UserInterface Class

More information

Swing Programming Example Number 2

Swing Programming Example Number 2 1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

CSCI 201L Midterm Written Summer % of course grade

CSCI 201L Midterm Written Summer % of course grade CSCI 201L Summer 2016 10% of course grade 1. Abstract Classes and Interfaces Give two differences between an interface and an abstract class in which all of the methods are abstract. (0.5% + 0.5%) 2. Serialization

More information

Chapter 9 Designing Graphical User Interfaces (GUIs)

Chapter 9 Designing Graphical User Interfaces (GUIs) Chapter 9 Designing Graphical User Interfaces (GUIs) Overview The basics of GUIs in Java A tour of Java GUI libraries Containers and components Swing: the full picture Layout managers Understanding events

More information

Lecture 9. Lecture

Lecture 9. Lecture Layout Components MVC Design PaCern GUI Programming Observer Design PaCern D0010E Lecture 8 - Håkan Jonsson 1 Lecture 8 - Håkan Jonsson 2 Lecture 8 - Håkan Jonsson 3 1 1. GUI programming In the beginning,

More information

Chapter Nine: Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved.

Chapter Nine: Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Chapter Nine: Interfaces and Polymorphism Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how

More information

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

Introduction This assignment will ask that you write a simple graphical user interface (GUI). Computing and Information Systems/Creative Computing University of London International Programmes 2910220: Graphical Object-Oriented and Internet programming in Java Coursework one 2011-12 Introduction

More information

3/7/2012. Chapter Nine: Interfaces and Polymorphism. Chapter Goals

3/7/2012. Chapter Nine: Interfaces and Polymorphism. Chapter Goals Chapter Nine: Interfaces and Polymorphism Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how

More information

10/27/2011. Chapter Goals

10/27/2011. Chapter Goals Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how interfaces can be used to decouple classes

More information

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid Systems Programming Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid Leganés, 21st of March, 2014. Duration: 75 min. Full

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 32 April 9, 2018 Swing I: Drawing and Event Handling Chapter 29 HW8: Spellchecker Available on the web site Due: Tuesday! Announcements Parsing, working

More information

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

import javax.swing.*; import java.awt.*; import java.awt.event.*; I need to be walked through with why the stocks are being recognized "half way." They will print out in the console but won't be recognized by certain code. Every line of code seems to look right and that's

More information

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324 The Islamic University Gaza Department of Electrical & Computer Engineering Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324 Instructor: Dipl.-Ing. Abdelnasser Abdelhadi Date: 31.03.2013

More information

CHAPTER 8 INFERENCE. The concept of Inference would be explained in the following chapter, as the CTBN

CHAPTER 8 INFERENCE. The concept of Inference would be explained in the following chapter, as the CTBN CHAPTER 8 INFERENCE The concept of Inference would be explained in the following chapter, as the CTBN framework has already been detailed on. The chapter begins by answering the most asked queries and

More information

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

JRadioButton account_type_radio_button2 = new JRadioButton(Current); ButtonGroup account_type_button_group = new ButtonGroup(); Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button

More information

Building a Java First-Person Shooter

Building a Java First-Person Shooter Building a Java First-Person Shooter Episode 4 How Rendering Works [Last updated 5/02/2017] URL https://www.youtube.com/watch?v=6doiju7--jg&index=5&list=pl656dade0da25adbb Objectives This is a very short

More information

Graphical User Interface

Graphical User Interface Lecture 10 Graphical User Interface An introduction Sahand Sadjadee sahand.sadjadee@liu.se Programming Fundamentals 725G61 http://www.ida.liu.se/~725g61/ Department of Computer and Information Science

More information

CS 335 Graphics and Multimedia. Image Manipulation

CS 335 Graphics and Multimedia. Image Manipulation CS 335 Graphics and Multimedia Image Manipulation Image Manipulation Independent pixels: image subtraction image averaging grey level mapping thresholding Neighborhoods of pixels: filtering, convolution,

More information

CSCI 201L Midterm Written Fall % of course grade

CSCI 201L Midterm Written Fall % of course grade CSCI 201L Midterm Written Fall 2015 10% of course grade 1. Inheritance Answer the following questions about inheritance. a. Does Java allow overloading, overriding, and redefining of methods? (0.5%) b.

More information

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

/* Write a Program implementing GUI based Calculator using Swing */ /* Write a Program implementing GUI based Calculator using Swing */ import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*; public class Calculator extends JFrame

More information

State Application Using MVC

State Application Using MVC State Application Using MVC 1. Getting ed: Stories and GUI Sketch This example illustrates how applications can be thought of as passing through different states. The code given shows a very useful way

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

RobotPlanning.java Page 1

RobotPlanning.java Page 1 RobotPlanning.java Page 1 import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; * * RobotPlanning - 1030 GUI Demonstration.

More information

Swing - JButton. Adding buttons to the main window

Swing - JButton. Adding buttons to the main window Swing - JButton Adding buttons to the main window An empty JFrame is not very useful // In some GUI class: window = new JFrame("Window example"); window.setsize(800,600); window.setdefaultcloseoperation(jframe.exit_on_close);

More information

STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket;

STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket; STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket; //Membuat Kelas public class namakelas //Metode Utama public static void main(string[] args) perintah-perintah;... LATIHAN

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

Java, Swing, and Eclipse: The Calculator Lab.

Java, Swing, and Eclipse: The Calculator Lab. Java, Swing, and Eclipse: The Calculator Lab. ENGI 5895. Winter 2014 January 13, 2014 1 A very simple application (SomeimageswerepreparedwithanearlierversionofEclipseandmaynotlookexactlyasthey would with

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

More information

ว ฒนพงศ ส ทธภ กด Java Programming ( )

ว ฒนพงศ ส ทธภ กด Java Programming ( ) ว ฒนพงศ ส ทธภ กด Java Programming (254372 ) Basic GUI - Frame(new Windows) - Component - popup - addcomponentlistener - addmouselistener - Eclipse plugin for gui(windows Builder) import javax.swing.jframe;

More information

COMP16121 Notes on Mock Exam Questions

COMP16121 Notes on Mock Exam Questions COMP16121 Notes on Mock Exam Questions December 2016 Mock Exam Attached you will find a Mock multiple choice question (MCQ) exam for COMP16121, to assist you in preparing for the actual COMP16121 MCQ Exam

More information

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. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, WINTER TERM, 2012 FINAL EXAMINATION 9am to 12pm, 26 APRIL 2012 Instructor: Alan McLeod If the instructor is

More information

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

An array is a type of variable that is able to hold more than one piece of information under a single variable name. Arrays An array is a type of variable that is able to hold more than one piece of information under a single variable name. Basically you are sub-dividing a memory box into many numbered slots that can

More information

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

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb HAND IN Answers recorded on Examination paper This examination is THREE HOURS

More information

Chapter 9 Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 9 Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 9 Interfaces and Polymorphism Chapter Goals To be able to declare and use interface types To understand the concept of polymorphism To appreciate how interfaces can be used to decouple classes

More information

INSTITUTO POLITÉCNICO NACIONAL ESCUELA SUPERIOR DE CÓMPUTO

INSTITUTO POLITÉCNICO NACIONAL ESCUELA SUPERIOR DE CÓMPUTO INSTITUTO POLITÉCNICO NACIONAL ESCUELA SUPERIOR DE CÓMPUTO Cryptography Practice 1,2,3 By: Raúl Emmanuel Delgado Díaz de León Professor: M. en C. NIDIA ASUNCIÓN CORTEZ DUARTE February2015 Index Contenido

More information

Building Graphical User Interfaces. GUI Principles

Building Graphical User Interfaces. GUI Principles Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting

More information

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. QUEEN'S UNIVERSIY SCHOOL O COMPUING CMPE212, ALL ERM, 2011 INAL EXAMINAION 15 December 2011, 2pm, Grant Hall Instructor: Alan McLeod HAND IN Answers Are Recorded on Question Paper SOLUION If the instructor

More information

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

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics 1 Collections (from the Java tutorial)* A collection (sometimes called a container) is simply an object that

More information

CompSci 230 S Programming Techniques. Basic GUI Components

CompSci 230 S Programming Techniques. Basic GUI Components CompSci 230 S1 2017 Programming Techniques Basic GUI Components Agenda Agenda Basic GUI Programming Concepts Graphical User Interface (GUI) Simple GUI-based Input/Output JFrame, JPanel & JLabel Using Layout

More information

Lampiran A. SOURCE CODE PROGRAM

Lampiran A. SOURCE CODE PROGRAM A-1 Lampiran A. SOURCE CODE PROGRAM Frame Utama package FrameDesign; import ArithmeticSkripsi.ArithmeticCompress; import ArithmeticSkripsi.ArithmeticDecompress; import Deflate.DeflateContoh; import java.io.file;

More information

Client-side GUI. A simple Swing-gui for searching for proudcts

Client-side GUI. A simple Swing-gui for searching for proudcts Client-side GUI A simple Swing-gui for searching for proudcts Working from a sketch to a rough GUI We make a list of the features / requirements We ll then start with a sketch of how a GUI for searching

More information