给JAVA做个类VS的拖放式界面设计工具

2020

游历于CSDN和互联网,学习补缺知识链断点,体验大师们思路的开阔,有所收获也有待进一步收获。

临近年根,想来想去做点儿什么呢。

明年还要前行,就做点铺路的事儿吧。JAVA平台也好NET平台也好,Python也罢,都有相似的基础元素,也有各自的方向和优势。NET平台的拖放式IDE,不论做VBNET、C#还是平台支持的其它语言,都显得轻松随意,适合非专职人员把玩。AWT/SWING看了,tkinter看了,界面的东西最后都要变成代码描述给计算机,就控件而言,Unix系与Windows系有许多相似之处,如果用VS上的IDE设计界面(主要是WinForms),插段程序把控件的属性翻译成JAVA用语言就行了。于是,顺手超起VBNET插了段程序就做了,感觉还应付JAVA一般用的WinForm界面应该可以的。下面的图分别是VS IDE设计的界面,插入程序生成的JAVA代码,和JAVA SWING方式界面。

class ClassVBForm1 extends JFrame {
      String[] mystr = {"1","2","3","4","5","6","7"};
      private JFrame jfVBForm1;
      private JButton jbVBButton5, jbVBButton4, jbVBButton3, jbVBButton2, jbVBButton1;
      private JTextField jbVBTextBox1;
      private JLabel jbVBLabel2, jbVBLabel1;
      private JCheckBox jbVBCheckBox3, jbVBCheckBox2, jbVBCheckBox1;
      private JRadioButton jbVBRadioButton3, jbVBRadioButton2, jbVBRadioButton1;
      private JProgressBar jbVBProgressBar1;
      public ClassVBForm1(String string) {
          super(string);
          jbVBButton5 = new JButton("Button5");
          jbVBButton4 = new JButton("Button4");
          jbVBButton3 = new JButton("Button3");
          jbVBButton2 = new JButton("Button2");
          jbVBButton1 = new JButton("Button1");
          jbVBTextBox1 = new JTextField("TextBox1");
          jbVBLabel2 = new JLabel("Label2");
          jbVBLabel1 = new JLabel("Label1");
          jbVBCheckBox3 = new JCheckBox("CheckBox3");
          jbVBCheckBox2 = new JCheckBox("CheckBox2");
          jbVBCheckBox1 = new JCheckBox("CheckBox1");
          jbVBRadioButton3 = new JRadioButton("RadioButton3");
          jbVBRadioButton2 = new JRadioButton("RadioButton2");
          jbVBRadioButton1 = new JRadioButton("RadioButton1");
          jbVBProgressBar1 = new JProgressBar();
      }
      public void DOForm1() {
          JList<String> jbVBListBox1 = new JList<String>(mystr);
          JComboBox<String> jbVBComboBox1 = new JComboBox<String>(mystr);
          jfVBForm1= new JFrame("VBnet generated javaGUI code");
          jfVBForm1.setLayout(null);
          jfVBForm1.setSize(1035,463);
          jfVBForm1.setBackground(Color.BLUE);
          jfVBForm1.setLocation(442,293);
          jfVBForm1.setVisible(true);
          jfVBForm1.add(jbVBButton5);
          jfVBForm1.add(jbVBButton4);
          jfVBForm1.add(jbVBButton3);
          jfVBForm1.add(jbVBButton2);
          jfVBForm1.add(jbVBButton1);
          jfVBForm1.add(jbVBTextBox1);
          jfVBForm1.add(jbVBLabel2);
          jfVBForm1.add(jbVBLabel1);
          jfVBForm1.add(jbVBCheckBox3);
          jfVBForm1.add(jbVBCheckBox2);
          jfVBForm1.add(jbVBCheckBox1);
          jfVBForm1.add(jbVBRadioButton3);
          jfVBForm1.add(jbVBRadioButton2);
          jfVBForm1.add(jbVBRadioButton1);
          jfVBForm1.add(jbVBProgressBar1);
          jbVBProgressBar1.setMinimum(0); jbVBProgressBar1.setMaximum(100); jbVBProgressBar1.setValue(50);
          jfVBForm1.add(jbVBListBox1);
          jfVBForm1.add(jbVBComboBox1);
          jbVBButton5.setBounds(new Rectangle(276,49,207,86));
          jbVBButton4.setBounds(new Rectangle(276,166,207,30));
          jbVBButton3.setBounds(new Rectangle(73,166,170,30));
          jbVBButton2.setBounds(new Rectangle(73,105,170,30));
          jbVBButton1.setBounds(new Rectangle(73,49,170,30));
          jbVBTextBox1.setBounds(new Rectangle(73,268,410,39));
          jbVBLabel2.setBounds(new Rectangle(74,343,169,21));
          jbVBLabel1.setBounds(new Rectangle(74,244,169,21));
          jbVBCheckBox3.setBounds(new Rectangle(526,105,120,25));
          jbVBCheckBox2.setBounds(new Rectangle(526,77,120,25));
          jbVBCheckBox1.setBounds(new Rectangle(526,49,120,25));
          jbVBRadioButton3.setBounds(new Rectangle(516,192,111,20));
          jbVBRadioButton2.setBounds(new Rectangle(516,166,111,20));
          jbVBRadioButton1.setBounds(new Rectangle(516,140,111,20));
          jbVBProgressBar1.setBounds(new Rectangle(73,367,410,16));
          jbVBListBox1.setBounds(new Rectangle(662,49,278,148));
          jbVBComboBox1.setBounds(new Rectangle(657,248,282,20));
          jbVBButton5.setLocation(276,49);
          jbVBButton4.setLocation(276,166);
          jbVBButton3.setLocation(73,166);
          jbVBButton2.setLocation(73,105);
          jbVBButton1.setLocation(73,49);
          jbVBTextBox1.setLocation(73,268);
          jbVBLabel2.setLocation(74,343);
          jbVBLabel1.setLocation(74,244);
          jbVBCheckBox3.setLocation(526,105);
          jbVBCheckBox2.setLocation(526,77);
          jbVBCheckBox1.setLocation(526,49);
          jbVBRadioButton3.setLocation(516,192);
          jbVBRadioButton2.setLocation(516,166);
          jbVBRadioButton1.setLocation(516,140);
          jbVBProgressBar1.setLocation(73,367);
          jbVBListBox1.setLocation(662,49);
          jbVBComboBox1.setLocation(657,248);
          jfVBForm1.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt){
            jfVBForm1.setVisible(false);
            jfVBForm1.dispose();
            }
            });
      }
}

