import java.awt.*; // victimisation AWT's Graphics and Color
import java.awt.event.*; // victimisation AWT event categories and perceiver interfaces
import javax.swing.*; // victimisation Swing's parts and containers
/** Custom Drawing Code templet */
// A Swing application extends javax.swing.JFrame
public category CGTemplate extends JFrame outline constants
public static final int CANVAS_WIDTH = 640;
public static final int CANVAS_HEIGHT = 480;
// Declare AN instance of the drawing canvas,
// that is AN inner category known as DrawCanvas extending javax.swing.JPanel.
personal DrawCanvas canvas;
// builder to line up the graphical user interface parts and event handlers
public CGTemplate() because the JFrame's content-pane
instrumentation cp = getContentPane();
cp.add(canvas);
// or "setContentPane(canvas);"
setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the shut button
pack(); // Either pack() the components; or setSize()
setTitle("......"); // "super" JFrame sets the title
setVisible(true); // "super" JFrame show
}
/**
* outline inner category DrawCanvas, that could be a JPanel used for custom drawing.
*/
personal category DrawCanvas extends JPanel for instance,
// Drawing primitive shapes
g.setColor(Color.YELLOW); // set the drawing color
g.drawLine(30, 40, 100, 200);
g.drawOval(150, 180, 10, 10);
g.drawRect(200, 210, 20, 30);
g.setColor(Color.RED); // modification the drawing color
g.fillOval(300, 310, 30, 50);
g.fillRect(400, 350, 60, 50);
// Printing texts
g.setColor(Color.WHITE);
g.setFont(new Font("Monospaced", Font.PLAIN, 12));
g.drawString("Testing custom drawing ...", 10, 20);
}
}
// The entry main methodology
public static void main(String[] args) {
// Run the graphical user interface codes on the Event-Dispatching thread for thread safety
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CGTemplate(); // Let the builder do the duty
}
});
}
}
Solution
import java.awt.*; // victimisation AWT's Graphics and Color
import java.awt.event.*; // victimisation AWT event categories and perceiver interfaces
import javax.swing.*; // victimisation Swing's parts and containers
/** Custom Drawing Code templet */
// A Swing application extends javax.swing.JFrame
public category CGTemplate extends JFrame outline constants
public static final int CANVAS_WIDTH = 640;
public static final int CANVAS_HEIGHT = 480;
// Declare AN instance of the drawing canvas,
// that is AN inner category known as DrawCanvas extending javax.swing.JPanel.
personal DrawCanvas canvas;
// builder to line up the graphical user interface parts and event handlers
public CGTemplate() because the JFrame's content-pane
instrumentation cp = getContentPane();
cp.add(canvas);
// or "setContentPane(canvas);"
setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the shut button
pack(); // Either pack() the components; or setSize()
setTitle("......"); // "super" JFrame sets the title
setVisible(true); // "super" JFrame show
}
/**
* outline inner category DrawCanvas, that could be a JPanel used for custom drawing.
*/
personal category DrawCanvas extends JPanel for instance,
// Drawing primitive shapes
g.setColor(Color.YELLOW); // set the drawing color
g.drawLine(30, 40, 100, 200);
g.drawOval(150, 180, 10, 10);
g.drawRect(200, 210, 20, 30);
g.setColor(Color.RED); // modification the drawing color
g.fillOval(300, 310, 30, 50);
g.fillRect(400, 350, 60, 50);
// Printing texts
g.setColor(Color.WHITE);
g.setFont(new Font("Monospaced", Font.PLAIN, 12));
g.drawString("Testing custom drawing ...", 10, 20);
}
}
// The entry main methodology
public static void main(String[] args) {
// Run the graphical user interface codes on the Event-Dispatching thread for thread safety
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CGTemplate(); // Let the builder do the duty
}
});
}
}

import java.awt.; victimisation AWTs Graphics and Color impo.pdf

  • 1.
    import java.awt.*; //victimisation AWT's Graphics and Color import java.awt.event.*; // victimisation AWT event categories and perceiver interfaces import javax.swing.*; // victimisation Swing's parts and containers /** Custom Drawing Code templet */ // A Swing application extends javax.swing.JFrame public category CGTemplate extends JFrame outline constants public static final int CANVAS_WIDTH = 640; public static final int CANVAS_HEIGHT = 480; // Declare AN instance of the drawing canvas, // that is AN inner category known as DrawCanvas extending javax.swing.JPanel. personal DrawCanvas canvas; // builder to line up the graphical user interface parts and event handlers public CGTemplate() because the JFrame's content-pane instrumentation cp = getContentPane(); cp.add(canvas); // or "setContentPane(canvas);" setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the shut button pack(); // Either pack() the components; or setSize() setTitle("......"); // "super" JFrame sets the title setVisible(true); // "super" JFrame show } /** * outline inner category DrawCanvas, that could be a JPanel used for custom drawing. */ personal category DrawCanvas extends JPanel for instance, // Drawing primitive shapes g.setColor(Color.YELLOW); // set the drawing color g.drawLine(30, 40, 100, 200); g.drawOval(150, 180, 10, 10); g.drawRect(200, 210, 20, 30);
  • 2.
    g.setColor(Color.RED); // modificationthe drawing color g.fillOval(300, 310, 30, 50); g.fillRect(400, 350, 60, 50); // Printing texts g.setColor(Color.WHITE); g.setFont(new Font("Monospaced", Font.PLAIN, 12)); g.drawString("Testing custom drawing ...", 10, 20); } } // The entry main methodology public static void main(String[] args) { // Run the graphical user interface codes on the Event-Dispatching thread for thread safety SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new CGTemplate(); // Let the builder do the duty } }); } } Solution import java.awt.*; // victimisation AWT's Graphics and Color import java.awt.event.*; // victimisation AWT event categories and perceiver interfaces import javax.swing.*; // victimisation Swing's parts and containers /** Custom Drawing Code templet */ // A Swing application extends javax.swing.JFrame public category CGTemplate extends JFrame outline constants public static final int CANVAS_WIDTH = 640; public static final int CANVAS_HEIGHT = 480; // Declare AN instance of the drawing canvas, // that is AN inner category known as DrawCanvas extending javax.swing.JPanel.
  • 3.
    personal DrawCanvas canvas; //builder to line up the graphical user interface parts and event handlers public CGTemplate() because the JFrame's content-pane instrumentation cp = getContentPane(); cp.add(canvas); // or "setContentPane(canvas);" setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the shut button pack(); // Either pack() the components; or setSize() setTitle("......"); // "super" JFrame sets the title setVisible(true); // "super" JFrame show } /** * outline inner category DrawCanvas, that could be a JPanel used for custom drawing. */ personal category DrawCanvas extends JPanel for instance, // Drawing primitive shapes g.setColor(Color.YELLOW); // set the drawing color g.drawLine(30, 40, 100, 200); g.drawOval(150, 180, 10, 10); g.drawRect(200, 210, 20, 30); g.setColor(Color.RED); // modification the drawing color g.fillOval(300, 310, 30, 50); g.fillRect(400, 350, 60, 50); // Printing texts g.setColor(Color.WHITE); g.setFont(new Font("Monospaced", Font.PLAIN, 12)); g.drawString("Testing custom drawing ...", 10, 20); } } // The entry main methodology public static void main(String[] args) { // Run the graphical user interface codes on the Event-Dispatching thread for thread safety
  • 4.
    SwingUtilities.invokeLater(new Runnable() { @Override publicvoid run() { new CGTemplate(); // Let the builder do the duty } }); } }