|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
可以继承UIDialog类来自己“画”一个个性的对话框,具体的空间使用参照Swing的使用
一下给个例子
一 画界面
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import nc.ui.pub.beans.UIDialog;
public class QueryDialog extends UIDialog implements ActionListener {
private nc.ui.pub.beans.UIButton UIButtonComm = null;//按钮
private nc.ui.pub.beans.UIButton UIButtonCanel = null;
private javax.swing.JPanel ivjUIDialogContentPane = null;//主pane
private nc.ui.pub.beans.UILabel UILabel1 = null;//标签
private nc.ui.pub.beans.UILabel UILabel2 = null;
private nc.ui.pub.beans.UILabel UILabel3 = null;
private nc.ui.pub.beans.UIComboBox ComboBoxto = null;//下拉
private nc.ui.pub.beans.UITextField chooseField = null;//文本框
private String value = null;//使用value变量来告诉外界是点击什么按钮
@SuppressWarnings("deprecation")
public QueryDialog() {
super();
initialize();
}
// 初始话
private void initialize() {
setName("QueryDialog");
this.setTitle("查询条件");//设置标题
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//关闭就退出
setSize(330, 180);//大小
setContentPane(getUIDialogContentPane());//主panne
getUIButtonComm().addActionListener(this);//两个按钮添加监听
getUIButtonCanel().addActionListener(this);//
}
// 按钮的初始
private nc.ui.pub.beans.UIButton getUIButtonComm() {
if (UIButtonComm == null) {
UIButtonComm = new nc.ui.pub.beans.UIButton();
UIButtonComm.setName("UIButtonComm");
UIButtonComm.setText("确定");
UIButtonComm.setBounds(90, 110, 55, 22);
}
return UIButtonComm;
}
// 按钮初始
private nc.ui.pub.beans.UIButton getUIButtonCanel() {
if (UIButtonCanel == null)
UIButtonCanel = new nc.ui.pub.beans.UIButton();
UIButtonCanel.setName("UIButtonCanel");
UIButtonCanel.setText("取消");
UIButtonCanel.setBounds(170, 110, 55, 22);
return UIButtonCanel;
}
// 增加按钮等工作,主panne的初始
private javax.swing.JPanel getUIDialogContentPane() {
if (ivjUIDialogContentPane == null) {
ivjUIDialogContentPane = new javax.swing.JPanel();
ivjUIDialogContentPane.setName("UIDialogContentPane"); //名称
ivjUIDialogContentPane.setLayout(null);//布局
getUIDialogContentPane().add(getUIButtonComm(),
getUIButtonComm().getName()); //按钮
getUIDialogContentPane().add(getUIButtonCanel(),
getUIButtonCanel().getName()); //按钮
getUIDialogContentPane()
.add(getUILabel1(), getUILabel1().getName()); //
getUIDialogContentPane()
.add(getUILabel2(), getUILabel2().getName()); //
getUIDialogContentPane()
.add(getUILabel3(), getUILabel3().getName()); //标签
getUIDialogContentPane().add(getComboBoxto(),
getComboBoxto().getName()); //下拉
getUIDialogContentPane().add(getUITextField(),
getUITextField().getName()); //文本
}
return ivjUIDialogContentPane;
}
private Component getUILabel1() {//标签初始
if (UILabel1 == null) {
UILabel1 = new nc.ui.pub.beans.UILabel();
UILabel1.setName("Label1");
UILabel1.setText("查询条件:");
UILabel1.setBounds(10, 15, 60, 20);
}
return UILabel1;
}
private Component getUILabel2() {
if (UILabel2 == null) {
UILabel2 = new nc.ui.pub.beans.UILabel();
UILabel2.setName("Label2");
UILabel2.setText("从第");
UILabel2.setBounds(20, 55, 40, 20);
}
return UILabel2;
}
private Component getUILabel3() {
if (UILabel3 == null) {
UILabel3 = new nc.ui.pub.beans.UILabel();
UILabel3.setName("Label3");
UILabel3.setText("位开始的查询值为:");
UILabel3.setBounds(110, 55, 100, 20);
}
return UILabel3;
}
private Component getComboBoxto() {//下拉初始
if (ComboBoxto == null) {
ComboBoxto = new nc.ui.pub.beans.UIComboBox();
DefaultComboBoxModel invalue = new DefaultComboBoxModel(
new String[] { "1", "2", "3", "4", "5", "6", "7", "8" });
ComboBoxto.setModel(invalue);
ComboBoxto.setName("ComboBoxto");
ComboBoxto.setBounds(60, 55, 40, 20);
}
return ComboBoxto;
}
private Component getUITextField() {//文本初始
if (chooseField == null) {
chooseField = new nc.ui.pub.beans.UITextField();
chooseField.setName("chooseField");
chooseField.setBounds(220, 55, 80, 20);
}
return chooseField;
}
public void actionPerformed(ActionEvent e) {//点击按钮时调用
if (e.getSource() == getUIButtonComm()) {
value = UIButtonComm.getText();
getPriceVo();
this.closeOK();
}
if (e.getSource() == getUIButtonCanel()) {
value = UIButtonCanel.getText();
this.closeOK();
}
}
public String[] getPriceVo() {//确认是调用
String[] values = new String[2];
String ComboBoxt = ComboBoxto.getSelectdItemValue() == null ? ""
: ComboBoxto.getSelectdItemValue().toString();
String chooseF = chooseField.getText();
values[0] = ComboBoxt;
values[1] = chooseF;
return values;
}
public String getOkCanel() {//取消时调用
return value;
}
}
画出的结果如下:
二 使用对话框
一般这个对话框在点击某个按钮是弹出,所以在某个按钮处理方法里使用以下代码处理业务
QueryDialog dialog = new QueryDialog(); //new 一个
dialog.showModal(); //显示
String OkorNo=dialog.getOkCanel()==null?"":dialog.getOkCanel();//按钮点击判断
if(OkorNo.equals("")||OkorNo.equals("取消")){ //如果没有点击或点击取消则退出
return;
}
String[] queryConditon=dialog.getPriceVo();//否者,取得参数,进行业务操作
备注:
对对话框的初始是和Swing相同,可以参照Swing的使用来使用它 |
|