自己闲的,突发奇想编了这么个程序,最后关不了了,帮帮忙吧~~~
我改的地方已标注出来,请指教一个不用关eclipse就可以把它关掉的方法~~
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonDemo extends JFrame implements ActionListener{
     public static final int height=500;
     public static final int width=600;
public static void main(String[] args) {
ButtonDemo buttonGui=new ButtonDemo();
buttonGui.setVisible(true);
	}
public ButtonDemo(){
	setSize(height,width);	
	addWindowListener(new WindowDestroyer());
	setTitle("很抱歉,你已经中毒!");
	setBackground(Color.blue);	
	setLayout(new FlowLayout());	
	JButton stopbutton=new JButton("RED");
	stopbutton.addActionListener(this);
	add(stopbutton);	
	JButton gobutton=new JButton("Green");
	gobutton.addActionListener(this);
	add(gobutton);
	}
public void actionPerformed(ActionEvent e){
	if(e.getActionCommand().equals("RED"))
		setBackground(Color.red);
	else if(e.getActionCommand().equals("Green"))
		setBackground(Color.green);
	else
		System.out.println("Error in button interface");
}
}
class WindowDestroyer extends WindowAdapter
{
	  public void windowClosing(WindowEvent e)
	  {		 
 ButtonDemo buttonGui=new ButtonDemo(); 		  buttonGui.setVisible(true); 	  }
	}
------解决方案-------------------- 将选项卡面板上的导航项的控件设置为含有关闭按钮的按钮
tabbedPane.setTabComponentAt(index, buttonTabComponent);
------解决方案-------------------- setDefaultCloseOperation
public void setDefaultCloseOperation(int operation)设置用户在此窗体上发起 "close" 时默认执行的操作。必须指定以下选项之一:  
?DO_NOTHING_ON_CLOSE(在 WindowConstants 中定义):不执行任何操作;要求程序在已注册的 WindowListener 对象的 windowClosing 方法中处理该操作。  
?HIDE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册的 WindowListener 对象后自动隐藏该窗体。  
?DISPOSE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册 WindowListener 的对象后自动隐藏并释放该窗体。  
?EXIT_ON_CLOSE(在 JFrame 中定义):使用 System exit 方法退出应用程序。仅在应用程序中使用。  
默认情况下,该值被设置为 HIDE_ON_CLOSE。
------解决方案-------------------- 关虚拟机
------解决方案-------------------- 探讨  引用: setDefaultCloseOperation public void setDefaultCloseOperation(int operation)设置用户在此窗体上发起 "close" 时默认执行的操作。必须指定以下选项之一: ?DO_NOTHING_ON_CLOSE(在 WindowConstants 中定义):不执行任何操作;要求程序在已注…… 
------解决方案-------------------- 不就是想关闭程序嘛~~~~简单啊。。。。
eclipse菜单有个window菜单,点击后把鼠标放到show wiew子菜单上,选择菜单项Console
(你实在找不到,随便新建个hello.java,输出一下hello就可以看到Console标签页了)
这样,你的eclipse编辑界面中就多了一个console标签页(默认在下面),程序运行后console标签页的右边就会出现3个按钮,而第一个是变红的方块,点它就可以中止运行中的Java程序了~~~~