package graphic;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class HelloAwt extends Frame {
/**
*
*/
// private static final long serialVersionUID = 1L;
public static void main(String[] args)
{
new HelloAwt().run();
}
/**
* 运行程序
*/
private void run()
{
createButton();
configureFrame();
createButton();
createButton();
createButton();
createButton();
createButton();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
}
/**
* 创建主窗口
*
*/
private void configureFrame()
{
setTitle("Hello");
setLayout( new FlowLayout());
setSize(new Dimension(400,400));
setLocation(100,110);
}
/**
* 创建按钮
*/
private void createButton()
{
Button button = new Button("打开");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
createDialog();
}
});
add(button,BorderLayout.NORTH);
// setVisible(true);
}
private void createDialog()
{
//第一个参数表示是该类,第二个名字,
final Dialog dialog = new Dialog(HelloAwt.this,"对话框",true);
dialog.setSize(new Dimension(267,117));
Toolkit toolkit = dialog.getToolkit();
Dimension screenSize = toolkit.getScreenSize();
// x代表对话框的左边的位置
int x = HelloAwt.this.getX()
+(HelloAwt.this.getWidth()-dialog.getWidth())/2;
// 如果其小于 0 ,则代表其超出了左边屏幕,
// 则将其设置成0
if(x < 0)
x = 0;
//其加上对话框的宽度为右边对话框的x位置,如果其大于屏幕宽度,则将其
详细解决方案
照抄了书上一段代码,请教下awt的有关问题
热度:51 发布时间:2016-04-21 23:04:36.0
相关解决方案