Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; public class DirectDrawDemo extends JPanel { private BufferedImage canvas; public DirectDrawDemo(int width, int height) { canvas = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); fillCanvas(Color.BLUE); drawRect(Color.RED, 0, 0, width/2, height/2); } public Dimension getPreferredSize() { return new Dimension(canvas.getWidth(), canvas.getHeight()); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.drawImage(canvas, null, null); } public void fillCanvas(Color c) { int color = c.getRGB(); for (int x = 0; x &lt; canvas.getWidth(); x++) { for (int y = 0; y &lt; canvas.getHeight(); y++) { canvas.setRGB(x, y, color); } } repaint(); } public void drawLine(Color c, int x1, int y1, int x2, int y2) { // Implement line drawing repaint(); } public void drawRect(Color c, int x1, int y1, int width, int height) { int color = c.getRGB(); // Implement rectangle drawing for (int x = x1; x &lt; x1 + width; x++) { for (int y = y1; y &lt; y1 + height; y++) { canvas.setRGB(x, y, color); } } repaint(); } public void drawOval(Color c, int x1, int y1, int width, int height) { // Implement oval drawing repaint(); } public static void main(String[] args) { int width = 640; int height = 480; JFrame frame = new JFrame("Direct draw demo"); DirectDrawDemo panel = new DirectDrawDemo(width, height); frame.add(panel); frame.pack(); frame.setVisible(true); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } </code></pre> <p><a href="http://grab.by/grabs/39416148962d1da3de12bc0d95745341.png">alt text http://grab.by/grabs/39416148962d1da3de12bc0d95745341.png</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload