Java面向对象深入学习:制作一个画图工具并计算那些图形的面积和周长。
一.将以下的每一个Java程序都放到同一个包下。
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import com.lovoinfo.shape.Line;
import com.lovoinfo.shape.Oval;
import com.lovoinfo.shape.Rectangle;
import com.lovoinfo.shape.Shape;
import com.lovoinfo.util.MyUtil;
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
private JButton lineButton;
private JButton ovilButton;
private JButton rectangleButton;
private Shape shape = null;
private class ButtonHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("line")) {
shape = new Line();
} else if (command.equals("ovil")) {
shape = new Oval();
} else {
shape = new Rectangle();
}
shape.setX1(MyUtil.random(0, 1000));
shape.setY1(MyUtil.random(0, 600));
shape.setX2(MyUtil.random(0,