public class FrameMessageboxDemo extends JFrame
{
private static final long serialVersionUID = 1L;
private JButton[] b = {new JButton("确认"), new JButton("警告"), new JButton("爱好"), new JButton("录入爱好"),
new JButton("选择爱好")};
private JTextField textField = new JTextField(20);
private ActionListener al = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
String id = ((JButton)e.getSource()).getText();
if ("警告".equals(id))
{
JOptionPane.showMessageDialog(null, "系统运行期间出现了错误,请与程序员联系!", "系统提示!", JOptionPane.ERROR_MESSAGE);
}
else if ("确认".equals(id))
{
JOptionPane.showConfirmDialog(null, "你确认退出系统吗?", "系统提示!", JOptionPane.YES_NO_OPTION);
}
else if ("爱好".equals(id))
{
Object[] options = {"协作", "政治官僚"};
int sel = JOptionPane.showOptionDialog(null,
"请选择您的爱好!",
"系统提示!",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
options,
options[0]);
if (sel != JOptionPane.CLOSED_OPTION)
{
textField.setText("您选择的个人爱好为:" + options[sel]);
}
}
else if ("录入爱好".equals(id))
{
String val = JOptionPane.showInputDialog("您爱好什么?");
textField.setText(val);
}
else if ("选择爱好".equals(id))
{
Object[] selections = {"写作", "政治", "军事"};
// JOptionPane.INFORMATION_MESSAGE :选择框的形式显示
Object val = JOptionPane.showInputDialog(null,
"请输入您的爱好",
"系统提示",
JOptionPane.INFORMATION_MESSAGE,
null,
selections,
selections[0]);
if (val != null)
{
textField.setText(val.toString());
}
}
}
};
private FlowLayout flowLayout = new FlowLayout();
private JLabel label = new JLabel();
private void jbInit()
throws Exception
{
Container cop = this.getContentPane();
cop.setLayout(flowLayout);
for (int i = 0; i < b.length; i++)
{
b[i].addActionListener(al);
cop.add(b[i]);
}
this.setTitle("消息框(Message box)");
label.setText("显示消息");
cop.add(textField, null);
cop.add(label);
}
public FrameMessageboxDemo()
{
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
FrameMessageboxDemo frame = new FrameMessageboxDemo();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
分享到:
相关推荐
变压器变频器配电柜电路控制原理图CAD施工图纸设备控制图恒温烘房电气控制柜原理图120KW
使用R语言的jiebaR包的情感分析_jiebaR_emotion
springboot基于双因素身份认证的学生社团管理系统论文
鳄梨酱guacamole:1.5.5和guacd:1.5.5容器
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手
小程序&小工具类&生活圈(源码+截图+源码导入教程和视频).zip
记录r语言单细胞学习_Single-cell
本项目是基于Javascript开发的微信小程序电影资讯平台,包含44个文件,其中包括10个JavaScript脚本文件、9个JSON配置文件、8个WXSS样式表文件、6个WXML页面文件、4个PNG图像文件、1个EOT字体文件、1个SVG矢量图文件、1个TTF字体文件、1个WOFF字体文件和1个WOFF2字体文件。该项目旨在为用户提供一个便捷、高效的电影资讯浏览和搜索平台,支持电影信息展示、分类查询、用户评价等功能,以提升用户体验和互动性。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手
变压器变频器配电柜电路控制原理图CAD施工图纸设备控制图控制室平面布置图
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手
本项目是基于Java开发的飞滴出行网约车2022,包含81个文件,其中包括52个Java源代码文件、11个XML配置文件、8个gitignore文件、5个YAML配置文件、3个HTML页面文件和2个Markdown文档文件。该项目旨在为用户提供一个便捷、高效的网约车服务平台,支持乘客下单、司机接单、行程跟踪等功能,以提升用户体验和运营效率。
NBA决策树R语言实践_NBA-decision-tree
解决oracle退格键乱码问题
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手
一个R语言的数据分析及可视化_R_Language_analysis_visualization
STM32F4使用通用定时器生成PWM和脉冲(只有干货、注释详细、附程序包)
包含 1)系统的文档教程 2)实例讲义 3)模型源文件 DesignModeler(简称DM)是ANSYS Workbench中的一个重要模块,它主要用于几何模型的创建、修复、简化和前处理。以下是对DesignModeler的详细介绍: 一、主要功能 全参数化实体建模:DesignModeler支持全参数化建模,用户可以通过设置参数来控制模型的尺寸和形状,便于后续的优化分析和数据传递。 CAD模型修复与简化:从CAD软件导入的模型可能存在细节缺失或错误,DesignModeler提供了多种工具来修复这些问题,并可以对模型进行简化,以提高计算效率。 概念建模:DesignModeler还具备概念建模功能,如创建梁模型或面(壳体)概念模型,为后续的有限元分析提供基础。 前处理功能:包括对几何模型的修改、分割、中面抽取等,为后续的网格划分和仿真分析做好准备。
华为杯《统计学习方法-李航》200页PDF手推公式细节讲解,包含详细的目录以及R语言代码实现,可结合《统_statistic-learning-R-note.zip