Skip to content
Snippets Groups Projects
Commit 992bb98a authored by Martin Vatshelle's avatar Martin Vatshelle
Browse files

Code after lecture 9

parent 4e38f901
No related branches found
No related tags found
No related merge requests found
package lecture8_encapsulation;
public record PersonRecord(int age, String name) {
}
public record PersonRecord(int age, String name) {}
......@@ -87,7 +87,6 @@ public class TrafficLightVisualizer extends JPanel{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......
......@@ -4,7 +4,13 @@ public class UsePerson {
public static void main(String[] args) {
PersonRecord pr = new PersonRecord(12, "Per");
System.out.println(pr);
Person p = new Person(17,"Lise");
System.out.println(p);
System.out.println(pr.name());
System.out.println(p.getName());
}
}
......@@ -11,7 +11,7 @@ public class useTrafficLight {
//light.green=true; //not allowed when variable is private
viewer.view(light);
//viewer.run();
viewer.run();
// System.out.println(light.isValid(true, false, true));
// System.out.println(light.isValid(true, true, true));
......
package lecture9;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class MyPanel extends JPanel{
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for(int i=0; i<100; i+=10) {
g.setColor(Color.GREEN);
g.fillOval(2*i,100 ,80,i);
g.setColor(Color.BLACK);
g.drawOval(2*i,100 ,80,i);
}
g.fillOval(200,100 ,70 ,40);
Graphics2D g2 = (Graphics2D)g;
}
}
package lecture9;
import java.util.ArrayList;
import java.util.Iterator;
public class Range implements Iterable<Integer>{
int max;
Range(int max){
this.max = max;
}
ArrayList<Integer> getList(){
ArrayList<Integer> indices = new ArrayList<Integer>();
for(int i=0; i<max; i++) {
indices.add(i);
}
return indices;
}
@Override
public Iterator<Integer> iterator() {
return getList().iterator();
}
static Range range(int max) {
return new Range(max);
}
}
package lecture9;
import javax.swing.JFrame;
public class UseGraphics {
public static void main(String[] args) {
JFrame myFrame = new JFrame("My program");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(300, 300);
MyPanel myPanel = new MyPanel();
myFrame.add(myPanel);
myFrame.setVisible(true);
}
}
package lecture9;
import static lecture9.Range.range;
public class UseRange {
public static void main(String[] args) {
//Range range = new Range(10);
// for(int i:range.getList()) {
// for(int i:new Range(10)) {
// for(int i:Range.range(10)) {
for(int i:range(10)) {
System.out.println(i);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment