?? customdialog.java
字號:
/*
$Author: $
$Date: $
$Revision: $
$NoKeywords: $
*/
package jp.co.ntl.awt;
import java.awt.*;
import java.awt.event.*;
public class CustomDialog extends Dialog {
/**
*
*/
private static final long serialVersionUID = 1L;
public static int UNINITIALIZED_VALUE = 100;
public static int WINDOW_CLOSE_OPTION = 200;
private static int MIN_FIRST_BUTTON_X = 20;
private static int BTN_PANEL_HEIGHT = 50;
private static int BUTTON_WIDTH = 80;
private static int BUTTON_HEIGHT = 25;
private static int BUTTON_INTERVAL = 10;
private ValidatePanel vpanel = null;
private SimpleButton[] buttons;
private CustomDialog(Frame owner, String title, boolean modal, ValidatePanel vpanel) {
super(owner, title, modal);
this.vpanel = vpanel;
this.buttons = vpanel.getButtons();
int minPanelWidth = MIN_FIRST_BUTTON_X * 2+ BUTTON_WIDTH * buttons.length
+ BUTTON_INTERVAL * (buttons.length - 1);
Panel panel = new Panel();
panel.setLayout(null);
Dimension d = vpanel.getSize();
int width = d.width < minPanelWidth ? minPanelWidth : d.width;
int height = d.height;
vpanel.setBounds((width - d.width) / 2, 0, d.width, d.height);
panel.add(vpanel);
BtnContainer pnlButton = new BtnContainer();
pnlButton.setLayout(null);
pnlButton.setBounds(0, height, width, BTN_PANEL_HEIGHT);
panel.add(pnlButton);
ActionListener al = new MyActionListener();
int bx = (width - BUTTON_WIDTH * buttons.length - BUTTON_INTERVAL * (buttons.length - 1)) / 2;
int by = (BTN_PANEL_HEIGHT - BUTTON_HEIGHT) / 2;
for (int i = 0; i < buttons.length; i++) {
buttons[i].setBounds(bx,
by,
BUTTON_WIDTH,
BUTTON_HEIGHT);
pnlButton.add(buttons[i]);
buttons[i].addActionListener(al);
bx += BUTTON_WIDTH + BUTTON_INTERVAL;
}
panel.setSize(new Dimension(width, height + BTN_PANEL_HEIGHT));
add(panel, BorderLayout.CENTER);
pack();
// 僟僀傾儘僌偺昞帵埵抲傪愝掕
//Rectangle o = owner.getBounds();
Dimension o = getToolkit().getScreenSize();
Rectangle c = getBounds();
setLocation(/*o.x + */(o.width - c.width) / 2, /*o.y + */(o.height - c.height) / 2);
setResizable(false);
addWindowListener(new MyWindowListener());
}
private int codeAtEnd = UNINITIALIZED_VALUE;
public int getSelection() {
return codeAtEnd;
}
class MyActionListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
for (int i = 0; i < buttons.length; i++) {
if (source == buttons[i]) {
if (vpanel.isValid(i)) {
codeAtEnd = i;
dispose();
} else {
// 壗傕偟側偄
}
break;
}
}
}
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent we) {
codeAtEnd = WINDOW_CLOSE_OPTION;
dispose();
}
}
private static Frame getFrameForComponent(Component comp) {
Component parent = comp;
while (parent != null) {
if (parent instanceof Frame) {
break;
}
parent = parent.getParent();
}
return (Frame)parent;
}
public static int showCustomDialog(Component parent, String title, ValidatePanel vpanel) {
CustomDialog dialog = new CustomDialog(getFrameForComponent(parent), title, true, vpanel);
dialog.repaint();
dialog.setVisible(true);
return dialog.getSelection();
}
class BtnContainer extends Container {
/**
*
*/
private static final long serialVersionUID = 1L;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -