JAVA作业

来源:百度知道 编辑:UC知道 时间:2024/05/26 21:48:54
试编写一个Java应用程序,它有三个类:Shapes类Command类和GUI类。要求GUI类与应用程序分开,事件处理程序Command类(监听类)也与做具体工作的主程序Shapes类分开。运行结果如上图所示,具体实现是:三个按钮(如图所示)Square

作业是女友的,我不会JAVA……谢谢

图贴不了……

//好象在Frame中作图比较麻烦,作图方法正在实现中………
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class GUI extends JFrame{
JButton SquareBtn;
JButton CircleBtn;
JButton TrangleBtn;
GUI(){
super();
}
GUI(String name){
super(name);
SquareBtn = new JButton("Square");
CircleBtn = new JButton("Circle");
TrangleBtn = new JButton("Trangle");

SquareBtn.addActionListener(new Command());
CircleBtn.addActionListener(new Command());
TrangleBtn.addActionListener(new Command());

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
dispose();
System.exit(0);
}
});

this.setLayout(new FlowLayout());
this.add(SquareBtn);
this.add(CircleBtn);
this.add(TrangleBtn);

this.setSize(300,100);
this.setVisible(true);