The Quintessential Drawing Program:画图程序的精粹

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

This example creates a frame and draws an oval within the frame.

//导入awt和swing包,用于创建图形界面

import java.awt.*;

import javax.swing.*;

class BasicDraw extends JComponent {

public void paint(Graphics g) {

//创建一个Graphics2D对象

Graphics2D g2d = (Graphics2D)g;

//画椭圆

g2d.drawOval(0, 0, getSize().width-1,

getSize().height-1);

}

public static void main(String[] args) {

//创建主窗口

JFrame frame = new JFrame();

//添加一个匿名BasicDraw对象

frame.getContentPane().add(new BasicDraw());

int frameWidth = 300;

int frameHeight = 300;

frame.setSize(frameWidth, frameHeight);

frame.setVisible(true);

}

}

你可能感兴趣的:(C++,c,swing,C#)