Java GUI 桌面应用开发(java开发桌面应用程序)

  前言

  虽然现在已经很少项目会涉及GUI技术,但作为一个合格的java开发工程师,还是得了解才得

  本文记录,idea使用JFormDesigner插件进行Java GUI 桌面应用开发

  GUI Swing

  图形化的用户界面(Graphical User Interface,简称GUI),java提供了一套可以轻松构建GUI的工具

  GUI开发包:
    java.AWT 包: 主要提供字体/布局管理器
    javax.Swing 包:主要提供各种组件(窗口/按钮/文本框),商业开发常用
    java.awt.event 包:事件处理,后台功能的实现

  Swing组件

    相对于AWT而言Swing包中提供了更多的丰富的、快捷的、强大的GUI组件

    大体上包括以下内容:window顶层容器(窗口)、container中间容器(面板)、component基本组件(按钮、标签等)

Java GUI 桌面应用开发(java开发桌面应用程序)

  JFormDesigner

  JFormDesigner,高级Swing GUI设计器,支持MigLayout, JGoodies FormLayout, GroupLayout(自由设计),TableLayout和GridBagLayout,这使得它很容易创建专业外观的表单。

  通俗的讲就是使用这个插件进行拖拉布局,快速创建页面,但是这个插件需要购买许可才能使用

  破解教程:https://www.cnblogs.com/ylkh/p/13858433.html

1、打开注册机JFormDesigner_Keygen.exe,选择idea plug-in,里面的可以随便填2、点击Patch,选择已安装的插件,生成bak文件(插件位置idea安装路径pluginsFormDesigner)3、点击generate生成JFormDesigner_license.txt文件

Java GUI 桌面应用开发(java开发桌面应用程序)

  代码编写

  创建图形页面,插件会自动同步生成java文件

Java GUI 桌面应用开发(java开发桌面应用程序)Java GUI 桌面应用开发(java开发桌面应用程序)Java GUI 桌面应用开发(java开发桌面应用程序)

  进行拖拉布局

Java GUI 桌面应用开发(java开发桌面应用程序)

  关键点:

  1、顶层容器(JFrame)的Name值要为:this

  2、生成的java文件要继承 javax.swing.JFrame

public class TestFrame extends javax.swing.JFrame{ //省略其他代码... }

  3、需要进行单选的RadioButton,要添加同一个Button Group

Java GUI 桌面应用开发(java开发桌面应用程序)

  4、defaultCloseOperation要设置成EXIT,点击X号退出页面时才会退出程序

Java GUI 桌面应用开发(java开发桌面应用程序)

  5、绑定事件,给按钮添加一个actionPerformed即可

Java GUI 桌面应用开发(java开发桌面应用程序)

  6、关闭当前页面:this.dispose(); //退出当前界面

  7、代码弹出对话框:JOptionPane.showMessageDialog(null, "恭喜哦,登录成功!");// Message 对话框

