java如何遍历combobox_如何通过COMBOBOX设置Java中的框架标题?

我想创建类似下图的内容,当用户从组合框选项中选择年份、月份和日期时,这些操作将更改标题,并且必须根据所选数据进行更改,这很简单,我还是新手

到目前为止,我已经做到了,问题是它不起作用,我怎么能做到呢?,你能帮我一下吗?

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class DateForm_Complete extends JFrame {

private JLabel year, month, day;

private JComboBox cmonth, cday, cyear;

public DateForm_Complete() {

setTitle("Date Selection");

setSize(400,100);

setupWidgets();

setVisible(true);

}

private void setupWidgets() {

year= new JLabel("Year");

month= new JLabel("Month");

day= new JLabel("Day");

cyear= new JComboBox();

cmonth= new JComboBox();

cday= new JComboBox();

setLayout(new GridLayout (2,3));

add(year); add(month); add(day);

add(cyear); add(cmonth); add(cday);

for (int i=1900; i<2019; i++)

{

cyear.addItem(i);

}

String months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

for (int i=0; i<12; i++)

{

cmonth.addItem(months[i]);

}

for (int i=1; i<32; i++)

{

cday.addItem(i);

}

setupEvents();

}

private void setupEvents() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

cyear.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent ev) {

JComboBox combo = (JComboBox)ev.getSource();

String texty = (String)combo.getSelectedItem();

}

});

cmonth.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent ev) {

JComboBox combo = (JComboBox)ev.getSource();

String textm = (String)combo.getSelectedItem();

}

});

cday.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent ev) {

JComboBox combo = (JComboBox)ev.getSource();

String textd = (String)combo.getSelectedItem();

}

});

setTitle("Today is "+ texd+ "of "+ textm + "of " +texty);

}

