实现一个窗口,布局用BorderLayout,在其布局的北部添加一个按钮,点击该按钮可以退
1个回答
2014-05-10
展开全部
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.hello;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
/**
*
* @author fxb
*/
public class MyFrame extends Frame implements ActionListener {
public MyFrame(String title){
super(title);
}
public static void main(String[] args) {
MyFrame frame = new MyFrame("myGUI");
Button bn =new Button("close");
bn.addActionListener(frame);
frame.add(bn,BorderLayout.NORTH);
frame.setSize(500,500);
frame.setBackground(Color.blue);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
System.out.println("onclick");
System.exit(0);
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.hello;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
/**
*
* @author fxb
*/
public class MyFrame extends Frame implements ActionListener {
public MyFrame(String title){
super(title);
}
public static void main(String[] args) {
MyFrame frame = new MyFrame("myGUI");
Button bn =new Button("close");
bn.addActionListener(frame);
frame.add(bn,BorderLayout.NORTH);
frame.setSize(500,500);
frame.setBackground(Color.blue);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
System.out.println("onclick");
System.exit(0);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询