⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawings.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.windows;
import java.awt.*;
import javax.swing.*;
/** An example class used to demonstrate various
  * drawing techniques including text, lines,
  * shapes, and filled shapes.
  */
public class Drawings extends JFrame {
   /** Class constructor method
     * @param titleText name to be put in the
     *    window's title bar
     */
   public Drawings( String titleText ) {
      super( titleText );
      addWindowListener( new WindowCloser() );
      DrawingPanel dp = new DrawingPanel();
      getContentPane().add( dp, BorderLayout.CENTER );
      setSize( 500, 500 );
      setVisible( true );
   }

   public class DrawingPanel extends JPanel {
      /** Class constructor
        */
      public DrawingPanel() {
         setBackground( Color.white );
         setBorder( BorderFactory.createTitledBorder(
            "Sample output from drawing methods:" ) );
      }
      /** Draws the text, lines, and shapes in the
        * specified graphics context
        * @param g the component's graphics context
        */
      public void paintComponent( Graphics g ) {
         super.paintComponent(g);
         g.drawString( "Hello World!", 100, 60 );
         Font cFont = g.getFont();
         Font newFont = new Font( cFont.getName(),
                                  cFont.getStyle(),
                                  cFont.getSize() + 20 );
         g.setFont( newFont );
         g.drawString( "Here I am!", 200, 80 );
         g.drawLine( 50, 50, 100, 200 );
         g.setColor( Color.blue );
         g.drawRoundRect( 150, 300, 100, 125, 15, 15 );
         g.setColor( Color.red );
         g.fillOval( 400, 200, 50, 180 );
      }
   }

   /** The test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      new Drawings( "Drawings Sample" );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -