I'm trying to copile this Java program in Textpad, but I'm getting the following error
C:\Users\User\Desktop\java\Drawing.java:14: error: incompatible types: possible lossy conversion from float to int g.drawLine ((getWidth()/2) , 0, (getWidth()*i) , (getHeight()/2));
Here is the code
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class Drawing extends JPanel
{
public void painComponent(Graphics g)
{
super.paintComponent (g);
for (float i=0; i<=1; i+=1/7)
{
Random r=new Random();
g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
g.drawLine ((getWidth()/2) , 0, (getWidth()*i) , (getHeight()/2));
}
g.drawLine(0,getHeight()/2, getWidth()/2, getHeight()/2);
g.drawLine(getWidth(), getHeight()/2, getWidth()/2, getHeight());
}
public static void main(String args[])
{
Drawing d=new Drawing();
JFrame frame=new JFrame();
frame.add(d);
frame.setSize(600,600);
frame.setTitle("Drawing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
I've tried adding (float) to before getWidth*i, but it didn't work for me. Google wasn't of much help either, that or I haven't searched enough. I'd be very grateful if anyone could provide me with a certain solution.
Thank you