Lab4: Theory + GUI Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
For(int i = 1; i
Domain and Range Increasing and Decreasing x- and y-intercepts
Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
1 C OMP 346 – W INTER 2015 Tutorial # 5. Semaphores for Barrier Sync A barrier is a type of synchronization method. A barrier for a group of threads or.
1 CSC241: Object Oriented Programming Lecture No 21.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 102 Computer Programming II (Lab:
Introduction to Programming Lecture 39. Copy Constructor.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
EC-241 Object-Oriented Programming
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Lab2: Socket Programming Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.
Lab1: File I/O and Streams Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.
Stack buffer overflow.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 19, Friday, October 17.
1 Lecture Today’s Topics Classes –Attribute (variables) –Behaviors (methods) Using methods –How to write methods –How to use methods Scope –Private.
Exam Preparation Spring 2010 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 21, Wednesday, October 22.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Exam Preparation Fall 2008 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Sep 21, 2007 MC Model Checking 2007 Exercises Barbara Jobstmann.
Lecture 16: Multithreaded Programming. public partial class Form1 : Form { Thread ct; Thread rt; public static int circle_sleep = 0; public static int.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Synchronization Producer/Consumer Problem. Synchronization - PC with Semaphores2 Abstract The producer/consumer problem is a classical synchronization.
ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.
Building java programs, chapter 3 Parameters, Methods and Objects.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
1 MIPS Assembly Language Programming CDA 3101 Discussion Section 04.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Experimental vs. Theoretical Probability. Theoretical vs. Experimental Probability Objectives: (1)(2) Essential Questions: (1)(2)
NESTED CLASS. Apa itu nested class ? Nested class is a class defined inside a class, that can be used within the scope of the class in which it is defined.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Animate objects and threads
MSc/ICY Software Workshop , Semester 2
CHEM-E7205 Process Automation and Information Systems: Applications
Introduction to Nursing Theories
Structs versus Classes
Monitoring excercise Marianna Luoma.
MIS 505 Enthusiastic Study/snaptutorial.com
הוראת מיומנויות של עבודה בקבוצה מחקר פעולה
Critter exercise: Snake
null, true, and false are also reserved.
Introduction to Programming
نجاح وفشل المنشآت الصغيرة
Introduction to Programming
Midterm Thursday, in class.
Exam Preparation Spring 2017
class PrintOnetoTen { public static void main(String args[]) {
Web Service.
Template Functions Lecture 9 Fri, Feb 9, 2007.
Outline of the Lectures
2.5 Library of Functions and Piece-Wise Functions
Lecture 11 The Noiseless Coding Theorem (Section 3.4)
CIS 110: Introduction to Computer Programming
Chapter 11 Classes.
CS148 Introduction to Programming II
Exam Preparation Spring 2018
Exam Preparation Spring 2012
Presentation transcript:

Lab4: Theory + GUI Lecturer: Mauro Conti T.A.: Eyüp S. Canlar

Outline Homework Discussion Theoretical Excercise Exercise involving GUI

Exercise 1 class C { private int i = 0; public synchronized void m() { for (int k=0; k< ; k++) i++; for (int k=0; k< ; k++) i--; i++; notifyAll(); } public synchronized void n() throws InterruptedException { if (i<9) wait(); System.out.print(i+" "); }

Exercise 1 class T1 extends Thread { private C c; public T1(C c) {this.c =c;} public void run() { for (int i=0; i<1000; i++) c.m(); } class T2 extends Thread { private C c; public T2(C c) {this.c = c;} public void run() { try { c.n();} catch(InterruptedException e){} }

Exercise 2 class Nodo{ private String info; private Nodo next; public Nodo(String s){info=s;} public void setNext (Nodo n) {next=n;} public static void stampaInfo(Nodo n){ synchronized(n) { If (n!=null) System.out.print(n.info + " \n"); } public synchronized void stampaAncheNext(){ System.out.print(info + " \n"); for(int i=0; i< ; ++i); stampaInfo(next); System.out.print("FINESTAMPA \n"); }

Exercise 2 class T extends Thread { private Nodo n; public T(Nodo n){this.n=n;} public void run(){ n.stampaAncheNext();} } class Esercizio { public static void main(String [] args){ Nodo uno = new Nodo("UNO"), due=new Nodo("DUE"); uno.setNext(due); due.setNext(uno); T[] array = {new T(uno), new T(due)}; int k = (int) (Math.random()*2); array[k].start(); array[(k+1)%2].start(); }

Exercise 3 You have to make a SWING application The application must have three buttons: Start, Pause, Stop When the Start is pressed a thread is created that changes the background color of the application every 30 ms The background color has to be selected randomly (e.g random RGB values) When you press the Pause button you have to suspend the thread. However, it should be still possible to restart the thread When Stop is pressed the thread should be stopped and it should not be possible to restart it again. Chapter 5 contains material about GUIs.

Exercise 3: Creating a GUI Public class Lab4Gui{ …. public void createGUI(){ JFrame guiFrame = new JFrame(Lab 4); Container cp = guiFrame.getContentPane(); JButton start = new JButton(Start); …. cp.add(start); …. guiFrame.pack(); guiFrame.setVisible(); }

Exercise 3: Events Public class Lab4GUI implements ActionListener{ …. public void ActionPerformed(ActionEvent e){ if(/* start is pressed */) /* create thread that changes bgc */ if(/* pause is pressed*/) /* pause bgc changing thread */ if(/* stop is pressed */) /* stop bgc changing thread */ } …. }

Exercise 3: Changing BGC Class ChangeBGCThread extends Thread{ …. public void run(){ int r, g, b …. while(/* some condition */){ /* Get random values for r, g, and b */ Color color = new Color(r, g, b); /* set background color */ …. /* repaint container */ …. } …. }