- 浏览: 42389 次
- 性别:
- 来自: 苏州
最新评论
-
jijiajia19:
...
Nexus 2.0.5 私人服务器构建 -
senhui19:
非常感谢,收藏啦。
JAVA SWING 日期选择控件(目前支持JLable和JTextField,若有需要可自行扩展其它控件) -
一碗单炒饭:
拿来用了,谢谢谢谢
JAVA SWING 日期选择控件(目前支持JLable和JTextField,若有需要可自行扩展其它控件) -
神恰恰:
高手啊 厉害 现在抄了一份 正用着
JAVA SWING 日期选择控件(目前支持JLable和JTextField,若有需要可自行扩展其它控件) -
lin714916927:
...
JAVA SWING 日期选择控件(目前支持JLable和JTextField,若有需要可自行扩展其它控件)
package com.dzg.ticket.util;
/**
* ClassName:DateChooser
* Copyright: copyright (c)2012
* @author Deng Zhiguang
* @Date 2012-2-7
* Modification History:
* Date Author Version Reason
* ------------------------------------------
*/
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
/**
* 日期选择器,可以指定日期的显示格式
*/
public class DateChooser extends JPanel {
private static final long serialVersionUID = 4529266044762990227L;
private Date initDate;
private Calendar now = Calendar.getInstance();
private Calendar select;
private JPanel monthPanel;//月历
private JP1 jp1;//四块面板,组成
private JP2 jp2;
private JP3 jp3;
private JP4 jp4;
private Font font = new Font("宋体", Font.PLAIN, 12);
private final LabelManager lm = new LabelManager();
private SimpleDateFormat sdf;
private boolean isShow = false;
private Popup pop;
private JComponent showDate;
public static DateChooser getInstance() {
return new DateChooser();
}
public static DateChooser getInstance(Date date) {
return new DateChooser(date);
}
public static DateChooser getInstance(String format) {
return new DateChooser(format);
}
public static DateChooser getInstance(Date date, String format) {
return new DateChooser(date, format);
}
/**
* Creates a new instance of DateChooser
*/
private DateChooser() {
this(new Date());
}
private DateChooser(Date date) {
this(date, "yyyy年MM月dd日");
}
private DateChooser(String format) {
this(new Date(), format);
}
private DateChooser(Date date, String format) {
initDate = date;
sdf = new SimpleDateFormat(format);
select = Calendar.getInstance();
select.setTime(initDate);
initPanel();
}
/**
* 是否允许用户选择
*/
public void setEnabled(boolean b) {
super.setEnabled(b);
showDate.setEnabled(b);
}
/**
*得到当前选择框的日期
*/
public Date getDate() {
return select.getTime();
}
public String getStrDate() {
return sdf.format(select.getTime());
}
public String getStrDate(String format) {
sdf = new SimpleDateFormat(format);
return sdf.format(select.getTime());
}
//根据初始化的日期,初始化面板
private void initPanel() {
monthPanel = new JPanel(new BorderLayout());
monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE));
JPanel up = new JPanel(new BorderLayout());
up.add(jp1 = new JP1(), BorderLayout.NORTH);
up.add(jp2 = new JP2(), BorderLayout.CENTER);
monthPanel.add(jp3 = new JP3(), BorderLayout.CENTER);
monthPanel.add(up, BorderLayout.NORTH);
monthPanel.add(jp4 = new JP4(), BorderLayout.SOUTH);
this.addAncestorListener(new AncestorListener() {
public void ancestorAdded(AncestorEvent event) {
}
public void ancestorRemoved(AncestorEvent event) {
}
//只要祖先组件一移动,马上就让popup消失
public void ancestorMoved(AncestorEvent event) {
hidePanel();
}
});
}
public void register(final JComponent showDate) {
this.showDate = showDate;
showDate.setRequestFocusEnabled(true);
showDate.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
showDate.requestFocusInWindow();
}
});
this.setBackground(Color.WHITE);
this.add(showDate, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(90, 25));
this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
showDate.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
if (showDate.isEnabled()) {
showDate.setCursor(new Cursor(Cursor.HAND_CURSOR));
showDate.setForeground(Color.RED);
}
}
public void mouseExited(MouseEvent me) {
if (showDate.isEnabled()) {
showDate.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
showDate.setForeground(Color.BLACK);
}
}
public void mousePressed(MouseEvent me) {
if (showDate.isEnabled()) {
showDate.setForeground(Color.CYAN);
if (isShow) {
hidePanel();
} else {
showPanel(showDate);
}
}
}
public void mouseReleased(MouseEvent me) {
if (showDate.isEnabled()) {
showDate.setForeground(Color.BLACK);
}
}
});
showDate.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
hidePanel();
}
public void focusGained(FocusEvent e) {
}
});
}
//根据新的日期刷新
private void refresh() {
jp1.updateDate();
jp2.updateDate();
jp3.updateDate();
jp4.updateDate();
SwingUtilities.updateComponentTreeUI(this);
}
//提交日期
private void commit() {
//TODO add other components here
if (showDate instanceof JTextField) {
((JTextField) showDate).setText(sdf.format(select.getTime()));
}else if (showDate instanceof JLabel) {
((JLabel) showDate).setText(sdf.format(select.getTime()));
}
hidePanel();
}
//隐藏日期选择面板
private void hidePanel() {
if (pop != null) {
isShow = false;
pop.hide();
pop = null;
}
}
//显示日期选择面板
private void showPanel(Component owner) {
if (pop != null) {
pop.hide();
}
Point show = new Point(0, showDate.getHeight());
SwingUtilities.convertPointToScreen(show, showDate);
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
int x = show.x;
int y = show.y;
if (x < 0) {
x = 0;
}
if (x > size.width - 295) {
x = size.width - 295;
}
if (y < size.height - 170) {
} else {
y -= 188;
}
pop = PopupFactory.getSharedInstance().getPopup(owner, monthPanel, x, y);
pop.show();
isShow = true;
}
/**
* 最上面的面板用来显示月份的增减
*/
private class JP1 extends JPanel {
private static final long serialVersionUID = -5638853772805561174L;
JLabel yearleft, yearright, monthleft, monthright, center, centercontainer;
public JP1() {
super(new BorderLayout());
this.setBackground(new Color(160, 185, 215));
initJP1();
}
private void initJP1() {
yearleft = new JLabel(" <<", JLabel.CENTER);
yearleft.setToolTipText("上一年");
yearright = new JLabel(">> ", JLabel.CENTER);
yearright.setToolTipText("下一年");
yearleft.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
yearright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
monthleft = new JLabel(" <", JLabel.RIGHT);
monthleft.setToolTipText("上一月");
monthright = new JLabel("> ", JLabel.LEFT);
monthright.setToolTipText("下一月");
monthleft.setBorder(BorderFactory.createEmptyBorder(2, 30, 0, 0));
monthright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30));
centercontainer = new JLabel("", JLabel.CENTER);
centercontainer.setLayout(new BorderLayout());
center = new JLabel("", JLabel.CENTER);
centercontainer.add(monthleft, BorderLayout.WEST);
centercontainer.add(center, BorderLayout.CENTER);
centercontainer.add(monthright, BorderLayout.EAST);
this.add(yearleft, BorderLayout.WEST);
this.add(centercontainer, BorderLayout.CENTER);
this.add(yearright, BorderLayout.EAST);
this.setPreferredSize(new Dimension(295, 25));
updateDate();
yearleft.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
yearleft.setCursor(new Cursor(Cursor.HAND_CURSOR));
yearleft.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me) {
yearleft.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
yearleft.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me) {
select.add(Calendar.YEAR, -1);
yearleft.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me) {
yearleft.setForeground(Color.BLACK);
}
});
yearright.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
yearright.setCursor(new Cursor(Cursor.HAND_CURSOR));
yearright.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me) {
yearright.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
yearright.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me) {
select.add(Calendar.YEAR, 1);
yearright.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me) {
yearright.setForeground(Color.BLACK);
}
});
monthleft.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
monthleft.setCursor(new Cursor(Cursor.HAND_CURSOR));
monthleft.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me) {
monthleft.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
monthleft.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me) {
select.add(Calendar.MONTH, -1);
monthleft.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me) {
monthleft.setForeground(Color.BLACK);
}
});
monthright.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
monthright.setCursor(new Cursor(Cursor.HAND_CURSOR));
monthright.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me) {
monthright.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
monthright.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me) {
select.add(Calendar.MONTH, 1);
monthright.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me) {
monthright.setForeground(Color.BLACK);
}
});
}
private void updateDate() {
center.setText(select.get(Calendar.YEAR) + "年" + (select.get(Calendar.MONTH) + 1) + "月");
}
}
private class JP2 extends JPanel {
private static final long serialVersionUID = -8176264838786175724L;
public JP2() {
this.setPreferredSize(new Dimension(295, 20));
}
protected void paintComponent(Graphics g) {
g.setFont(font);
g.drawString("星期日 星期一 星期二 星期三 星期四 星期五 星期六", 5, 10);
g.drawLine(0, 15, getWidth(), 15);
}
private void updateDate() {
}
}
private class JP3 extends JPanel {
private static final long serialVersionUID = 43157272447522985L;
public JP3() {
super(new GridLayout(6, 7));
this.setPreferredSize(new Dimension(295, 100));
initJP3();
}
private void initJP3() {
updateDate();
}
public void updateDate() {
this.removeAll();
lm.clear();
Date temp = select.getTime();
Calendar select = Calendar.getInstance();
select.setTime(temp);
select.set(Calendar.DAY_OF_MONTH, 1);
int index = select.get(Calendar.DAY_OF_WEEK);
int sum = (index == 1 ? 8 : index);
select.add(Calendar.DAY_OF_MONTH, 0 - sum);
for (int i = 0; i < 42; i++) {
select.add(Calendar.DAY_OF_MONTH, 1);
lm.addLabel(new MyLabel(select.get(Calendar.YEAR), select.get(Calendar.MONTH), select.get(Calendar.DAY_OF_MONTH)));
}
for (MyLabel my : lm.getLabels()) {
this.add(my);
}
select.setTime(temp);
}
}
private class MyLabel extends JLabel implements Comparator<MyLabel>, MouseListener, MouseMotionListener {
private static final long serialVersionUID = 3668734399227577214L;
private int year, month, day;
private boolean isSelected;
public MyLabel(int year, int month, int day) {
super("" + day, JLabel.CENTER);
this.year = year;
this.day = day;
this.month = month;
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.setFont(font);
if (month == select.get(Calendar.MONTH)) {
this.setForeground(Color.BLACK);
} else {
this.setForeground(Color.LIGHT_GRAY);
}
if (day == select.get(Calendar.DAY_OF_MONTH)) {
this.setBackground(new Color(160, 185, 215));
} else {
this.setBackground(Color.WHITE);
}
}
public boolean getIsSelected() {
return isSelected;
}
public void setSelected(boolean b, boolean isDrag) {
isSelected = b;
if (b && !isDrag) {
int temp = select.get(Calendar.MONTH);
select.set(year, month, day);
if (temp == month) {
SwingUtilities.updateComponentTreeUI(jp3);
} else {
refresh();
}
}
this.repaint();
}
protected void paintComponent(Graphics g) {
if (day == select.get(Calendar.DAY_OF_MONTH) && month == select.get(Calendar.MONTH)) {
//如果当前日期是选择日期,则高亮显示
g.setColor(new Color(160, 185, 215));
g.fillRect(0, 0, getWidth(), getHeight());
}
if (year == now.get(Calendar.YEAR) && month == now.get(Calendar.MONTH) && day == now.get(Calendar.DAY_OF_MONTH)) {
//如果日期和当前日期一样,则用红框
Graphics2D gd = (Graphics2D) g;
gd.setColor(Color.RED);
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(getWidth() - 1, 0);
p.addPoint(getWidth() - 1, getHeight() - 1);
p.addPoint(0, getHeight() - 1);
gd.drawPolygon(p);
}
if (isSelected) {//如果被选中了就画出一个虚线框出来
Stroke s = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 2.0f, 2.0f }, 1.0f);
Graphics2D gd = (Graphics2D) g;
gd.setStroke(s);
gd.setColor(Color.BLACK);
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(getWidth() - 1, 0);
p.addPoint(getWidth() - 1, getHeight() - 1);
p.addPoint(0, getHeight() - 1);
gd.drawPolygon(p);
}
super.paintComponent(g);
}
public boolean contains(Point p) {
return this.getBounds().contains(p);
}
private void update() {
repaint();
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
isSelected = true;
update();
}
public void mouseReleased(MouseEvent e) {
Point p = SwingUtilities.convertPoint(this, e.getPoint(), jp3);
lm.setSelect(p, false);
commit();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
Point p = SwingUtilities.convertPoint(this, e.getPoint(), jp3);
lm.setSelect(p, true);
}
public void mouseMoved(MouseEvent e) {
}
public int compare(MyLabel o1, MyLabel o2) {
Calendar c1 = Calendar.getInstance();
c1.set(o1.year, o2.month, o1.day);
Calendar c2 = Calendar.getInstance();
c2.set(o2.year, o2.month, o2.day);
return c1.compareTo(c2);
}
}
private class LabelManager {
private List<MyLabel> list;
public LabelManager() {
list = new ArrayList<MyLabel>();
}
public List<MyLabel> getLabels() {
return list;
}
public void addLabel(MyLabel my) {
list.add(my);
}
public void clear() {
list.clear();
}
@SuppressWarnings("unused")
public void setSelect(MyLabel my, boolean b) {
for (MyLabel m : list) {
if (m.equals(my)) {
m.setSelected(true, b);
} else {
m.setSelected(false, b);
}
}
}
public void setSelect(Point p, boolean b) {
//如果是拖动,则要优化一下,以提高效率
if (b) {
//表示是否能返回,不用比较完所有的标签,能返回的标志就是把上一个标签和
//将要显示的标签找到了就可以了
boolean findPrevious = false, findNext = false;
for (MyLabel m : list) {
if (m.contains(p)) {
findNext = true;
if (m.getIsSelected()) {
findPrevious = true;
} else {
m.setSelected(true, b);
}
} else if (m.getIsSelected()) {
findPrevious = true;
m.setSelected(false, b);
}
if (findPrevious && findNext) {
return;
}
}
} else {
MyLabel temp = null;
for (MyLabel m : list) {
if (m.contains(p)) {
temp = m;
} else if (m.getIsSelected()) {
m.setSelected(false, b);
}
}
if (temp != null) {
temp.setSelected(true, b);
}
}
}
}
private class JP4 extends JPanel {
private static final long serialVersionUID = -6391305687575714469L;
public JP4() {
super(new BorderLayout());
this.setPreferredSize(new Dimension(295, 20));
this.setBackground(new Color(160, 185, 215));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
final JLabel jl = new JLabel("今天: " + sdf.format(new Date()));
jl.setToolTipText("点击选择今天日期");
this.add(jl, BorderLayout.CENTER);
jl.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
jl.setCursor(new Cursor(Cursor.HAND_CURSOR));
jl.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me) {
jl.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
jl.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me) {
jl.setForeground(Color.WHITE);
select.setTime(new Date());
refresh();
commit();
}
public void mouseReleased(MouseEvent me) {
jl.setForeground(Color.BLACK);
}
});
}
private void updateDate() {
}
}
public static void main(String[] args) {
DateChooser dateChooser1 = DateChooser.getInstance("yyyy-MM-dd");
DateChooser dateChooser2 = DateChooser.getInstance("yyyy-MM-dd");
JTextField showDate1 = new JTextField("单击选择日期");
JLabel showDate2 = new JLabel("单击选择日期");
dateChooser1.register(showDate1);
dateChooser2.register(showDate2);
JFrame jf = new JFrame("测试日期选择器");
jf.add(showDate1, BorderLayout.NORTH);
jf.add(showDate2, BorderLayout.SOUTH);
jf.pack();
jf.setLocationRelativeTo(null);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
评论
非常感谢,收藏啦。
好东西呀!
发表评论
-
springmvc
2013-02-26 23:26 0... -
netty
2013-02-15 23:23 0netty -
base dao
2013-01-27 21:32 0使用的Spring是3.1版本,不是3.0版本。两者还是有区 ... -
attachments
2012-09-04 21:36 0attachments -
临时草稿
2012-08-06 16:59 0使用的Spring是3.1版本,不是3.0版本。两者还是有区 ... -
OCR
2012-07-22 23:24 22JAVA OCR -
Nexus 2.0.5 私人服务器构建
2012-06-07 11:43 42101. 首先第一步,我们需要下载nexus-2.0.5-b ... -
软件版本
2012-03-23 22:48 6612306终极购票助手:1.0 JAVA实现的文件监听器:1 ... -
JAVA实现的文件监听器
2012-02-18 11:02 1588本软件可对任何文件进行监听,具体功能如下: 1、支持 ... -
DB4O 封装(面向对象数据库),采用泛型,支持任意对象存取,可移植性贼好! 哈哈
2012-02-14 13:35 1642自己封装的DB4O Template, 可很方便的进行对象保存 ... -
JAVA SWING 日期控件(目前支持JLable和JTextField,若有需要可自行扩展其它控件)
2012-02-14 13:25 7import java.awt.BasicStroke; ...
相关推荐
这篇博客(博文链接:https://zgdeng.iteye.com/blog/1405459)可能详细介绍了如何实现一个自定义的日期选择组件,目前该控件支持JLabel和JTextField,但其设计使得开发者可以根据需要扩展到其他Swing控件。...
这是一个小java的一个小demo 是Java swing的小demo jlable的右击鼠标实现上下移动 互换列表项的位置 可以用来学习一下 。。。。。。
在Java编程语言中,开发图形用户界面...这些组件的灵活性和可扩展性使得Java成为开发桌面GUI应用的强大工具。在实际项目中,还可以结合其他组件如`JButton`、`JTextArea`等,进一步增强用户体验,提供更多的交互功能。
Java基于要SWing技术自定义标签的边界效果,通过javax.swing.border.Border 接口,进行自定义边界类OwnBorder。可以实现空边界(EmptyBorder)、斜切边界(BevelBorder)、蚀刻边界(EtchedBorder)、线条边界...
(2) 基本组件(JButton,JLable,JTextField......)及方法 (3)基本容器(JFrame......)及方法 (4) 事件处理机制 (5)容器布局方式 (6)菜单(JMenu......) (7)GUI基本的继承体系 4.使用场景: 使用Java语言...
Swing的优势在于其组件具有更好的外观和感觉,同时支持事件处理和模型视图控制器(MVC)模式,使程序更易于维护和扩展。 8.2 创建窗体 创建Java Swing窗体主要通过JFrame类。你可以使用`setTitle()`方法设置窗体...
### Java课程设计小型图书管理系统知识点解析 #### 一、项目背景与目标 - **项目名称**:小型图书管理系统 - **课程名称**:Java应用 - **项目作者**:王焕 - **完成日期**:2008年12月24日 - **项目概述**:该系统...
### Java 实现的文字滚动知识点详解 #### 一、程序概述 本示例代码演示了如何在Java中创建一个简单的文字滚动效果。对于Java初学者而言,通过实践编写类似的小程序不仅可以增强对语言基础的理解,还能加深对图形...
JLabel是Java Swing库中的一个类,用于在窗口应用中显示文本、图像或者组合两者。在GUI设计中,JLabel常用来展示信息、提示或者简单的用户反馈。 描述 "ApplicationResources_zh.properties 转换后的unicode 编码...
《Java项目开发全程实录》这一本书从开发背景、需求分析、系统功能分析、数据库分析、数据库建模、网站开发和网站发布或者程序打包与运行,每一过程都进行了详细的介绍。 目 录 第1章 进销存管理系统(Swing+SQL ...
设置Table的DefaultRenderer,这个根据个人需要选择将要添加到Table的cell里的 组件(JButton,JLable...)继承相应的组件,并且implements TableCellRenderer,图片的方式是,将图片添加该组件中就可以了,具体方式...
Java可视化编程(winbuilder)视频教程+实践项目教程 Java可视化编程(winbuilder)视频教程+实践项目教程
这是2011年达内刘苍松老师讲解的第一小项目,给需要的朋友,资料都是内部的!我q963780015,欢迎IT朋友加我,令出售各种达内c java安卓,传智播客视频教程等等! Swing 1 历史 1.1 SUN Jdk1.1 AWT, 控件很少, 不...
程序基于Java开发,利用了Java的核心组件如JFrame和JLabel,这些都是Java Swing库中的关键元素。 【Java】Java是一种广泛使用的面向对象的编程语言,以其“一次编写,到处运行”的特性而著名。在本项目中,Java被...
乐透개요 또확인프그램그램기술스택 前端-Java Swing 后端-Java(JDK 1.8) 库和API-json-simple-1.1.1.jar IDE-Eclipse(EE,2020-06年) 服务器-Java应用程序Cl-Github,git주안점 摇摆으로만 Window Builder를이...
在 Java 中,设计图形界面标签和按钮组件是非常重要的,今天我们将学习如何使用 JLabel 和 JButton 等组件来设计图形界面。 一、标签组件 JLable JLabel 是一个基本的组件,用于显示文字或者图标。JLabel 的构造...
1.界面主要运用JLable呈现(以题目所给样式生成); 2.随机生成迷宫(只有有通路的迷宫才会用于初始化); 3.老鼠的行动初步定为:采用顺时针、未走过的优先原则(完全漫无目的的随机太难找到出口); 4.猫的行动是...
编写一个JFrame窗口,要求如下: 1)在窗口的最上方放置一个JLabel标签,标签中默认的文本是“鼠标右键点击的坐标” 2)为JFrame窗口添加一个鼠标,当鼠标右键点击窗口时,鼠标的坐标在JLabel标签中显示