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

📄 painter.java

📁 金旭亮的java教案
💻 JAVA
字号:
// Painter.java
// 在JPanel的一个子类中用鼠标绘图
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class Painter extends JFrame
{
   // 绘图板
   private DrawJPanel myDrawJPanel;

   // 构造函数
   public Painter()
   {
      createUserInterface();//创建用户界面
   }

   // 创建所有的用户界面元素
   public void createUserInterface()
   {
      // 获取容器对象
      Container contentPane = getContentPane();

      // 不指定布局管理器,从而允许自由地摆放控件 
      contentPane.setLayout( null );
      
      // 创建绘图面板
      myDrawJPanel = new DrawJPanel();
      myDrawJPanel.setBounds( 0, 0, 300, 300 );
      contentPane.add( myDrawJPanel );

      
      setTitle( "Painter" ); // 设置窗体标题
      setSize( 300, 300 );   // 设置窗体大小
       setLocation(300,300);
      setVisible( true );    // 显示窗体

   } // end method createUserInterface

   //程序入口点
   public static void main( String[] args )
   {
      Painter application = new Painter();
      //允许关闭程序
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

   } // end method main

} // end class Painter

/**************************************************************************
 * (C) Copyright 1992-2004 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/

⌨️ 快捷键说明

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