I am taking an AP computer programming class and one of the codes I have to write is as follows, could someone please help me and write it because I am quite stuck, thank you:
The Müller-Lyer illusion is caused by an image that consists of two parallel line segments. One line segment looks like an arrow with two heads, and the other line segment looks like an arrow with two tails. Although the line segments are of exactly the same length, they appear to be unequal (see below). Write a graphics program that illustrates this illusion. As the JFrame is resized, the illusion should stay centered horizontally and maintain its position vertically.
Additionally, draw a small dot which is centered in the center of the frame and label the coordinates of the dot below it with text ( i.e. (412, 138) ). As the JFrame is resized, the dot should remain centered with the current coordinates of the center below it.
My code so far:
package q303_starykh_centeredillusion;
import java.awt.*;
import javax.swing.*;
/**
*
* @author matveystarykh
*/
public class Q303_Starykh_CenteredIllusion {
/**
* @param args the command line arguments
*/
Line line = new Line();
public static void main(String[] args) {
// TODO code application logic here
JFrame frame = new JFrame();
frame.setTitle("Colored Grid");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLayout(new GridLayout(1,1));
frame.add(line,BorderLayout.CENTER);
}
public class Line extends JPanel{
public void paintComponent (Graphics g){
super.paintComponent(g);
double x1 = (getWidth() - 0.75 * getWidth())/2;
double x2 = x1 + getWidth() * 0.75;
g.drawLine((int) x1,10, (int) x2, 10);
}
}
}
Matvey
Level 0
Müller-Lyer illusion in Java
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
7 September 2021, 21:27
And you haven't written a single code line on this? Here and now you can show how far you've come, and exactly where you got stuck and why.
Or maybe we should write the whole thing for you?...
I think rather you should do this CodeGym course, and by the end you'll learn how to write programs like this. (I don't know it yet.)
0
Gellert Varga
7 September 2021, 21:33
But if I were a good businessman, I would have asked how much would it be worth to you if I wrote such a program? :-D
0
Matvey
7 September 2021, 23:11
My bad, forgot to add what I had so far.
0
Matvey
7 September 2021, 23:11
Just added my code so far.
0