Muller-Lyer Illusion GUI

Arman Majumder 0 Tallied Votes 1K Views Share

A simple program that displays the Muller-Lyer Illusion. Also tests the ability to draw simple figures using the Paint Component function.

// Arman Majumder
// Muller-Lyer Illusion GUI

   import javax.swing.*;
   import java.awt.*;
   import java.awt.event.*;
       
    public class MullerLyer extends JPanel
   {
       public MullerLyer(Color backColor)
      {
         setBackground(backColor);
      }
      
       public void paintComponent(Graphics g)
      {
         super.paintComponent(g);
         int x = getWidth() / 2 - 60;
         int y = getHeight() / 2;     
      	
         g.setColor(Color.red);
         g.drawLine(10, 10, 40, 10);
         g.drawLine(14, 14, 10, 10);
         g.drawLine(14, 06, 10, 10);
         g.drawLine(36, 14, 40, 10);
         g.drawLine(36, 06, 40, 10);
         
      	
         g.setColor(Color.green);
         g.drawLine(10, 40, 40, 40);
         g.drawLine(06, 44, 10, 40);
         g.drawLine(06, 36, 10, 40);
         g.drawLine(44, 44, 40, 40);
         g.drawLine(44, 36, 40, 40);
         
         g.setColor(Color.blue);
         g.drawString("Muller-Lyer Illusion", x, y);	
      }
   	
       public static void main(String [] args)
      {
         JFrame theGUI = new JFrame();
         theGUI.setTitle("Muller-Lyer Illusion");
         theGUI.setSize(200, 200);
         theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         MullerLyer panel = new MullerLyer(Color.black);
         Container pane = theGUI.getContentPane();
         pane.add(panel);
         theGUI.setVisible(true);
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.