+ 1

Java graphics

I need help drawing a fillRect method that takes in width and height. And fills it with pixels.

3rd Feb 2019, 9:46 PM
icU
icU - avatar
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); } }
4th Feb 2019, 1:51 AM
JavaBobbo
JavaBobbo - avatar
+ 1
can we add color in the graphic section
4th Feb 2019, 10:55 AM
Bharat Pawar
Bharat Pawar - avatar
+ 1
Yes, above fillRect you can use: g.setColor(Color.red);
4th Feb 2019, 11:34 AM
JavaBobbo
JavaBobbo - avatar