本文介绍了二维几何约束系统,面向对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imane BEN MOUSSA


我正在尝试将矩形2d,circle2d,line2D,point2D绘制到窗格上.我的程序将编译
并运行,但是当我按下任何按钮时似乎都不会绘制.当程序
运行时,程序框架打开,但是我在
上看不到任何东西除按钮外的窗格.
任何帮助将不胜感激.
真诚的
Imane

Imane BEN MOUSSA


I am trying to draw rectangle2d, circle2d , line2D,point2D onto a pane. My program will compile
and run but when i press any button does not seem to get drawn. When the program
is run the program frame opens up, but I cannot see any thing on the
pane except button.
Any help would be appreciated.
Sincerely,
Imane

推荐答案

package com.test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
public class Program extends JFrame {

	public Program() {
		setSize(320, 200);
		setBackground(Color.WHITE);
		setForeground(Color.WHITE);
	}

	@Override
	public void paint(Graphics g) {
		Graphics2D graphics = (Graphics2D) g;
		// Draw red rectangle
		graphics.setPaint(Color.RED);
		Rectangle2D.Double rectangle = new
                   Rectangle2D.Double(64, 64, 60, 30);
		graphics.drawRect((int)rectangle.x, (int)rectangle.y,
                   (int)rectangle.width, (int)rectangle.height);

		// Draw green circle
		graphics.setPaint(Color.GREEN);

		graphics.drawArc(120, 120, 32, 32, 0, 360);
	}

	public static void main(String[] args) throws Exception  {
		Program program = new Program();
		program.setVisible(true);

		System.in.read();

	}
}



希望这会有所帮助,
弗雷德里克·博纳德(Fredrik Bornander)



Hope this helps,
Fredrik Bornander


这篇关于二维几何约束系统,面向对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:40