一道简单的Java Swing问题
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassTestextendsJFr...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame{
public Test(){
JButton b1=new JButton("关闭");
b1.addActionListener(new al());
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b1);
}
class al implements ActionListener{
public void actionPerformed(ActionEvent e){
}
}
public static void main(String[] args) {
Test gl=new Test();
gl.setSize(300,200);
gl.setTitle("Test");
gl.setVisible(true);
}
}
想要在public void actionPerformed(ActionEvent e){}里面设置一个监听事件,当点击按扭后可以关闭JFrame,请指教 展开
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame{
public Test(){
JButton b1=new JButton("关闭");
b1.addActionListener(new al());
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b1);
}
class al implements ActionListener{
public void actionPerformed(ActionEvent e){
}
}
public static void main(String[] args) {
Test gl=new Test();
gl.setSize(300,200);
gl.setTitle("Test");
gl.setVisible(true);
}
}
想要在public void actionPerformed(ActionEvent e){}里面设置一个监听事件,当点击按扭后可以关闭JFrame,请指教 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询