📄 errordialog.java
字号:
//////////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 1996 L. Patocchi & W.Gander//// This program is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 of the License, or (at your option)// any later version.//// This program is distributed in the hope that it will be useful, but WITHOUT// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for// more details.//// You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., 675 Mass// Ave, Cambridge, MA 02139, USA.//// Contacts:// // Project Supervisor// W.Hett hew@info.isbiel.ch// // Authors// W.Gander gandw@info.isbiel.ch// L.Patocchi patol@info.isbiel.ch//// Documentation can be found at://// http://www.isbiel.ch/Projects/janet/index.html////////////////////////////////////////////////////////////////////////////////////////// File : errorDialog.java//
package jaNet;
import java.awt.*;
public class errorDialog extends Dialog {
public Label labelErrorMsg;
public Separator separatorH;
public Button buttonOk;
public errorDialog(Frame parent, String msg) {
super(parent, " ", false);
this.setBackground(Color.lightGray);
// main panel
GridBagLayout grid = new GridBagLayout();
int rowHeights[] = {0,10,20,25,25,10};
int columnWidths[] = {0,5,125,75,125,5};
double rowWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0};
double columnWeights[] = {0.0,0.0,1.0,0.0,1.0,0.0};
grid.rowHeights = rowHeights;
grid.columnWidths = columnWidths;
grid.rowWeights = rowWeights;
grid.columnWeights = columnWeights;
labelErrorMsg = new Label();
labelErrorMsg.setFont(new Font("Helvetica",Font.BOLD , 14));
labelErrorMsg.setText(msg);
this.add(labelErrorMsg);
separatorH = new Separator(Separator.HORIZONTAL);
separatorH.perSide = 0;
separatorH.rise = Separator.IN;
this.add(separatorH);
buttonOk = new Button();
buttonOk.setLabel("OK");
this.add(buttonOk);
// Geometry management
GridBagConstraints con = new GridBagConstraints();
reset(con);
con.gridx = 2;
con.gridy = 2;
con.gridwidth = 3;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.NONE;
grid.setConstraints(labelErrorMsg, con);
reset(con);
con.gridx = 2;
con.gridy = 3;
con.gridwidth = 3;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.BOTH;
grid.setConstraints(separatorH, con);
reset(con);
con.gridx = 3;
con.gridy = 4;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.HORIZONTAL;
grid.setConstraints(buttonOk, con);
// Resize behavior management and parent heirarchy
setLayout(grid);
//{{INIT_CONTROLS
addNotify();
//}}
int h=0,w=0;
for(int i=0;i<rowHeights.length;i++) h += rowHeights[i];
for(int i=0;i<columnWidths.length;i++) w += columnWidths[i];
resize(insets().left + insets().right + w, insets().top + insets().bottom + h);
//setResizable(false);
pack();
}
public synchronized void show() {
Rectangle bounds = getParent().bounds();
Rectangle abounds = bounds();
move(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
super.show();
}
public synchronized void wakeUp() {
notify();
}
public boolean handleEvent(Event event) {
if (event.id == Event.ACTION_EVENT && event.target == buttonOk) {
clickedButtonOk();
return true;
}
else
if (event.id == Event.WINDOW_DESTROY) {
hide();
dispose();
return true;
}
return super.handleEvent(event);
}
public void clickedButtonOk() {
hide();
dispose();
}
private void reset(GridBagConstraints con) {
con.gridx = GridBagConstraints.RELATIVE;
con.gridy = GridBagConstraints.RELATIVE;
con.gridwidth = 1;
con.gridheight = 1;
con.weightx = 0;
con.weighty = 0;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.NONE;
con.insets = new Insets(0, 0, 0, 0);
con.ipadx = 0;
con.ipady = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -