用模态的方式打开自定义JDialog,并获取返回值
来源:互联网 发布:淘宝搜索权重模型 编辑:程序博客网 时间:2024/06/06 16:51
JFrame的变量名为jf
JDialog的类名为Fff
btnLoadImage.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {Fff myff = new Fff();//myff.setModal(false);myff.setModalityType(ModalityType.APPLICATION_MODAL);myff.setVisible(true);//如果是点击确定,则文本框中输入的内容显示出来String strText;int iReturn;iReturn = myff.f_GetCoseType();if (iReturn == 0) {lbImage.setText("选择了取消");}else{strText = myff.f_GetText();lbImage.setText(strText);}}});
Fff的类
package bb;import java.awt.BorderLayout;import java.awt.FlowLayout;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JTextField;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;/** * @author 作者 E-mail: * @version 创建时间:Sep 18, 2017 2:48:29 PM * 类说明 */public class Fff extends JDialog {private final JPanel contentPanel = new JPanel();private JTextField textOut;private int iCloseType; //点击确定,该值为1,点击取消,该值为0/** * Launch the application. */public static void main(String[] args) {try {Fff dialog = new Fff();dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);} catch (Exception e) {e.printStackTrace();}}/** * Create the dialog. */public Fff() {iCloseType = 0 ;//默认是点击取消按钮setBounds(100, 100, 450, 300);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));getContentPane().add(contentPanel, BorderLayout.CENTER);contentPanel.setLayout(new BorderLayout(0, 0));{JPanel panel = new JPanel();contentPanel.add(panel);panel.setLayout(new BorderLayout(0, 0));{textOut = new JTextField();panel.add(textOut, BorderLayout.NORTH);textOut.setColumns(10);}}{JPanel buttonPane = new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane, BorderLayout.SOUTH);{JButton okButton = new JButton("OK");okButton.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {//检查用户是否输入了内容if(f_chkInput()) {iCloseType = 1;//点击了确定性按钮dispose();}}});okButton.setActionCommand("OK");buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);}{JButton cancelButton = new JButton("Cancel");cancelButton.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {iCloseType = 0;//点击了取消按钮dispose();}});cancelButton.setActionCommand("Cancel");buttonPane.add(cancelButton);}}}//检查用户是否输入了文本public boolean f_chkInput() { String strText; boolean bRet;strText = textOut.getText();if ( strText.length()==0 || strText==null) {JOptionPane jMsg = new JOptionPane();jMsg.showMessageDialog(null, "请输入内容");bRet = false;}else{bRet = true;}return bRet;}public int f_GetCoseType() {return iCloseType;}public String f_GetText() {String strOut;strOut = textOut.getText();return strOut;}}
阅读全文
0 0
- 用模态的方式打开自定义JDialog,并获取返回值
- 继承Dialog、 JDialog 获取返回值
- 关于JDialog将值返回给父窗口的方法
- window.open打开窗口并获取返回值例子
- .net 从WebService的restful api接口以POST方式请求并获取返回值
- fetch API获取返回值的方式
- K3打开序时簿,并返回选中的值
- 自定义打开Reflector的方式
- java调用webservice天气预报(SOAP请求的方式获取天气信息并解析返回的XML)
- java调用webservice天气预报(SOAP请求的方式获取天气信息并解析返回的XML)
- java调用webservice天气预报(SOAP请求的方式获取天气信息并解析返回的XML)
- Android之开启新的activity并获取返回值
- 前端两种跨域传值并获取返回值的方法
- android post方式传递参数并获取返回数据代码
- 【备忘】:fetch API获取返回值的方式
- SpringMVC 拦截返回值,并自定义
- react 获取属性的正确打开方式
- Android之从网络中获取数据并返回客户端的两种方式:XML格式返回与Json格式返回
- 运算符++的暴击
- Floating Action Button 简单使用
- Java对象和类的详解
- jsp网上商城jsp课程设计
- 浅谈PSR规范与PHP框架中类的自动加载原理
- 用模态的方式打开自定义JDialog,并获取返回值
- 微信JSAPI支付开发说明和注意事项
- JavaScript基础之层级选择器
- Android模块化开发探索
- 强化学习之Policy Gradient
- 1. linux C -- 进程锁
- SDWebImage的使用
- System 命名空间
- dubbo 后台管理dubbo-admin