1

The lines should go top right corner, where (a,0) is. I couldn't work it out. I'm using Eclipse 3.65.

enter image description here

public class Ikibin extends JFrame{

int a = 400;
int b = 600;

public Ikibin()
{

    setTitle("Tutorial");
    setSize(a,b);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void paint(Graphics g)
{
    g.setColor(Color.blue);
    g.drawLine(0, 0, 0, b);
    g.drawLine(a/4, 0, a/4, b);
    g.drawLine(a/2, 0, a/2, b);
    g.drawLine(3*a/4, 0, 3*a/4, b);
    g.drawLine(0, 0, a, 0);
    g.drawLine(0, b/4, a, 0);
    g.drawLine(0, b/2, a, 0);
    g.drawLine(0, 3*b/4, a, 0);
}


public static void main (String [] args)
{
    Ikibin i = new Ikibin();
}
} 
Frakcool
  • 10,915
  • 9
  • 50
  • 89
  • Looks like they are, but they're going to the 0,0 of the WINDOW, not the canvas. – Marc B May 20 '14 at 16:03
  • But the canvas ends in (a,0), and the line also goes to (a,0). How can this happen? Thank you for your answer. –  May 20 '14 at 16:04
  • 2
    "Swing programs should override `paintComponent()` instead of overriding `paint()`."—[*Painting in AWT and Swing: The Paint Methods*](http://www.oracle.com/technetwork/java/painting-140037.html#callbacks). – trashgod May 20 '14 at 16:43

1 Answers1

0

Your setting it to be 0 which is where it is but the X is still a /4 or a / 2 or so. So basically you are making it go in select places. How the code is written is where they will go if you want them all in the top right corner then you would just leave x as 400. Or in your case A = 400.