graphicsview.java

来自「我这次还是java的代码」· Java 代码 · 共 84 行

JAVA
84
字号
/**
 * 
 */
package hnu.software.pfdai;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author daipengfei
 * 
 */
public class GraphicsView extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1433974899842922654L;

	private double rate;

	private JLabel rateLabel;

	/**
	 * Constructs a new GraphicsView that is initially invisible.
	 * 
	 */
	public GraphicsView() {
		super();
		rateLabel = new JLabel("Result Rate is " + rate);

		add(rateLabel);
		setBackground(Color.WHITE);
	}

	/**
	 * paint the round
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		int arcAngle = (int) (360 * (rate / 100));
		g2.setPaint(Color.red);
		g2.fillArc(100, 100, 150, 150, arcAngle, 360);
		g2.setPaint(Color.blue);
		g2.fillArc(100, 100, 150, 150, 0, arcAngle);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
	 */
	public void update(Observable o, Object arg) {
		Model model = (Model) o;
		rate = model.getResult();
		rateLabel.setText("Result Rate is " + rate);
		repaint();
	}

	/**
	 * @return the rate
	 */
	public double getRate() {
		return rate;
	}

	/**
	 * @param rate
	 *            the rate to set
	 */
	public void setRate(double rate) {
		this.rate = rate;
	}

}

⌨️ 快捷键说明

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