Drawing function descriptions drawLine(int x1, int y1, int x2, int y2) public vo
ID: 3826690 • Letter: D
Question
Drawing function descriptions drawLine(int x1, int y1, int x2, int y2) public void fillOval(int x, int y, int width, int height) drawOval(int x, int y, int width, int height) drawRect(int x, int y, int width, int height) drawString(String str, int x, int y) fillRect(int x, int y, int width, int height) One - Sketch the results of a call to the following paint function public void paintComponent (Graphics g) {g. drawString ("Let It Snow", 100, 100); g.setColor(Color.blue); g.drawOval (200, 150, 50, 50); g. drawOval(187, 200, 75, 75); g.drawOval(175, 275, 100, 100); g.setColor(Color.black); g. drawLine(200, 150, 250, 150); g.fillRect(210, 120, 30, 30);Explanation / Answer
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JPanel {
public void paintComponent(Graphics g) {
g.drawString("Let It Snow", 100, 100);
g.setColor(Color.blue);
g.drawOval(200,150,50,50);
g.drawOval(187,200,75,75);
g.drawOval(175,275,100,100);
g.setColor(Color.black);
g.drawLine(200,150,250,150);
g.fillRect(210,120,30,30);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MainClass());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200,200);
frame.setVisible(true);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.