paintdemo.java

来自「这是一个用java编写的关于GUI应用编程的简单的样例」· Java 代码 · 共 57 行

JAVA
57
字号
package chap13.demo;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2008-3-18
 * Time: 1:01:18
 * File PaintDemo.java
 */
public class PaintDemo extends JPanel {

    public PaintDemo() {
    }

    public void paint(Graphics g) {
        super.paint(g);    //To change body of overridden methods use File | Settings | File Templates.
        g.draw3DRect(100,50,100,100,true);
        g.drawOval(200,50,100,100);
        Font font=new Font("SimSun",Font.ITALIC,20);
        g.setFont(font);
        g.drawString("Welcome",100,250);
    }
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("PaintDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        PaintDemo demo = new PaintDemo();
        frame.add(demo,BorderLayout.CENTER);

        //Display the window.
        frame.setSize(800,600);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        for(Font f:GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()){
            System.out.println(f);
        }
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}

⌨️ 快捷键说明

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