3个回答
展开全部
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLayeredPane;
public class MyFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton exitButton;
protected static JLayeredPane layeredpane;
public MyFrame (){
super("MyFrame");
setSize(300,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(200,200);
setLayout(null);
setVisible(true);
layeredpane=getLayeredPane();
exitButton=new JButton("退出");
exitButton.setBounds(90, 50, 100, 50);
exitButton.addActionListener(this);
exitButton.setContentAreaFilled(false);
layeredpane.add(exitButton);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==exitButton) System.exit(0);
}
public static void main(String[] args) {
new MyFrame ();
}
}
大概是这样吧
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLayeredPane;
public class MyFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton exitButton;
protected static JLayeredPane layeredpane;
public MyFrame (){
super("MyFrame");
setSize(300,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(200,200);
setLayout(null);
setVisible(true);
layeredpane=getLayeredPane();
exitButton=new JButton("退出");
exitButton.setBounds(90, 50, 100, 50);
exitButton.addActionListener(this);
exitButton.setContentAreaFilled(false);
layeredpane.add(exitButton);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==exitButton) System.exit(0);
}
public static void main(String[] args) {
new MyFrame ();
}
}
大概是这样吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询