生成代码后main调用就简单了

		ClassVBForm1 vbf = new ClassVBForm1("VB generated Java Code");
			vbf.DOForm1();
		}

VS生成JAVA代码过程:

1、遍历窗体Form所有控件

2、对Button、Label、Text、ComboBox、List、ProgressBar、CheckBox、RadioButton进行分类识别,记录它们的属性。

3、翻译成JAVA语句,写进文本文件。NotePad打开文本文件,考贝粘贴至Eclipse,main主程序做初始化,调用类中方法,SWING方式的界面就出来了,位置大小与net平台上的一模一样。

微软和Delphi的IDE做WinForm设计都不错,就用它们的,无需自己费劲去写、做无用功。

 

增补(2月3日):

增补后的效果图

说明:分别做了FlowLayout/BorderLayout/CardLayout/GridLayout/GridBagLayout(最后的图遮盖住了)的AWT和SWING图,并在优麒麟(UBUNTU)上安装Eclipse编译。结果:(1)AWT的字体和图线随软件平台自身影响,字有些走样; SWING的字体图样不受平台影响,跨平台效果一样。(2)Eclipse + Java 加生成代码编译不用改动,跨平台直接编译运行。Solaris上Eclipse只有4.5.2版的,Solaris版本本身也只有10没升级到11,可怜Solaris已行将末路。跨平台测试都是在VMWARE虚拟机上做的。

2021

WebForm软件如林,框架繁多,如果是玩的话前后端都好实现,要接触一些新的思想和理念。Python一上路就拐到iPython完玩了几天,tkinter只是看也没动手去练,明年改一下拖放窗口,熟悉Python布局管理器同时,方便玩些小东西、减少枯燥。回首2020,和大家在CSDN遇见挺开心的,祝你们新年工作顺利、病毒不侵、幸福的生活!

猜你喜欢

转载自blog.csdn.net/weixin_45707491/article/details/113524941