初用Intellij GUI Form
来源:互联网 发布:无法触碰影评 知乎 编辑:程序博客网 时间:2024/06/05 09:14
终于下定决心完全使用Intellij进行编程,但还没用多久,就碰到今天的问题,Eclipse种可以使用JFrame插件,Intellij中如何实现。在查阅诸多大神和Intellij官方说明文档后,终于略有收获,特此Mark一下。这次主要用Intellij GUI Form实现已有的源代码。先看一下代码对比,体会一下最明显的差距。
Eclipse版代码:
public class StringConvert extends JFrame { private JTextField inputTextField; private JTextField outputTextField; /** * @wbp.nonvisual location=538,247 */ private final ButtonGroup buttonGroup = new ButtonGroup(); /** * Launch the application. */ public static void main(String[] args) { try { UIManager .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { StringConvert frame = new StringConvert(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public StringConvert() { setTitle("\u5B57\u7B26\u4E32\u5927\u5C0F\u5199\u8F6C\u6362"); setBounds(100, 100, 450, 214); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(null); inputTextField = new JTextField(); inputTextField.setBounds(23, 21, 383, 31); getContentPane().add(inputTextField); inputTextField.setColumns(10); JButton button = new JButton("\u8F6C\u6362"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { do_button_actionPerformed(arg0); } }); button.setBounds(23, 77, 93, 23); getContentPane().add(button); JRadioButton radioButton = new JRadioButton("大写"); radioButton.setActionCommand("大写"); radioButton.setSelected(true); radioButton.setBounds(169, 77, 76, 23); buttonGroup.add(radioButton); getContentPane().add(radioButton); JRadioButton radioButton_1 = new JRadioButton("小写"); radioButton_1.setBounds(280, 77, 121, 23); radioButton_1.setActionCommand("小写"); buttonGroup.add(radioButton_1); getContentPane().add(radioButton_1); outputTextField = new JTextField(); outputTextField.setEditable(false); outputTextField.setColumns(10); outputTextField.setBounds(23, 122, 383, 31); getContentPane().add(outputTextField); @SuppressWarnings("unused") String strBook = "MingRiBook".toLowerCase(); } protected void do_button_actionPerformed(ActionEvent arg0) { // 获取大小写单选项的选择 String command = buttonGroup.getSelection().getActionCommand(); boolean upper = command.equals("大写");// 判断是否选择的大写单选项 String text = inputTextField.getText();// 获取输入字符串 if (upper) {// 大写转换 outputTextField.setText(text.toUpperCase()); } else {// 小写转换 outputTextField.setText(text.toLowerCase()); } }}
Intellij版的代码:
public class StringConvertTest { private JPanel panel1; private JTextField InputTextField; private JTextField OutputTextField; private JButton Button1; private JRadioButton RadioButton1; private JRadioButton RadioButton2; public static void main(String[] args) { JFrame frame = new JFrame("StringConvert"); frame.setContentPane(new StringConvertTest().panel1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }// 设置构造方法 public StringConvertTest(){ Button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { do_button_actionPerformed(e); } }); }// 定义按钮事件 protected void do_button_actionPerformed(ActionEvent arg){ String text = InputTextField.getText(); if(RadioButton1.isSelected()){ OutputTextField.setText(text.toUpperCase()); }else{ OutputTextField.setText(text.toLowerCase()); } }}
最直接的印象就是代码量少好多啊,对于我这种菜鸟来说是极好的。
废话少说,开始创建GUI Form:
创建完成后,会有这个:
这StringConvertTest就是java程序。而.form文件就是一个基于XML的文件,双击打开就是这个样子滴:
通过添加相应组件,代码就会变成这样:
这就厉害了,代码哥,要是在Eclipse里面情况必须是这样滴:
其实过程就是这么简单,但今天使用中有一个区别的地方是,Eclipse中有buttonGroup这个东东,
可以Intellij中却难觅踪影:
看完官方文档后明白了,原来选中两个radiobutton后右键,选择group buttons就OK了,so easy:
然后就成了这个样子咯:
这是个人学习笔记,大神勿喷,小生这厢有礼了。
1 0
- 初用Intellij GUI Form
- 初用 intelliJ 的GUI Form
- Intellij IDEA 16 通过GUI Form 创建图形界面的方法( JAVA )
- intellij idea Swing GUI
- Intellij IDEA 创建GUI界面
- GUI Form小问题一
- java 反编译工具:JD-GUI、JD-Eclipse、JD-IntelliJ
- 用IntelliJ IDEA的GUI Designer写Swing程式
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 如何快速上手Netbeans的GUI Form Designer
- 使用IDEA创建GUI Form项目并构建
- GUI
- GUI
- Hive metastore database is not initialized. Please use schematool(...) to create the schema.
- 大数据开发利器:Hadoop(4)
- JS中在html中加载的顺序
- The VirtualBox kernel modules do not match this version of VirtualBox 解决 (linux update,nvidia失败)
- qt---cdb(Microsoft Console Debugger)调试
- 初用Intellij GUI Form
- C#——线程基础
- activity的四中启动模式
- 如何解决python2.7x 版本的安装出错问题
- 对象
- 经典算法题目:Cracking the coding interview 问题与解答
- week5 4-1 CheckBST[1]
- iOS rtf 和 ttf 字体导入技巧(iOS应用自定义字体)
- Rust语言教程(1) - 一门没有GC的语言