  生成的java文件

/* * Created by JFormDesigner on Tue Dec 28 15:24:42 CST 2021 */package cn.huanzi.qch.view;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * 测试 */public class TestFrame extends javax.swing.JFrame{ public TestFrame() { initComponents(); setVisible(true);// 显示 setLocationRelativeTo(null);// JFrame 窗口居中显示 } public static void main(String[] args) { java.awt.EventQueue.invokeLater(() -> { new TestFrame(); System.out.println("启动成功!"); }); } private void SubmitActionPerformed(ActionEvent e) { // TODO add your code here System.out.println("---------------------------"); System.out.println("姓名:" userNameTestField.getText()); String sex = ""; if (xyRadioButton.isSelected()) { sex = "男"; } else if (xxRadioButton.isSelected()) { sex = "女"; }else if (yyRadioButton.isSelected()) { sex = "不确定"; } System.out.println("性别:" sex); String hobby = ""; if (singCheckBox.isSelected()) { hobby = "唱、"; } if (skipCheckBox.isSelected()) { hobby = "跳、"; } if (rapCheckBox.isSelected()) { hobby = "rap、"; } System.out.println("爱好:" hobby); System.out.println("自我评价:" selfTextArea.getText()); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents label1 = new JLabel(); userNameTestField = new JTextField(); label2 = new JLabel(); label3 = new JLabel(); submit = new JButton(); reset = new JButton(); xxRadioButton = new JRadioButton(); xyRadioButton = new JRadioButton(); yyRadioButton = new JRadioButton(); scrollPane1 = new JScrollPane(); selfTextArea = new JTextArea(); label4 = new JLabel(); label5 = new JLabel(); singCheckBox = new JCheckBox(); skipCheckBox = new JCheckBox(); rapCheckBox = new JCheckBox(); //======== this ======== setBackground(Color.gray); setTitle("Test GUI"); setForeground(SystemColor.windowText); setMinimumSize(new Dimension(300, 200)); setResizable(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = getContentPane(); contentPane.setLayout(null); //---- label1 ---- label1.setText("u59d3u540duff1a"); contentPane.add(label1); label1.setBounds(34, 55, 65, 30); contentPane.add(userNameTestField); userNameTestField.setBounds(119, 55, 200, userNameTestField.getPreferredSize().height); //---- label2 ---- label2.setText("u6027u522buff1a"); contentPane.add(label2); label2.setBounds(34, 95, 65, 30); //---- label3 ---- label3.setText("u81eau6211u8bc4u4ef7uff1a"); contentPane.add(label3); label3.setBounds(34, 165, 65, 30); //---- submit ---- submit.setText("u63d0u4ea4"); submit.addActionListener(e -> SubmitActionPerformed(e)); contentPane.add(submit); submit.setBounds(new Rectangle(new Point(64, 271), submit.getPreferredSize())); //---- reset ---- reset.setText("u91cdu7f6e"); contentPane.add(reset); reset.setBounds(new Rectangle(new Point(219, 271), reset.getPreferredSize())); //---- xxRadioButton ---- xxRadioButton.setText("u5973"); contentPane.add(xxRadioButton); xxRadioButton.setBounds(new Rectangle(new Point(184, 100), xxRadioButton.getPreferredSize())); //---- xyRadioButton ---- xyRadioButton.setText("u7537"); contentPane.add(xyRadioButton); xyRadioButton.setBounds(new Rectangle(new Point(129, 100), xyRadioButton.getPreferredSize())); //---- yyRadioButton ---- yyRadioButton.setText("u4e0du786eu5b9a"); contentPane.add(yyRadioButton); yyRadioButton.setBounds(new Rectangle(new Point(239, 100), yyRadioButton.getPreferredSize())); //======== scrollPane1 ======== { scrollPane1.setViewportView(selfTextArea); } contentPane.add(scrollPane1); scrollPane1.setBounds(117, 165, 202, 71); //---- label4 ---- label4.setText("u6d4bu8bd5u8868u5355"); label4.setFont(label4.getFont().deriveFont(22f)); contentPane.add(label4); label4.setBounds(124, 0, 100, 45); //---- label5 ---- label5.setText("u7231u597duff1a"); contentPane.add(label5); label5.setBounds(34, 130, 65, 30); //---- singCheckBox ---- singCheckBox.setText("u5531"); contentPane.add(singCheckBox); singCheckBox.setBounds(new Rectangle(new Point(129, 135), singCheckBox.getPreferredSize())); //---- skipCheckBox ---- skipCheckBox.setText("u8df3"); contentPane.add(skipCheckBox); skipCheckBox.setBounds(new Rectangle(new Point(184, 135), skipCheckBox.getPreferredSize())); //---- rapCheckBox ---- rapCheckBox.setText("rap"); contentPane.add(rapCheckBox); rapCheckBox.setBounds(239, 135, 50, rapCheckBox.getPreferredSize().height); { // compute preferred size Dimension preferredSize = new Dimension(); for(int i = 0; i < contentPane.getComponentCount(); i ) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width = insets.right; preferredSize.height = insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(400, 365); setLocationRelativeTo(null); //---- buttonGroup2 ---- ButtonGroup buttonGroup2 = new ButtonGroup(); buttonGroup2.add(xxRadioButton); buttonGroup2.add(xyRadioButton); buttonGroup2.add(yyRadioButton); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JLabel label1; private JTextField userNameTestField; private JLabel label2; private JLabel label3; private JButton submit; private JButton reset; private JRadioButton xxRadioButton; private JRadioButton xyRadioButton; private JRadioButton yyRadioButton; private JScrollPane scrollPane1; private JTextArea selfTextArea; private JLabel label4; private JLabel label5; private JCheckBox singCheckBox; private JCheckBox skipCheckBox; private JCheckBox rapCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables}

  效果演示

Java GUI 桌面应用开发(java开发桌面应用程序)

  后记

  掌握了基本操作后,下面分享我在大学时期做的单机版五子棋、以及java课程实训作品:图书管理系统

  单机版五子棋

  猛戳:Java GUI 单机版五子棋

Java GUI 桌面应用开发(java开发桌面应用程序)

  图书管理系统

  数据库用mysql,GUI图形化页面实现用户登录后对图书进行CRUD操作

Java GUI 桌面应用开发(java开发桌面应用程序)

  登录页面

Java GUI 桌面应用开发(java开发桌面应用程序)

  图书管理

Java GUI 桌面应用开发(java开发桌面应用程序)Java GUI 桌面应用开发(java开发桌面应用程序)

  图书类别管理

Java GUI 桌面应用开发(java开发桌面应用程序)Java GUI 桌面应用开发(java开发桌面应用程序)

  关于我们

Java GUI 桌面应用开发(java开发桌面应用程序)

版权声明

作者:huanzi-qch

出处:https://www.cnblogs.com/huanzi-qch

若标题中有“转载”字样,则本文版权归原作者所有。若无转载字样,本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

(0)
上一篇 2024年5月19日 下午2:55
下一篇 2024年5月19日 下午3:07

相关推荐

  • 泰坦档案管理

    泰坦档案管理 随着泰坦尼克号船沉没的事件发生,泰坦尼克号档案成为了人们关注的焦点。这些档案包含了船上所有人员的姓名,出生年月,性别,宗教信仰,职业等信息。这些档案对于研究泰坦尼克号…

    科研百科 2024年10月8日
    16
  • 关于科技项目负责人变更的请示

    请示:关于科技项目负责人变更的请示 尊敬的领导: 我是一名科技项目负责人,现就关于科技项目负责人变更的问题向您请示。 近期,我们发现我们的科技项目存在一些问题,导致项目进度缓慢,效…

    科研百科 2024年11月16日
    6
  • 横向科研项目立项登记表

    横向科研项目立项登记表 项目名称: 项目简介: 本科研项目旨在研究一种新的能源技术,即可再生能源技术,包括太阳能、风能和水能等。该研究旨在开发更加高效、环保、可持续的能源技术,为未…

    科研百科 2025年2月2日
    0
  • 科研项目启动仪式发言稿

    尊敬的各位嘉宾,大家好! 今天,我们在这里隆重举行XXX科研项目启动仪式。我代表实验室全体人员,向各位嘉宾表示热烈的欢迎! XXX科研项目是一项非常重要的任务,它将为我们的研究带来…

    科研百科 2025年2月4日
    2
  • 24fall英国法学看这里,十大优质院校推荐,附申请要求(下)(英国法学系大学排名)

    随着留学热潮的持续升温,越来越多的学生开始将目光投向海外,其中英国法学专业成为了热门之选。今天继续推荐英国法学十大优质院校(下篇) 牛津大学 24QS排名:3 专业名称:法律和金融…

    科研百科 2024年4月14日
    98
  • 分包合同管理

    分包合同管理 分包合同是建筑工程中常见的合同之一,它是业主与分包商之间约定工程承包内容的协议。分包合同管理是保证分包合同履行的重要措施之一,对于业主和分包商都至关重要。本文将从分包…

    科研百科 2024年5月24日
    57
  • 种肥定位同播技术助推油菜“345” 模式示范推广

      9月27日,由中国农业科学院油料作物研究所和湖北省农业厅油菜办公室联合建立的种肥定位同播技术现场会在湖北省黄梅县分路镇召开。油料所副所长张学昆、湖北省农业厅科教处处长欧阳书文、…

    科研百科 2022年5月14日
    236
  • 国自然、省市级课题傻傻分不清?哪个更合适?(省自然和国自然题目一样有影响吗)

    课题已成为评职称的必须材料! 但国自然,省市级课题 区别到底是啥? 哪个是能够上的? 一、国自然课题 从课题申报人要求上来说,比省部级课题更高,从选题角度上来说,比省部级课题范围更…

    科研百科 2024年4月18日
    71
  • 四川省2024年科研项目申报

    四川省2024年科研项目申报 近年来,四川省在科技创新方面取得了显著成绩。为了进一步促进科技创新,四川省政府提出了2024年科研项目申报计划。本文将介绍该计划的背景和主要内容。 四…

    科研百科 2024年4月9日
    107
  • 内部审计具体做什么?有什么作用?(内部审计具体做什么-有什么作用呢)

    有一些对审计不了解的人,一听到内部审计就会觉得企业有什么事情,可能会十分的慌张,会认为企业是否有大规模变动或者企业财务状况发生了什么大事等。 其实内部审计就是对企业的财务收支,经济…

    科研百科 2024年1月28日
    121