+ 1
Java graphics
I need help drawing a fillRect method that takes in width and height. And fills it with pixels.
3 Answers
+ 1
A example how you can do it:
import java.awt.*;
import javax.swing.*;
class MyRec extends JPanel{
public static void main(String[] args) {
MyRec mr = new MyRec();
JFrame frame = new JFrame();
frame.add(mr);
frame.setSize(300,300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.fillRect(50, 50, 70, 70);
}
}
+ 1
can we add color in the graphic section
+ 1
Yes, above fillRect you can use:
g.setColor(Color.red);