Opgave 3.1 a

paltryboarpigSoftware and s/w Development

Nov 3, 2013 (4 years and 6 days ago)

76 views

Opgave 3.1 a


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_1a extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_1a fr
ame = new Opgave3_1a();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = ne
w JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent

event) {




Graphics paper = panel.getGraphics();



paper.drawRect(10, 10, 100, 100);





}

}











Opgave 3.1 b


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_1b extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_1b frame = new Opgave3_1b();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public vo
id maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Pres
s me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.drawLine(10, 10, 110, 10);



paper.drawLine(10, 10, 10, 110);



paper.drawLine(10, 110, 1
10, 110);



paper.drawLine(110, 10, 110, 110);





}

}








Opgave 3.2


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_2 extends JFrame implements ActionListener {



private JButton button;


private JPanel pane
l;



public static void main(String args[]) {




Opgave3_2 frame = new Opgave3_2();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentP
ane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addAction
Listener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.drawLine(10, 10, 10, 110);



paper.drawLine(10, 10, 110, 60);



paper.drawLine(10, 110, 110, 60);







}

}









Opgave 3.3


import
java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_3 extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_3 frame = new Opgave3_3();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setP
referredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics pa
per = panel.getGraphics();



paper.drawRect(10, 10, 30, 30);



paper.drawRect(40, 10, 30, 30);



paper.drawRect(70, 10, 30, 30);



paper.drawRect(10, 40, 30, 30);



paper.drawRect(40, 40, 30, 30);



paper.drawRect(70, 40, 30, 30);



paper.drawRect(10, 70,
30, 30);



paper.drawRect(40, 70, 30, 30);



paper.drawRect(70, 70, 30, 30);





}

}
















































Opgave 3.4


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_4 extends JFrame imple
ments ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_4 frame = new Opgave3_4();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.s
how();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




butto
n = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.drawRect(50,90, 200, 100);



paper.drawLine(50,90, 150 , 40);



pape
r.drawLine(250,90 , 150 , 40);



paper.drawRect(75,130,35,60);



paper.drawRect(140,130,80,30);



paper.setColor(Color.yellow);



paper.fillOval(240,30,40,40);





}

}


Opgave 3.5


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public

class Opgave3_5 extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_5 frame = new Opgave3_5();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON
_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.
white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.setColor(Color.black);



paper.
fillRect(10, 10, 30, 30);



paper.setColor(Color.blue);



paper.fillRect(40, 10, 30, 30);



paper.setColor(Color.cyan);



paper.fillRect(70, 10, 30, 30);



paper.setColor(Color.darkGray);



paper.fillRect(100, 10, 30, 30);



paper.setColor(Color.gray);



p
aper.fillRect(10, 40, 30, 30);



paper.setColor(Color.green);



paper.fillRect(40, 40, 30, 30);



paper.setColor(Color.lightGray);



paper.fillRect(70, 40, 30, 30);



paper.setColor(Color.magenta);



paper.fillRect(100, 40, 30, 30);



paper.setColor(Color.
orange);



paper.fillRect(10, 70, 30, 30);



paper.setColor(Color.pink);



paper.fillRect(40, 70, 30, 30);



paper.setColor(Color.red);



paper.fillRect(70, 70, 30, 30);



paper.setColor(Color.white);



paper.fillRect(100, 70, 30, 30);



paper.setColor(Col
or.yellow);



paper.fillRect(10,100, 30, 30);










}

}































Opgave 3.6 a


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opgave3_6a extends JFrame implements ActionListener {



private JButton

button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_6a frame = new Opgave3_6a();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.
add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.setColor(Color.red);



//het tekenen van de x
-
as



paper.drawLine(10, 10, 10, 110);



paper.drawLine(10, 1
0, 5, 15);



paper.drawLine(10, 10, 15, 15);



//het tekenen van de y
-
as



paper.drawLine(10, 110, 110, 110);



paper.drawLine(110, 110, 105, 105);



paper.drawLine(110, 110, 105, 115);



//het tekenen van de neerslag




paper.setColor(Color.blue);




pape
r.drawLine(30, 110, 30, 35);



paper.drawLine(50, 110, 50, 22);



paper.drawLine(70, 110, 70, 50);







}

}
















































Opgave 3.6 b


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Opga
ve3_6b extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_6b frame = new Opgave3_6b();



frame.setSize(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(new Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.getGraphics();



paper.setColor(Color.red);



//het tekenen va
n de x
-
as



paper.drawLine(10, 10, 10, 110);



paper.drawLine(10, 10, 5, 15);



paper.drawLine(10, 10, 15, 15);



//het tekenen van de y
-
as



paper.drawLine(10, 110, 110, 110);



paper.drawLine(110, 110, 105, 105);



paper.drawLine(110, 110, 105, 115);



/
/het tekenen van de neerslag




paper.setColor(Color.blue);




paper.fillRect(30, 35, 10, 75);



paper.fillRect(50, 22, 10, 88);



paper.fillRect(70, 50, 10, 60);







}

}
















































Opgave 3.7


import java.awt.*;

imp
ort java.awt.event.*;

import javax.swing.*;


public class Opgave3_7 extends JFrame implements ActionListener {



private JButton button;


private JPanel panel;



public static void main(String args[]) {




Opgave3_7 frame = new Opgave3_7();



frame.setSize
(400,400);



frame.setDefaultCloseOperation(EXIT_ON_CLOSE);



frame.maakGUI();



frame.show();


}



public void maakGUI() {




Container window = getContentPane();



window.setLayout(new FlowLayout());






panel = new JPanel();



panel.setPreferredSize(ne
w Dimension(300,200));



panel.setBackground(Color.white);



window.add(panel);




button = new JButton("Press me");



window.add(button);



button.addActionListener(this);


}



public void actionPerformed(ActionEvent event) {




Graphics paper = panel.get
Graphics();



paper.setColor(Color.black);



paper.fillOval(10, 10, 180, 180);



paper.setColor(Color.blue);



paper.fillOval(30, 30, 140, 140);



paper.setColor(Color.red);



paper.fillOval(50, 50, 100, 100);



paper.setColor(Color.yellow);



paper.fillOv
al(70, 70, 60, 60);



paper.setColor(Color.black);



paper.fillOval(95, 95, 10, 10);










}

}