public static void main(String[] args) {

new DateForm_Complete();

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541057.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

为什么公司要努力发展数字化战略

发现自身数字化滞后的公司正在遭受因为在二十年前所做的战略决策的煎熬。这里我们将阐述如何才能迎头赶上。 发展数字化战略的公司正在努力促进转型&#xff0c;因为大多数首席信息官(CIO)还没有能力成为数字化领导者。根据Caldwell Partners公司的技术、数字和数据领导事务的管…

java scanner_Java Scanner radix()方法与示例

java scanner扫描器类radix()方法 (Scanner Class radix() method) radix() method is available in java.util package. radix()方法在java.util包中可用。 radix() method is used to return the default or implicit radix of this Scanner. radix()方法用于返回此Scanner的…

java用mysql存储图片_Java存储图片到Mysql

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼【1】视图层action"${ctx}/web/UserInforServlet?methoduserInforServlet" >更换头像立即提交重置var layer,upload,form;//1-页面数据加载$(function () {//【1】加载&初始化layui模块-弹出层与table数据表格la…

ITU衡量信息社会报告:我国ICT发展指数进入亚太前十

11月22日&#xff0c;国际电信联盟&#xff08;ITU&#xff09;发布2016版《衡量信息社会报告》&#xff0c;公布了最新国家和地区ICT发展指数&#xff08;IDI&#xff09;。《报告》显示&#xff0c;排在前十位的国家和地区均来自欧洲和亚洲&#xff0c;韩国以0.01分的优势再次…

treeset java_Java TreeSet clear()方法与示例

treeset javaTreeSet类的clear()方法 (TreeSet Class clear() method) clear() method is available in java.util package. clear()方法在java.util包中可用。 clear() method is used to clear all of the objects that exist from this TreeSet. clear()方法用于清除此TreeS…

Facebook也大干新闻聚合 “新闻快读”向所有媒体开放

去年五月&#xff0c;Facebook推出了不离开本站直接阅读新闻的聚合服务“新闻快读”&#xff08;Instant Articles&#xff09;&#xff0c;用户载入文章的速度大增&#xff0c;不过当时只面向一些特定合作的新闻机构。日前&#xff0c;这一聚合服务全面开始接纳所有的新闻媒体…

kafka偏移量保存到mysql里_【队列】调试应用时进行的kafka偏移量调整

# KAFKA操作记录##export BASE_DIR/home/dba/kafkaexport SERVERS1.1.1.1:9092cd ${BASE_DIR}/bin# 删除残留的消费者./kafka-consumer-groups.sh --bootstrap-server $SERVERS --group DBAAlertSplash --delete --command-config ${BASE_DIR}/config/client.properties# 这个在…

java scanner_Java Scanner match()方法与示例

java scanner扫描器类match()方法 (Scanner Class match() method) match() method is available in java.util package. match()方法在java.util包中可用。 match() method is used to get the MatchResult of the last scanning operation operated by this Scanner. match()…

苹果再次拒绝协助美国政府解锁纽约毒品案中的iPhone

继美国联邦调查局(FBI)成功解锁圣贝纳迪诺市恐袭案枪手 Syed Farook所使用的iPhone 5c后&#xff0c;美国司法部已撤回对苹果公司采取的法律行动。然而近日美国司法部宣布&#xff0c;将继续要求苹果公司协助解锁一部在纽约毒品调查案中查获的iPhone 5s手机。不过苹果今天向美国…

openssl java aes_请问如何使用AES对使用OpenSSL命令加密的Java文件进行解密?

以下是OpenSSLPBEInputStream和OpenSSLPBEOutputStream它可以用于以与OpenSSL兼容的方式加密/解密任意字节流。示例用法&#xff1a;// The original clear text bytesbyte[] originalBytes ...// Encrypt these byteschar[] pwd "thePassword".toCharArray();Byte…

Java ArrayList set()方法与示例

ArrayList类set()方法 (ArrayList Class set() method) set() method is available in java.util package. set()方法在java.util包中可用。 set() method is used to replace the element at the given indices with the given ele(element) in this Arraylist. set()方法用于…

《R的极客理想—工具篇》—— 第2章 时间序列基础包

本节书摘来自华章出版社《R的极客理想—工具篇》一 书中的第2章&#xff0c;作者&#xff1a;张丹&#xff0c;更多章节内容可以访问云栖社区“华章计算机”公众号查看。 第2章 时间序列基础包 本章主要介绍了时间序列数据处理的3个工具包&#xff0c;帮助读者掌握时间序列在R语…

java结构设计_Java基本的程序设计结构(一)

前言&#xff1a;虽然说学过设计模式&#xff0c;J2EE&#xff0c;这个学期才开始学Java&#xff0c;呵呵&#xff0c;有点颠倒了&#xff0c;但是还是要从基本的抓起。hoho&#xff5e;&#xff5e;(一)一个简单的java应用程序Package edu.ynu.java.lession1/*The simplest Ja…

Java ArrayList get()方法与示例

ArrayList类的get()方法 (ArrayList Class get() method) get() method is available in java.util package. get()方法在java.util包中可用。 get() method is used to retrieve the element at the given index in this Arraylist. get()方法用于检索此Arraylist中给定索引处…

第三方应用商店仍为用户获取APP主渠道 细分市场或成新增长点

近年来&#xff0c;在应用分发市场领域随着渠道多元化趋势日渐显现&#xff0c;第三方应用商店似乎已经显得乏善可陈&#xff0c;缺少亮点。事实上&#xff0c;根据比达咨询(Big Data-Research)发布的《2016年第一季度中国第三方应用商店市场研究报告》显示&#xff0c;第三方应…

java反射 动态调用_java反射拼接方法名动态执行方法

近期由于负责项目的一个模块,该模块下有很多分类,每个分类都有一个编码code,这个值是作为一个参数携带过来的.但是每个code确实对应一个方法的.code的值有很多个,自己又不想做ifelse或者switch判断于是就狂搜资料,主要让我发现利用java的反射机制可以完美的解决这个问题测试代码…

Python | Lambda函数与示例

With the help of lambda function, we can create one line function definition. 借助lambda函数&#xff0c;我们可以创建一个行函数定义。 Note: Function must have return type and parameter 注意&#xff1a;函数必须具有返回类型和参数 Example: 例&#xff1a; Co…

使用大数据闪存打造融合数据平台

随着企业、服务提供商和超大型数据中心从描述性分析向预测性和规范性分析演进&#xff0c;结合了融合运营和分析数据管道的融合数据平台变得日益重要。大数据闪存可让数据处理平台快速访问历史数据和实时数据流&#xff0c;从而以较低成本创建有效的预测模型。 随着大数据从描述…

stl min函数_std :: min()函数以及C ++ STL中的示例

stl min函数C STL std :: min()函数 (C STL std::min() function) min() function is a library function of algorithm header, it is used to find the smallest value from given two values, it accepts two values and returns the smallest value and if both the value…

c# uri.host_C#| Uri.FromHex()方法与示例

c# uri.hostUri.FromHex()方法 (Uri.FromHex() Method) Uri.FromHex() method is a static method that returns an integer that represents a decimal digit of specified hex char. Uri.FromHex()方法是一个静态方法&#xff0c;该方法返回一个整数&#xff0c;该整数表示指…