导航:首页 > 编程语言 > java中弹出一个对话框

java中弹出一个对话框

发布时间:2023-06-04 03:22:43

java编程:我想实现一个功能:点击下来菜单一个按钮时,弹出一个对话框

一个简单的例子。。。。importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;publicclassAextendsJFrame{privateAa;publicJLabellbl1;publicJLabellbl2;publicA(){lbl1=newJLabel("111111111");lbl2=newJLabel("222222222");JButtonbtnTest=newJButton("测试按钮");btnTest.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){newB(a).setVisible(true);}});setLayout(newGridLayout(1,3));add(lbl1);add(lbl2);add(btnTest);setSize(300,70);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);a=this;}publicstaticvoidmain(String[]args){newA().setVisible(true);}}classBextendsJFrame{privateAa;privateJTextFieldtxt1;privateJTextFieldtxt2;publicB(Aaa){a=aa;txt1=newJTextField();txt2=newJTextField();JButtonbtnTest=newJButton("测试按钮");btnTest.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){a.lbl1.setText(txt1.getText());a.lbl2.setText(txt2.getText());}});setLayout(newGridLayout(3,1));add(txt1);add(txt2);add(btnTest);setBounds(100,100,300,100);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}}===============有问题直接在这提问吧,说的清楚点就行了。我不要悬赏分

② java如何在线程中弹出对话框

1.显示一个错误对话框,该对话框显示的 message 为 'alert':

JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);

2.显示一个内部信息对话框,其 message 为 'information':

JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);

3.显示一个信息面板,其 options 为 "yes/no",message 为 'choose one':

JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);

4.显示一个内部信息对话框,其 options 为 "yes/no/cancel",message 为 'please choose one',并具有 title 信息:

JOptionPane.showInternalConfirmDialog(frame,
"please choose one", "information",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);

5.显示一个警告对话框,其 options 为 OK、CANCEL,title 为 'Warning',message 为 'Click OK to continue':

Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);

6.显示一个要求用户键入 String 的对话框:

String inputValue = JOptionPane.showInputDialog("Please input a value");

7.显示一个要求用户选择 String 的对话框:

Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);

③ JAVA怎么弹出对话框

需要引入下面的名称空间javax.swing.JOptionPane JOptionPane
public JOptionPane(Object message,
int messageType,
int optionType,
Icon icon,
Object[] options,
Object initialValue)在指定最初选择的选项的前提下,创建一个显示消息的 JOptionPane 的实例,使其具有指定的消息类型、图标和选项。

参数:
message – 要显示的 Object
messageType – 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE 或 PLAIN_MESSAGE
optionType – 要在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION
icon – 要显示的图标图像
options – 用户可以选择的选项
initialValue – 最初选择的选项;如果为 null,则不做最初选择;只有在使用 options 时才有意义

④ 用java编写一个程序,程序运行时弹出一个输入对话框,用户使用该对话

packagecn.fu;
importjava.awt.BorderLayout;
importjava.awt.EventQueue;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.border.EmptyBorder;
importjavax.swing.JOptionPane;
importjavax.swing.JTextField;
importjavax.swing.JLabel;
importjavax.swing.JButton;
importjava.awt.event.ActionListener;
importjava.awt.event.ActionEvent;
importjava.awt.Window.Type;
publicclassLoginextendsJFrame{
privateJPanelcontentPane;
privateJTextFieldtextField;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
Loginframe=newLogin();
frame.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
/**
*Createtheframe.
*/
publicLogin(){
setTitle("工具");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,300);
contentPane=newJPanel();
contentPane.setToolTipText("");
contentPane.setBorder(newEmptyBorder(5,5,5,5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField=newJTextField();
textField.setBounds(121,86,194,21);
contentPane.add(textField);
textField.setColumns(10);
JLabellblNewLabel=newJLabel("请输入10位数以内的字符串");
lblNewLabel.setBounds(145,59,194,15);
contentPane.add(lblNewLabel);
JButtonbtnNewButton=newJButton("确定");
btnNewButton.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
Stringca=textField.getText();
intn=ca.length();
if(n>10){
JOptionPane.showMessageDialog(null,"对不起,您输入的字符串长度超过10",
"错误提示",JOptionPane.ERROR_MESSAGE);
}elseif(n>=0||n<=10){
JOptionPane.showMessageDialog(null,"字符串长度为"+n,"提示",
JOptionPane.PLAIN_MESSAGE);
}
}
});
btnNewButton.setBounds(172,130,93,23);
contentPane.add(btnNewButton);
}
}

⑤ 在JAVA类中弹出js对话框

1:java程序
package org.elb.util;

