zoukankan      html  css  js  c++  java
  • Java基础之创建窗口——颜色和光标(TryWindow4)

    控制台程序。

    java.awt包中把SystemColor类定义为Color类的子类。SystemColor类封装了本机操作系统用于显示各种组件的标准颜色。如果要比较SystemColor值和Color对象,就必须使用getRGB()方法。这是因为SystemColor类在内部存储颜色时采用的方式是:使用从Color类继承而来的域,而不是使用正常的Color对象。

    java.awt.Cursor类的对象封装了鼠标光标的位图表示。Cursor类包含一组final static常量,用来指定标准的光标类型,它们可用于选择或创建特定的光标。

    要创建表示文本光标的Cursor对象,可以编写如下代码:

    Cursor myCursor = new Cursor(Cursor.TEXT_CURSOR);

    另外,还可以使用一个静态类方法来检索预定义的光标:

    Cursor myCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);

    当不希望存储Cursor对象,而只是希望将之传送给方法时,例如传送给Component对象的setCursor()方法,这个方法尤其有用。

     1 import javax.swing.JFrame;
     2 import javax.swing.SwingUtilities;
     3 import java.awt.Toolkit;
     4 import java.awt.Dimension;
     5 import java.awt.Color;
     6 import java.awt.Cursor;
     7 
     8 public class TryWindow4 {
     9   public static void createWindow(){
    10     JFrame aWindow = new JFrame("This is the Window Title");
    11     Toolkit theKit = aWindow.getToolkit();                             // Get the window toolkit
    12     Dimension wndSize = theKit.getScreenSize();                        // Get screen size
    13 
    14     // Set the position to screen center & size to half screen size
    15     aWindow.setSize(wndSize.width/2, wndSize.height/2);                // Set window size
    16     aWindow.setLocationRelativeTo(null);                               // Center window
    17     aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    18 
    19     aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    20     aWindow.getContentPane().setBackground(Color.PINK);
    21 
    22     aWindow.setVisible(true);                                          // Display the window
    23   }
    24 
    25   public static void main(String[] args) {
    26     SwingUtilities.invokeLater(new Runnable() {
    27             public void run() {
    28                 createWindow();
    29             }
    30         });
    31   }
    32 }
  • 相关阅读:
    2、容器初探
    3、二叉树:先序,中序,后序循环遍历详解
    Hebbian Learning Rule
    论文笔记 Weakly-Supervised Spatial Context Networks
    在Caffe添加Python layer详细步骤
    论文笔记 Learning to Compare Image Patches via Convolutional Neural Networks
    Deconvolution 反卷积理解
    论文笔记 Feature Pyramid Networks for Object Detection
    Caffe2 初识
    论文笔记 Densely Connected Convolutional Networks
  • 原文地址:https://www.cnblogs.com/mannixiang/p/3463966.html
Copyright © 2011-2022 走看看