public class JavaScriptDemo_1 {
public static String getJS(){
return "<script language=\"JavaScript\">alert(\"弹出框\")</script>";
}
}
2:JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

</head>

<body>
<jsp:useBean id="a" class="org.elb.util.JavaScriptDemo_1"></jsp:useBean>
<%=a.getJS() %>
</body>
</html>
想弹出什么来,就写什么就行了,明白了吗?

⑥ java怎么通过点击菜单弹出对话框

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class testMenuItem {
public static void main(String[] args) {
int x=200,y=200,width=400,height=400;
final JFrame j=new JFrame();
j.setLayout(new GridLayout(10, 1));
JMenuBar jb=new JMenuBar();
j.add(jb);
JMenu jm=new JMenu("菜单");
jb.add(jm);
JMenuItem jm1=new JMenuItem("选项1");
JMenuItem jm2=new JMenuItem("选项2");
JMenuItem jm3=new JMenuItem("选项3");
ActionListener al =new ActionListener(){
public void actionPerformed(ActionEvent e) {
String buttonString=e.getActionCommand();
if(buttonString.equals("选项1"))
JOptionPane.showMessageDialog(j, "您选择了 选项1");
else if(buttonString.equals("选项2"))
JOptionPane.showMessageDialog(j, "您选择了 选项2");
else if(buttonString.equals("选项3"))
JOptionPane.showMessageDialog(j, "您选择了 选项3");
}
};
jm1.addActionListener(al);
jm2.addActionListener(al);
jm3.addActionListener(al);

jm.add(jm1);
jm.add(jm2);
jm.add(jm3);
j.setBounds(x, y, width, height);
j.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
j.setVisible(true);

}

}

⑦ java中关于页面弹出对话框问题

if(JOptionPane.showConfirmDialog(null, "确定不通过此次家长会申请吗?", "提示", JOptionPane.OK_CANCEL_OPTION)==JOptionPane.OK_CANCEL_OPTION)==JOptionPane.YES_OPTION)或者下面

if(JOptionPane.showConfirmDialog(null, "确定不通过此次家长会申请吗?", "提示", JOptionPane.OK_CANCEL_OPTION)==0){
request.getRequestDispatcher("/AppAudit.jsp").forward(request, response);
}else{
request.getRequestDispatcher("/a.jsp").forward(request, response);
}
方法签名:
showConfirmDialog

public static int showConfirmDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType)
throws HeadlessException
调用一个由 optionType 参数确定其中选项数的对话框,messageType 参数确定要显示的图标。messageType 参数主要用于提供来自外观的默认图标。
参数:
parentComponent - 确定在其中显示对话框的 Frame;如果为 null 或者 parentComponent 不具有 Frame,则使用默认的 Frame。
message - 要显示的 Object
title - 对话框的标题字符串
optionType - 指定可用于对话框的选项的整数:YES_NO_OPTION 或 YES_NO_CANCEL_OPTION
messageType - 指定此消息种类的整数;主要用于确定来自可插入外观的图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE 或 PLAIN_MESSAGE
返回:
指示用户所选选项的整数

源码如下:
public class JOptionPane extends JComponent implements Accessible
{
public static final int YES_OPTION = 0;
/** Return value from class method if NO is chosen. */
public static final int NO_OPTION = 1;
/** Return value from class method if CANCEL is chosen. */
public static final int CANCEL_OPTION = 2;
/** Return value form class method if OK is chosen. */
public static final int OK_OPTION = 0;
/** Return value from class method if user closes window without selecting
* anything, more than likely this should be treated as either a
* <code>CANCEL_OPTION</code> or <code>NO_OPTION</code>. */
public static final int CLOSED_OPTION = -1;
}

阅读全文

与java中弹出一个对话框相关的资料

热点内容
彩视制作教程 浏览:766
圣墟在哪个App看免费 浏览:395
网络哪些不能玩 浏览:868
probe315使用教程 浏览:646
数字电位器程序 浏览:198
c代码整理 浏览:104
网络营销具有什么优势 浏览:378
右下角网络连接不显示宽带连接 浏览:940
ps修改tif文件 浏览:580
预防医学如何转行做大数据 浏览:234
pdf文件变蓝 浏览:309
怎么在pdf文件上面用k宝签名 浏览:213
如何知道表格里数据后面有空格 浏览:720
gee引擎更新系统找不到指定文件 浏览:802
贝壳网的数据删除了如何找回 浏览:509
华为荣耀6x怎么切换网络 浏览:418
手机里的pdf文件在哪放 浏览:889
java版贪吃蛇毕业论文 浏览:989
微信公共号邮箱 浏览:415
图片宽度代码 浏览:460

友情链接